mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 23:33:47 +01:00
Fixed Issue #1
This commit is contained in:
@@ -7,6 +7,8 @@ using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using NUnit.Framework;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||
@@ -41,10 +43,10 @@ namespace WireMock.Net.Tests
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Requests
|
||||
.Given(RequestBuilder
|
||||
.WithUrl("/foo")
|
||||
.UsingGet())
|
||||
.RespondWith(Responses
|
||||
.RespondWith(ResponseBuilder
|
||||
.WithStatusCode(200)
|
||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||
|
||||
@@ -98,7 +100,7 @@ namespace WireMock.Net.Tests
|
||||
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
|
||||
|
||||
// then
|
||||
var result = _server.SearchLogsFor(Requests.WithUrl("/b*"));
|
||||
var result = _server.SearchLogsFor(RequestBuilder.WithUrl("/b.*"));
|
||||
Check.That(result).HasSize(1);
|
||||
var requestLogged = result.First();
|
||||
Check.That(requestLogged.Url).IsEqualTo("/bar");
|
||||
@@ -125,10 +127,10 @@ namespace WireMock.Net.Tests
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Requests
|
||||
.Given(RequestBuilder
|
||||
.WithUrl("/foo")
|
||||
.UsingGet())
|
||||
.RespondWith(Responses
|
||||
.RespondWith(ResponseBuilder
|
||||
.WithStatusCode(200)
|
||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||
|
||||
@@ -147,17 +149,17 @@ namespace WireMock.Net.Tests
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Requests
|
||||
.Given(RequestBuilder
|
||||
.WithUrl("/foo")
|
||||
.UsingGet())
|
||||
.RespondWith(Responses
|
||||
.RespondWith(ResponseBuilder
|
||||
.WithStatusCode(307)
|
||||
.WithHeader("Location", "/bar"));
|
||||
_server
|
||||
.Given(Requests
|
||||
.Given(RequestBuilder
|
||||
.WithUrl("/bar")
|
||||
.UsingGet())
|
||||
.RespondWith(Responses
|
||||
.RespondWith(ResponseBuilder
|
||||
.WithStatusCode(200)
|
||||
.WithBody("REDIRECT SUCCESSFUL"));
|
||||
|
||||
@@ -176,9 +178,9 @@ namespace WireMock.Net.Tests
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Requests
|
||||
.Given(RequestBuilder
|
||||
.WithUrl("/*"))
|
||||
.RespondWith(Responses
|
||||
.RespondWith(ResponseBuilder
|
||||
.WithStatusCode(200)
|
||||
.WithBody(@"{ msg: ""Hello world!""}")
|
||||
.AfterDelay(TimeSpan.FromMilliseconds(2000)));
|
||||
@@ -200,9 +202,9 @@ namespace WireMock.Net.Tests
|
||||
_server = FluentMockServer.Start();
|
||||
_server.AddRequestProcessingDelay(TimeSpan.FromMilliseconds(2000));
|
||||
_server
|
||||
.Given(Requests
|
||||
.Given(RequestBuilder
|
||||
.WithUrl("/*"))
|
||||
.RespondWith(Responses
|
||||
.RespondWith(ResponseBuilder
|
||||
.WithStatusCode(200)
|
||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace WireMock.Net.Tests
|
||||
// then
|
||||
Check.That(MapperServer.LastRequest).IsNotNull();
|
||||
Check.That(MapperServer.LastRequest.Headers).Not.IsNullOrEmpty();
|
||||
Check.That(MapperServer.LastRequest.Headers.Contains(new KeyValuePair<string, string>("x-alex", "1706"))).IsTrue();
|
||||
Check.That(MapperServer.LastRequest.Headers.Contains(new KeyValuePair<string, string>("X-Alex", "1706"))).IsTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -141,7 +141,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
public static string UrlPrefix { get; private set; }
|
||||
|
||||
public static new MapperServer Start()
|
||||
public new static MapperServer Start()
|
||||
{
|
||||
var port = Ports.FindFreeTcpPort();
|
||||
UrlPrefix = "http://localhost:" + port + "/";
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using NFluent;
|
||||
using NUnit.Framework;
|
||||
using WireMock.RequestBuilders;
|
||||
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1633:FileMustHaveHeader",
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1633:FileMustHaveHeader",
|
||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace WireMock.Net.Tests
|
||||
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_url()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo");
|
||||
var spec = RequestBuilder.WithUrl("/foo");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
||||
@@ -34,7 +35,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_url_prefix()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo*");
|
||||
var spec = RequestBuilder.WithUrl("/foo*");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
||||
@@ -47,7 +48,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_exclude_requests_not_matching_given_url()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo");
|
||||
var spec = RequestBuilder.WithUrl("/foo");
|
||||
|
||||
// when
|
||||
var request = new Request("/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
||||
@@ -60,7 +61,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_path()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithPath("/foo");
|
||||
var spec = RequestBuilder.WithPath("/foo");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", "?param=1", "blabla", "whatever", new Dictionary<string, string>());
|
||||
@@ -73,7 +74,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_url_and_method()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingPut();
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingPut();
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
|
||||
@@ -86,7 +87,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingPut();
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingPut();
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
|
||||
@@ -99,7 +100,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/bar").UsingPut();
|
||||
var spec = RequestBuilder.WithUrl("/bar").UsingPut();
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
|
||||
@@ -112,11 +113,11 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_url_and_headers()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
|
||||
|
||||
|
||||
// then
|
||||
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||
}
|
||||
@@ -125,7 +126,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_exclude_requests_not_matching_given_headers()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
|
||||
@@ -134,14 +135,27 @@ namespace WireMock.Net.Tests
|
||||
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
||||
{
|
||||
// given
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "abc", false);
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "ABC" } });
|
||||
|
||||
// then
|
||||
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_specify_requests_matching_given_header_prefix()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "TaTaTa" } });
|
||||
|
||||
// then
|
||||
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||
@@ -151,7 +165,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_body()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithBody(".*Hello world!.*");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||
@@ -164,7 +178,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_body_as_wildcard()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody("H*o wor?d!");
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithBody("H.*o");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||
@@ -177,7 +191,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_exclude_requests_not_matching_given_body()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
||||
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||
@@ -190,7 +204,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_specify_requests_matching_given_params()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithPath("/foo").WithParam("bar", "1", "2");
|
||||
var spec = RequestBuilder.WithPath("/foo").WithParam("bar", "1", "2");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", "bar=1&bar=2", "Get", "Hello world!", new Dictionary<string, string>());
|
||||
@@ -203,7 +217,7 @@ namespace WireMock.Net.Tests
|
||||
public void Should_exclude_requests_not_matching_given_params()
|
||||
{
|
||||
// given
|
||||
var spec = Requests.WithPath("/foo").WithParam("bar", "1");
|
||||
var spec = RequestBuilder.WithPath("/foo").WithParam("bar", "1");
|
||||
|
||||
// when
|
||||
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string>());
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using NFluent;
|
||||
using NUnit.Framework;
|
||||
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1633:FileMustHaveHeader",
|
||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class WildcardPatternMatcherTests
|
||||
{
|
||||
[Test]
|
||||
public void Should_evaluate_patterns()
|
||||
{
|
||||
// Positive Tests
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*", string.Empty)).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?", " ")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*", "a")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*", "ab")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?", "a")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*?", "abc")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?*", "abc")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc", "abc")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc*", "abc")).IsTrue();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*a*bc*", "aXXXbc")).IsTrue();
|
||||
|
||||
// Negative Tests
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*a", string.Empty)).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("a*", string.Empty)).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?", string.Empty)).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*b*", "a")).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("b*a", "ab")).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("??", "a")).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*?", string.Empty)).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("??*", "a")).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc", "abX")).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc*", "Xbc")).IsFalse();
|
||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*a*bc*", "ac")).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,6 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RequestsTests.cs" />
|
||||
<Compile Include="RequestTests.cs" />
|
||||
<Compile Include="WildcardPatternMatcherTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
Reference in New Issue
Block a user