update some tests

This commit is contained in:
Stef Heyenrath
2017-02-09 07:26:46 +01:00
parent 4919e32264
commit abde3cd83f

View File

@@ -215,7 +215,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_headers() public void Should_exclude_requests_not_matching_given_headers()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata"); var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tatata");
// when // when
string bodyAsString = "whatever"; string bodyAsString = "whatever";
@@ -231,7 +231,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_headers_ignorecase() public void Should_exclude_requests_not_matching_given_headers_ignorecase()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "abc", false); var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "abc", false);
// when // when
string bodyAsString = "whatever"; string bodyAsString = "whatever";
@@ -247,7 +247,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_header_prefix() public void Should_specify_requests_matching_given_header_prefix()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*"); var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tata*");
// when // when
string bodyAsString = "whatever"; string bodyAsString = "whatever";
@@ -263,7 +263,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_cookies() public void Should_specify_requests_matching_given_cookies()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithCookie("session", "a*"); var spec = Request.Create().UsingAnyVerb().WithCookie("session", "a*");
// when // when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", null, null, null, new Dictionary<string, string> { { "session", "abc" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", null, null, null, new Dictionary<string, string> { { "session", "abc" } });
@@ -277,7 +277,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body() public void Should_specify_requests_matching_given_body()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody("Hello world!"); var spec = Request.Create().UsingAnyVerb().WithBody("Hello world!");
// when // when
string bodyAsString = "Hello world!"; string bodyAsString = "Hello world!";
@@ -293,7 +293,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_ExactMatcher_true() public void Should_specify_requests_matching_given_body_using_ExactMatcher_true()
{ {
// given // given
var requestBuilder = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new ExactMatcher("cat")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
// when // when
string bodyAsString = "cat"; string bodyAsString = "cat";
@@ -305,11 +305,27 @@ namespace WireMock.Net.Tests
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0); Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
} }
[Test]
public void Should_specify_requests_matching_given_body_using_ExactMatcher_multiplePatterns()
{
// given
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat", "dog"));
// when
string bodyAsString = "cat";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString);
// then
var requestMatchResult = new RequestMatchResult();
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.5);
}
[Test] [Test]
public void Should_specify_requests_matching_given_body_using_ExactMatcher_false() public void Should_specify_requests_matching_given_body_using_ExactMatcher_false()
{ {
// given // given
var requestBuilder = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new ExactMatcher("cat")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
// when // when
string bodyAsString = "caR"; string bodyAsString = "caR";
@@ -325,7 +341,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_SimMetricsMatcher() public void Should_specify_requests_matching_given_body_using_SimMetricsMatcher()
{ {
// given // given
var requestBuilder = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody("The cat walks in the street."); var requestBuilder = Request.Create().UsingAnyVerb().WithBody("The cat walks in the street.");
// when // when
string bodyAsString = "The car drives in the street."; string bodyAsString = "The car drives in the street.";
@@ -357,7 +373,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_RegexMatcher() public void Should_specify_requests_matching_given_body_using_RegexMatcher()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new RegexMatcher("H.*o")); var spec = Request.Create().UsingAnyVerb().WithBody(new RegexMatcher("H.*o"));
// when // when
string bodyAsString = "Hello world!"; string bodyAsString = "Hello world!";
@@ -373,7 +389,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_XPathMatcher_true() public void Should_specify_requests_matching_given_body_using_XPathMatcher_true()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]")); var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
// when // when
string xmlBodyAsString = @" string xmlBodyAsString = @"
@@ -394,7 +410,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_XPathMatcher_false() public void Should_specify_requests_matching_given_body_using_XPathMatcher_false()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]")); var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
// when // when
string xmlBodyAsString = @" string xmlBodyAsString = @"
@@ -415,7 +431,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_JsonPathMatcher_true() public void Should_specify_requests_matching_given_body_using_JsonPathMatcher_true()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")); var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
// when // when
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }"; string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
@@ -431,7 +447,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body_using_JsonPathMatcher_false() public void Should_specify_requests_matching_given_body_using_JsonPathMatcher_false()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")); var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
// when // when
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }"; string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
@@ -447,7 +463,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_body() public void Should_exclude_requests_not_matching_given_body()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(" Hello world! "); var spec = Request.Create().UsingAnyVerb().WithBody(" Hello world! ");
// when // when
string bodyAsString = "xxx"; string bodyAsString = "xxx";
@@ -463,7 +479,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_param() public void Should_specify_requests_matching_given_param()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").WithParam("bar", "1", "2"); var spec = Request.Create().WithParam("bar", "1", "2");
// when // when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT"); var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT");
@@ -477,7 +493,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_paramNoValue() public void Should_specify_requests_matching_given_paramNoValue()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").WithParam("bar"); var spec = Request.Create().WithParam("bar");
// when // when
var request = new RequestMessage(new Uri("http://localhost/foo?bar"), "PUT"); var request = new RequestMessage(new Uri("http://localhost/foo?bar"), "PUT");
@@ -491,7 +507,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_param_func() public void Should_specify_requests_matching_given_param_func()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithParam(p => p.ContainsKey("bar")); var spec = Request.Create().UsingAnyVerb().WithParam(p => p.ContainsKey("bar"));
// when // when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT"); var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT");
@@ -505,7 +521,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_params() public void Should_exclude_requests_not_matching_given_params()
{ {
// given // given
var spec = Request.Create().WithPath("/foo").WithParam("bar", "1"); var spec = Request.Create().WithParam("bar", "1");
// when // when
var request = new RequestMessage(new Uri("http://localhost/test=7"), "PUT"); var request = new RequestMessage(new Uri("http://localhost/test=7"), "PUT");
@@ -515,5 +531,4 @@ namespace WireMock.Net.Tests
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0); Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
} }
} }
} }