* added byte[] body

* updated readme
This commit is contained in:
Stef Heyenrath
2017-01-19 14:57:12 +01:00
parent 8dfcf7288f
commit 1b2e5368a9
10 changed files with 355 additions and 186 deletions

View File

@@ -11,20 +11,20 @@ using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[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 ArrangeThisQualifier
// ReSharper disable InconsistentNaming
@@ -100,10 +100,12 @@ namespace WireMock.Net.Tests
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
// then
var result = _server.SearchLogsFor(Request.WithUrl("/b.*"));
var result = _server.SearchLogsFor(Request.WithUrl("/b.*")).ToList();
Check.That(result).HasSize(1);
var requestLogged = result.First();
Check.That(requestLogged.Url).IsEqualTo("/bar");
Check.That(requestLogged.Path).IsEqualTo("/bar");
Check.That(requestLogged.Url).IsEqualTo("http://localhost:" + _server.Port + "/bar");
}
[Test]

View File

@@ -9,23 +9,22 @@ using NUnit.Framework;
using WireMock.Http;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[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 ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock.Net.Tests
{
[TestFixture]
@@ -50,7 +49,7 @@ namespace WireMock.Net.Tests
// then
Check.That(MapperServer.LastRequestMessage).IsNotNull();
Check.That(MapperServer.LastRequestMessage.Url).IsEqualTo("/toto");
Check.That(MapperServer.LastRequestMessage.Path).IsEqualTo("/toto");
}
[Test]
@@ -78,7 +77,7 @@ namespace WireMock.Net.Tests
// then
Check.That(MapperServer.LastRequestMessage).IsNotNull();
Check.That(MapperServer.LastRequestMessage.Body).IsEqualTo("Hello!");
Check.That(MapperServer.LastRequestMessage.BodyAsString).IsEqualTo("Hello!");
}
[Test]
@@ -146,7 +145,7 @@ namespace WireMock.Net.Tests
var port = Ports.FindFreeTcpPort();
UrlPrefix = "http://localhost:" + port + "/";
var server = new MapperServer(
UrlPrefix,
UrlPrefix,
context =>
{
LastRequestMessage = new HttpListenerRequestMapper().Map(context.Request);

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using NFluent;
using NUnit.Framework;
@@ -21,7 +23,9 @@ namespace WireMock.Net.Tests
public void Should_handle_empty_query()
{
// given
var request = new RequestMessage("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString);
// then
Check.That(request.GetParameter("foo")).IsEmpty();
@@ -31,7 +35,9 @@ namespace WireMock.Net.Tests
public void Should_parse_query_params()
{
// given
var request = new RequestMessage("/foo", "foo=bar&multi=1&multi=2", "blabla", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost?foo=bar&multi=1&multi=2"), "POST", body, bodyAsString);
// then
Check.That(request.GetParameter("foo")).Contains("bar");

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using NFluent;
using NUnit.Framework;
using WireMock.RequestBuilders;
@@ -25,7 +27,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo");
// when
var request = new RequestMessage("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -38,7 +42,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo*");
// when
var request = new RequestMessage("/foo/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo/bar"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -51,7 +57,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo");
// when
var request = new RequestMessage("/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/bar"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
@@ -64,7 +72,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithPath("/foo");
// when
var request = new RequestMessage("/foo", "?param=1", "blabla", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -77,7 +87,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingPut();
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -90,7 +102,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingPost();
// when
var request = new RequestMessage("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -103,7 +117,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingGet();
// when
var request = new RequestMessage("/foo", string.Empty, "GET", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -116,7 +132,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingDelete();
// when
var request = new RequestMessage("/foo", string.Empty, "DELETE", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "Delete", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -129,7 +147,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingHead();
// when
var request = new RequestMessage("/foo", string.Empty, "HEAD", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -142,7 +162,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingPut();
// when
var request = new RequestMessage("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
@@ -155,7 +177,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/bar").UsingPut();
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
@@ -168,7 +192,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -181,7 +207,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
@@ -194,7 +222,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "abc", false);
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "ABC" } });
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "ABC" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
@@ -207,7 +237,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "TaTaTa" } });
string bodyAsString = "whatever";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "TaTaTa" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -220,7 +252,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(".*Hello world!.*");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
string bodyAsString = "Hello world!";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -233,7 +267,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody("H.*o");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
string bodyAsString = "Hello world!";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -246,7 +282,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string> { { "X-toto", "tatata" } });
string bodyAsString = "xxx";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
@@ -259,7 +297,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithPath("/foo").WithParam("bar", "1", "2");
// when
var request = new RequestMessage("/foo", "bar=1&bar=2", "Get", "Hello world!", new Dictionary<string, string>());
string bodyAsString = "Hello world!";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -272,7 +312,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithPath("/foo").WithParam(p => p.ContainsKey("bar") && (p["bar"].Contains("1") || p["bar"].Contains("2")));
// when
var request = new RequestMessage("/foo", "bar=1&bar=2", "Get", "Hello world!", new Dictionary<string, string>());
string bodyAsString = "Hello world!";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
@@ -285,7 +327,9 @@ namespace WireMock.Net.Tests
var spec = Request.WithPath("/foo").WithParam("bar", "1");
// when
var request = new RequestMessage("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string>());
string bodyAsString = "Hello world!";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/test=7"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();