mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-14 14:22:02 +01:00
path <> url
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Admin.Mappings
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
/// <summary>
|
||||
/// UrlModel
|
||||
/// PathModel
|
||||
/// </summary>
|
||||
public class UrlModel
|
||||
public class PathModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
@@ -8,12 +8,12 @@ namespace WireMock.Admin.Mappings
|
||||
public class RequestModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the URL. (Can be a string or a UrlModel)
|
||||
/// Gets or sets the Path. (Can be a string or a PathModel)
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The URL.
|
||||
/// </value>
|
||||
public object Url { get; set; }
|
||||
public object Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The methods
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace WireMock.Matchers.Request
|
||||
public bool IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (Matchers != null)
|
||||
return Matchers.Any(matcher => matcher.IsMatch(requestMessage.Path));
|
||||
return Matchers.Any(matcher => matcher.IsMatch(requestMessage.Url));
|
||||
|
||||
if (_urlFuncs != null)
|
||||
return _urlFuncs.Any(func => func(requestMessage.Url));
|
||||
|
||||
@@ -9,27 +9,6 @@ namespace WireMock.RequestBuilders
|
||||
/// </summary>
|
||||
public interface IUrlAndPathRequestBuilder : IMethodRequestBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithUrl([NotNull] params IMatcher[] matchers);
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="urls">The urls.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithUrl([NotNull] params string[] urls);
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The url funcs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithUrl([NotNull] params Func<string, bool>[] funcs);
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
@@ -44,11 +23,32 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithPath([NotNull] params string[] paths);
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The path funcs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithPath([NotNull] params Func<string, bool>[] funcs);
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithUrl([NotNull] params IMatcher[] matchers);
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="urls">The urls.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithUrl([NotNull] params string[] urls);
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="func">The path func.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithPath([NotNull] params Func<string, bool>[] func);
|
||||
IRequestBuilder WithUrl([NotNull] params Func<string, bool>[] func);
|
||||
}
|
||||
}
|
||||
@@ -54,13 +54,46 @@ namespace WireMock.RequestBuilders
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithUrl(params IMatcher[] matchers)
|
||||
public IRequestBuilder WithPath(params IMatcher[] matchers)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(matchers));
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(matchers));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="paths">The paths.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params string[] paths)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(paths));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The path func.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(funcs));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="matcher">The matcher.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithUrl(params IMatcher[] matcher)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(matcher));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -86,39 +119,6 @@ namespace WireMock.RequestBuilders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with url.
|
||||
/// </summary>
|
||||
/// <param name="matcher">The matcher.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params IMatcher[] matcher)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(matcher));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="paths">The path.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params string[] paths)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(paths));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The path func.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(funcs));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using get.
|
||||
/// </summary>
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace WireMock.Server
|
||||
private void InitAdmin()
|
||||
{
|
||||
// __admin/mappings
|
||||
Given(Request.Create().WithUrl(AdminMappings).UsingGet()).RespondWith(new DynamicResponseProvider(MappingsGet));
|
||||
Given(Request.Create().WithUrl(AdminMappings).UsingPost()).RespondWith(new DynamicResponseProvider(MappingsPost));
|
||||
Given(Request.Create().WithPath(AdminMappings).UsingGet()).RespondWith(new DynamicResponseProvider(MappingsGet));
|
||||
Given(Request.Create().WithPath(AdminMappings).UsingPost()).RespondWith(new DynamicResponseProvider(MappingsPost));
|
||||
|
||||
// __admin/mappings/{guid}
|
||||
var guidPathMatcher = new RegexMatcher(@"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
|
||||
@@ -38,7 +38,7 @@ namespace WireMock.Server
|
||||
|
||||
|
||||
// __admin/requests
|
||||
Given(Request.Create().WithUrl(AdminRequests).UsingGet()).RespondWith(new DynamicResponseProvider(RequestsGet));
|
||||
Given(Request.Create().WithPath(AdminRequests).UsingGet()).RespondWith(new DynamicResponseProvider(RequestsGet));
|
||||
}
|
||||
|
||||
private ResponseMessage MappingGet(RequestMessage requestMessage)
|
||||
@@ -89,14 +89,14 @@ namespace WireMock.Server
|
||||
private IRequestBuilder InitRequestBuilder(MappingModel mappingModel)
|
||||
{
|
||||
IRequestBuilder requestBuilder = Request.Create();
|
||||
string url = mappingModel.Request.Url as string;
|
||||
if (url != null)
|
||||
requestBuilder = requestBuilder.WithUrl(url);
|
||||
string path = mappingModel.Request.Path as string;
|
||||
if (path != null)
|
||||
requestBuilder = requestBuilder.WithPath(path);
|
||||
else
|
||||
requestBuilder = requestBuilder.WithUrl("/*");
|
||||
//UrlModel urlModel = mappingModel.Request.Url as UrlModel;
|
||||
requestBuilder = requestBuilder.WithPath("/*");
|
||||
//PathModel urlModel = mappingModel.Request.Path as PathModel;
|
||||
//if (urlModel?.Matchers != null)
|
||||
// builder = builder.WithUrl(urlModel.Matchers.Select(Map).ToArray());
|
||||
// builder = builder.WithPath(urlModel.Matchers.Select(Map).ToArray());
|
||||
|
||||
if (mappingModel.Request.Methods != null)
|
||||
requestBuilder = requestBuilder.UsingVerb(mappingModel.Request.Methods);
|
||||
@@ -209,7 +209,7 @@ namespace WireMock.Server
|
||||
Guid = mapping.Guid,
|
||||
Request = new RequestModel
|
||||
{
|
||||
Url = new UrlModel
|
||||
Path = new PathModel
|
||||
{
|
||||
Matchers = urlMatchers != null ? Map(urlMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)) : null
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user