NET Core 2.1 + support for Service Fabric commandline parameters (#209)

* netcore 2.1

* SimpleCommandLineParserTests

* tests

* SimpleCommandLineParserTests

* test report

* AspNetCoreSelfHost

* Fixed Resharper warnings

* tests

* .

* ResponseWithProxyTests

ResponseWithProxyTests

* postmanecho
This commit is contained in:
Stef Heyenrath
2018-10-10 09:49:32 +02:00
committed by GitHub
parent 04bcca6e14
commit 83457c1601
147 changed files with 3676 additions and 3330 deletions

View File

@@ -65,18 +65,18 @@ namespace WireMock.Net.Tests
staticMappingHandlerMock.Setup(m => m.FolderExists(It.IsAny<string>())).Returns(true);
staticMappingHandlerMock.Setup(m => m.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()));
var _server = FluentMockServer.Start(new FluentMockServerSettings
var server = FluentMockServer.Start(new FluentMockServerSettings
{
FileSystemHandler = staticMappingHandlerMock.Object
});
_server
server
.Given(Request.Create().WithPath($"/foo_{Guid.NewGuid()}"))
.WithGuid(guid)
.RespondWith(Response.Create().WithBody("save test"));
// Act
_server.SaveStaticMappings();
server.SaveStaticMappings();
// Assert and Verify
staticMappingHandlerMock.Verify(m => m.GetMappingFolder(), Times.Once);
@@ -90,12 +90,12 @@ namespace WireMock.Net.Tests
var guid = Guid.Parse("04ee4872-9efd-4770-90d3-88d445265d0d");
string title = "documentdb_root_title";
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", "documentdb_root.json");
_server.ReadStaticMappingAndAddOrUpdate(folder);
server.ReadStaticMappingAndAddOrUpdate(folder);
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(1);
Check.That(mappings.First().RequestMatcher).IsNotNull();
@@ -109,11 +109,11 @@ namespace WireMock.Net.Tests
{
string guid = "00000002-ee28-4f29-ae63-1ac9b0802d86";
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", guid + ".json");
_server.ReadStaticMappingAndAddOrUpdate(folder);
server.ReadStaticMappingAndAddOrUpdate(folder);
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(1);
Check.That(mappings.First().RequestMatcher).IsNotNull();
@@ -138,10 +138,10 @@ namespace WireMock.Net.Tests
string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
File.WriteAllText(folder, output);
var _server = FluentMockServer.Start();
_server.ReadStaticMappingAndAddOrUpdate(folder);
var server = FluentMockServer.Start();
server.ReadStaticMappingAndAddOrUpdate(folder);
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(1);
Check.That(mappings.First().RequestMatcher).IsNotNull();
@@ -159,13 +159,13 @@ namespace WireMock.Net.Tests
staticMappingHandlerMock.Setup(m => m.FolderExists(It.IsAny<string>())).Returns(true);
staticMappingHandlerMock.Setup(m => m.EnumerateFiles(It.IsAny<string>())).Returns(new string[0]);
var _server = FluentMockServer.Start(new FluentMockServerSettings
var server = FluentMockServer.Start(new FluentMockServerSettings
{
FileSystemHandler = staticMappingHandlerMock.Object
});
// Act
_server.ReadStaticMappings();
server.ReadStaticMappings();
// Assert and Verify
staticMappingHandlerMock.Verify(m => m.GetMappingFolder(), Times.Once);
@@ -178,30 +178,30 @@ namespace WireMock.Net.Tests
{
// Assign
string mapping = "{\"Request\": {\"Path\": {\"Matchers\": [{\"Name\": \"WildcardMatcher\",\"Pattern\": \"/static/mapping\"}]},\"Methods\": [\"get\"]},\"Response\": {\"BodyAsJson\": { \"body\": \"static mapping\" }}}";
var _staticMappingHandlerMock = new Mock<IFileSystemHandler>();
_staticMappingHandlerMock.Setup(m => m.ReadMappingFile(It.IsAny<string>())).Returns(mapping);
var staticMappingHandlerMock = new Mock<IFileSystemHandler>();
staticMappingHandlerMock.Setup(m => m.ReadMappingFile(It.IsAny<string>())).Returns(mapping);
var _server = FluentMockServer.Start(new FluentMockServerSettings
var server = FluentMockServer.Start(new FluentMockServerSettings
{
FileSystemHandler = _staticMappingHandlerMock.Object
FileSystemHandler = staticMappingHandlerMock.Object
});
// Act
_server.ReadStaticMappingAndAddOrUpdate(@"c:\test.json");
server.ReadStaticMappingAndAddOrUpdate(@"c:\test.json");
// Assert and Verify
_staticMappingHandlerMock.Verify(m => m.ReadMappingFile(@"c:\test.json"), Times.Once);
staticMappingHandlerMock.Verify(m => m.ReadMappingFile(@"c:\test.json"), Times.Once);
}
[Fact]
public void FluentMockServer_Admin_ReadStaticMappings()
{
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings");
_server.ReadStaticMappings(folder);
server.ReadStaticMappings(folder);
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(3);
}
@@ -215,13 +215,13 @@ namespace WireMock.Net.Tests
{
Logger = loggerMock.Object
};
var _server = FluentMockServer.Start(settings);
var server = FluentMockServer.Start(settings);
// Act
_server.ReadStaticMappings(Guid.NewGuid().ToString());
server.ReadStaticMappings(Guid.NewGuid().ToString());
// Assert
Check.That(_server.Mappings).HasSize(0);
Check.That(server.Mappings).HasSize(0);
// Verify
loggerMock.Verify(l => l.Info(It.Is<string>(s => s.StartsWith("The Static Mapping folder")), It.IsAny<object[]>()), Times.Once);
@@ -231,15 +231,15 @@ namespace WireMock.Net.Tests
public void FluentMockServer_Admin_Mappings_WithGuid_Get()
{
Guid guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
_server.Given(Request.Create().WithPath("/foo1").UsingGet()).WithGuid(guid)
server.Given(Request.Create().WithPath("/foo1").UsingGet()).WithGuid(guid)
.RespondWith(Response.Create().WithStatusCode(201).WithBody("1"));
_server.Given(Request.Create().WithPath("/foo2").UsingGet())
server.Given(Request.Create().WithPath("/foo2").UsingGet())
.RespondWith(Response.Create().WithStatusCode(202).WithBody("2"));
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(2);
}
@@ -247,12 +247,12 @@ namespace WireMock.Net.Tests
public void FluentMockServer_Admin_Mappings_WithGuidAsString_Get()
{
string guid = "90356dba-b36c-469a-a17e-669cd84f1f05";
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
_server.Given(Request.Create().WithPath("/foo100").UsingGet()).WithGuid(guid)
server.Given(Request.Create().WithPath("/foo100").UsingGet()).WithGuid(guid)
.RespondWith(Response.Create().WithStatusCode(201).WithBody("1"));
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(1);
}
@@ -260,23 +260,23 @@ namespace WireMock.Net.Tests
public void FluentMockServer_Admin_Mappings_Add_SameGuid()
{
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
var response1 = Response.Create().WithStatusCode(500);
_server.Given(Request.Create().UsingGet())
server.Given(Request.Create().UsingGet())
.WithGuid(guid)
.RespondWith(response1);
var mappings1 = _server.Mappings.ToArray();
var mappings1 = server.Mappings.ToArray();
Check.That(mappings1).HasSize(1);
Check.That(mappings1.First().Guid).Equals(guid);
var response2 = Response.Create().WithStatusCode(400);
_server.Given(Request.Create().WithPath("/2").UsingGet())
server.Given(Request.Create().WithPath("/2").UsingGet())
.WithGuid(guid)
.RespondWith(response2);
var mappings2 = _server.Mappings.ToArray();
var mappings2 = server.Mappings.ToArray();
Check.That(mappings2).HasSize(1);
Check.That(mappings2.First().Guid).Equals(guid);
Check.That(mappings2.First().Provider).Equals(response2);
@@ -285,22 +285,22 @@ namespace WireMock.Net.Tests
[Fact]
public async Task FluentMockServer_Admin_Mappings_AtPriority()
{
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
// given
_server.Given(Request.Create().WithPath("/1").UsingGet())
server.Given(Request.Create().WithPath("/1").UsingGet())
.AtPriority(2)
.RespondWith(Response.Create().WithStatusCode(200));
_server.Given(Request.Create().WithPath("/1").UsingGet())
server.Given(Request.Create().WithPath("/1").UsingGet())
.AtPriority(1)
.RespondWith(Response.Create().WithStatusCode(400));
var mappings = _server.Mappings.ToArray();
var mappings = server.Mappings.ToArray();
Check.That(mappings).HasSize(2);
// when
var response = await new HttpClient().GetAsync("http://localhost:" + _server.Ports[0] + "/1");
var response = await new HttpClient().GetAsync("http://localhost:" + server.Ports[0] + "/1");
// then
Check.That((int)response.StatusCode).IsEqualTo(400);
@@ -310,14 +310,14 @@ namespace WireMock.Net.Tests
public async Task FluentMockServer_Admin_Requests_Get()
{
// given
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
// when
await new HttpClient().GetAsync("http://localhost:" + _server.Ports[0] + "/foo");
await new HttpClient().GetAsync("http://localhost:" + server.Ports[0] + "/foo");
// then
Check.That(_server.LogEntries).HasSize(1);
var requestLogged = _server.LogEntries.First();
Check.That(server.LogEntries).HasSize(1);
var requestLogged = server.LogEntries.First();
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("GET");
Check.That(requestLogged.RequestMessage.BodyAsBytes).IsNull();
}
@@ -328,20 +328,20 @@ namespace WireMock.Net.Tests
// Assign
var client = new HttpClient();
// Act
var _server = FluentMockServer.Start();
_server.SetMaxRequestLogCount(2);
var server = FluentMockServer.Start();
server.SetMaxRequestLogCount(2);
await client.GetAsync("http://localhost:" + _server.Ports[0] + "/foo1");
await client.GetAsync("http://localhost:" + _server.Ports[0] + "/foo2");
await client.GetAsync("http://localhost:" + _server.Ports[0] + "/foo3");
await client.GetAsync("http://localhost:" + server.Ports[0] + "/foo1");
await client.GetAsync("http://localhost:" + server.Ports[0] + "/foo2");
await client.GetAsync("http://localhost:" + server.Ports[0] + "/foo3");
// Assert
Check.That(_server.LogEntries).HasSize(2);
Check.That(server.LogEntries).HasSize(2);
var requestLoggedA = _server.LogEntries.First();
var requestLoggedA = server.LogEntries.First();
Check.That(requestLoggedA.RequestMessage.Path).EndsWith("/foo2");
var requestLoggedB = _server.LogEntries.Last();
var requestLoggedB = server.LogEntries.Last();
Check.That(requestLoggedB.RequestMessage.Path).EndsWith("/foo3");
}
@@ -354,10 +354,10 @@ namespace WireMock.Net.Tests
{
FileSystemHandler = fileMock.Object
};
var _server = FluentMockServer.Start(settings);
var server = FluentMockServer.Start(settings);
// Act
_server.WatchStaticMappings();
server.WatchStaticMappings();
// Verify
fileMock.Verify(f => f.GetMappingFolder(), Times.Once);

View File

@@ -1,4 +1,3 @@
using System.Linq;
using NFluent;
using WireMock.Matchers;
using WireMock.Owin;

View File

@@ -0,0 +1,115 @@
using NFluent;
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
using Xunit;
using Xunit.Abstractions;
namespace WireMock.Net.Tests
{
public class FluentMockServerProxy2Tests : IDisposable
{
private readonly ITestOutputHelper _output;
private readonly CancellationTokenSource _cts;
private Guid _guid;
private string _url;
public FluentMockServerProxy2Tests(ITestOutputHelper output)
{
_output = output;
_cts = new CancellationTokenSource();
}
//private Task Run()
//{
// return Task.Run(() =>
// {
// _guid = Guid.NewGuid();
// var targetServer = FluentMockServer.Start();
// targetServer.Given(Request.Create().UsingPost().WithPath($"/{_guid}"))
// .RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 42 }).WithHeader("Content-Type", "application/json"));
// _url = targetServer.Urls[0];
// //while (!_cts.IsCancellationRequested)
// //{
// // Thread.Sleep(100);
// //}
// }, _cts.Token);
//}
private void X()
{
_guid = Guid.NewGuid();
var targetServer = FluentMockServer.Start();
targetServer.Given(Request.Create().UsingPost().WithPath($"/{_guid}"))
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 42 }).WithHeader("Content-Type", "application/json"));
_url = targetServer.Urls[0];
// Thread.Sleep(TimeSpan.FromSeconds(3));
_output.WriteLine(targetServer.Urls[0]);
//while (!_cts.IsCancellationRequested)
//{
// Thread.Sleep(100);
//}
}
[Fact]
public void FluentMockServer_ProxyAndRecordSettings_ShouldProxyContentTypeHeader()
{
// Assign
_output.WriteLine("This is output fr");
//var t = new Thread(X);
//t.Start();
X();
_output.WriteLine("started");
Thread.Sleep(TimeSpan.FromSeconds(4));
_output.WriteLine("sleep 4 done");
var server = FluentMockServer.Start(
new FluentMockServerSettings
{
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = _url
}
}
);
_output.WriteLine("started 2");
_output.WriteLine(server.Urls[0]);
// Act
var response = new HttpClient().PostAsync(new Uri($"{server.Urls[0]}/{_guid}"), new StringContent("{ \"x\": 1 }", Encoding.UTF8, "application/json")).Result;
//string content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
//// Assert
//Check.That(content).IsEqualTo("{\"p\":42}");
//Check.That(response.StatusCode).IsEqualTo(HttpStatusCode.Created);
//Check.That(response.Content.Headers.GetValues("Content-Type").First()).IsEqualTo("application/json");
}
public void Dispose()
{
_cts.Cancel();
}
}
}

View File

@@ -11,7 +11,7 @@ namespace WireMock.Net.Tests
{
public class FluentMockServerSettingsTests
{
private Mock<IWireMockLogger> _loggerMock;
private readonly Mock<IWireMockLogger> _loggerMock;
public FluentMockServerSettingsTests()
{

View File

@@ -1,10 +1,8 @@
using NFluent;
using System;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
@@ -18,12 +16,12 @@ namespace WireMock.Net.Tests
public async Task FluentMockServer_Should_respond_to_request_bodyAsBase64()
{
// given
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
_server.Given(Request.Create().WithPath("/foo").UsingGet()).RespondWith(Response.Create().WithBodyFromBase64("SGVsbG8gV29ybGQ/"));
server.Given(Request.Create().WithPath("/foo").UsingGet()).RespondWith(Response.Create().WithBodyFromBase64("SGVsbG8gV29ybGQ/"));
// when
var response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0] + "/foo");
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/foo");
// then
Check.That(response).IsEqualTo("Hello World?");
@@ -33,14 +31,14 @@ namespace WireMock.Net.Tests
public async Task FluentMockServer_Should_reset_requestlogs()
{
// given
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
// when
await new HttpClient().GetAsync("http://localhost:" + _server.Ports[0] + "/foo");
_server.ResetLogEntries();
await new HttpClient().GetAsync("http://localhost:" + server.Ports[0] + "/foo");
server.ResetLogEntries();
// then
Check.That(_server.LogEntries).IsEmpty();
Check.That(server.LogEntries).IsEmpty();
}
[Fact]
@@ -48,9 +46,9 @@ namespace WireMock.Net.Tests
{
// given
string path = $"/foo_{Guid.NewGuid()}";
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
_server
server
.Given(Request.Create()
.WithPath(path)
.UsingGet())
@@ -58,12 +56,11 @@ namespace WireMock.Net.Tests
.WithBody(@"{ msg: ""Hello world!""}"));
// when
_server.ResetMappings();
server.ResetMappings();
// then
Check.That(_server.Mappings).IsEmpty();
Check.ThatAsyncCode(() => new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0] + path))
.ThrowsAny();
Check.That(server.Mappings).IsEmpty();
Check.ThatAsyncCode(() => new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + path)).ThrowsAny();
}
[Fact]
@@ -73,16 +70,16 @@ namespace WireMock.Net.Tests
string path = $"/foo_{Guid.NewGuid()}";
string pathToRedirect = $"/bar_{Guid.NewGuid()}";
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
_server
server
.Given(Request.Create()
.WithPath(path)
.UsingGet())
.RespondWith(Response.Create()
.WithStatusCode(307)
.WithHeader("Location", pathToRedirect));
_server
server
.Given(Request.Create()
.WithPath(pathToRedirect)
.UsingGet())
@@ -91,7 +88,7 @@ namespace WireMock.Net.Tests
.WithBody("REDIRECT SUCCESSFUL"));
// Act
var response = await new HttpClient().GetStringAsync($"http://localhost:{_server.Ports[0]}{path}");
var response = await new HttpClient().GetStringAsync($"http://localhost:{server.Ports[0]}{path}");
// Assert
Check.That(response).IsEqualTo("REDIRECT SUCCESSFUL");
@@ -101,9 +98,9 @@ namespace WireMock.Net.Tests
public async Task FluentMockServer_Should_delay_responses_for_a_given_route()
{
// given
var _server = FluentMockServer.Start();
var server = FluentMockServer.Start();
_server
server
.Given(Request.Create()
.WithPath("/*"))
.RespondWith(Response.Create()
@@ -113,7 +110,7 @@ namespace WireMock.Net.Tests
// when
var watch = new Stopwatch();
watch.Start();
await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0] + "/foo");
await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/foo");
watch.Stop();
// then
@@ -124,16 +121,16 @@ namespace WireMock.Net.Tests
public async Task FluentMockServer_Should_delay_responses()
{
// given
var _server = FluentMockServer.Start();
_server.AddGlobalProcessingDelay(TimeSpan.FromMilliseconds(200));
_server
var server = FluentMockServer.Start();
server.AddGlobalProcessingDelay(TimeSpan.FromMilliseconds(200));
server
.Given(Request.Create().WithPath("/*"))
.RespondWith(Response.Create().WithBody(@"{ msg: ""Hello world!""}"));
// when
var watch = new Stopwatch();
watch.Start();
await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0] + "/foo");
await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/foo");
watch.Stop();
// then

View File

@@ -8,13 +8,13 @@ namespace WireMock.Net.Tests.Handlers
{
public class LocalFileSystemHandlerTests
{
private LocalFileSystemHandler sut = new LocalFileSystemHandler();
private readonly LocalFileSystemHandler _sut = new LocalFileSystemHandler();
[Fact]
public void LocalFileSystemHandler_GetMappingFolder()
{
// Act
string result = sut.GetMappingFolder();
string result = _sut.GetMappingFolder();
// Assert
Check.That(result).EndsWith(Path.Combine("__admin", "mappings"));
@@ -24,14 +24,14 @@ namespace WireMock.Net.Tests.Handlers
public void LocalFileSystemHandler_CreateFolder_Throws()
{
// Act
Check.ThatCode(() => sut.CreateFolder(null)).Throws<ArgumentNullException>();
Check.ThatCode(() => _sut.CreateFolder(null)).Throws<ArgumentNullException>();
}
[Fact]
public void LocalFileSystemHandler_WriteMappingFile_Throws()
{
// Act
Check.ThatCode(() => sut.WriteMappingFile(null, null)).Throws<ArgumentNullException>();
Check.ThatCode(() => _sut.WriteMappingFile(null, null)).Throws<ArgumentNullException>();
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using NFluent;
using WireMock.Http;

View File

@@ -16,11 +16,11 @@ namespace WireMock.Net.Tests.Owin
{
public class GlobalExceptionMiddlewareTests
{
private Mock<IWireMockMiddlewareOptions> _optionsMock;
private Mock<IOwinResponseMapper> _responseMapperMock;
private Mock<IContext> _contextMock;
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
private readonly Mock<IOwinResponseMapper> _responseMapperMock;
private readonly Mock<IContext> _contextMock;
private GlobalExceptionMiddleware _sut;
private readonly GlobalExceptionMiddleware _sut;
public GlobalExceptionMiddlewareTests()
{

View File

@@ -21,17 +21,17 @@ namespace WireMock.Net.Tests.Owin.Mappers
{
public class OwinResponseMapperTests
{
private static Task completedTask = Task.FromResult(true);
private OwinResponseMapper _sut;
private Mock<IResponse> _responseMock;
private Mock<Stream> _stream;
private Mock<IHeaderDictionary> _headers;
private static readonly Task CompletedTask = Task.FromResult(true);
private readonly OwinResponseMapper _sut;
private readonly Mock<IResponse> _responseMock;
private readonly Mock<Stream> _stream;
private readonly Mock<IHeaderDictionary> _headers;
public OwinResponseMapperTests()
{
_stream = new Mock<Stream>();
_stream.SetupAllProperties();
_stream.Setup(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>())).Returns(completedTask);
_stream.Setup(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>())).Returns(CompletedTask);
_headers = new Mock<IHeaderDictionary>();
_headers.SetupAllProperties();
@@ -156,7 +156,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
// Assert
#if NET452
_headers.Verify(h => h.AppendValues("h", new string[] { "x", "y" } ), Times.Once);
_headers.Verify(h => h.AppendValues("h", new string[] { "x", "y" }), Times.Once);
#else
var v = new StringValues();
_headers.Verify(h => h.TryGetValue("h", out v), Times.Once);

View File

@@ -13,9 +13,8 @@ namespace WireMock.Net.Tests.Owin
{
public class MappingMatcherTests
{
private Mock<IWireMockMiddlewareOptions> _optionsMock;
private IMappingMatcher _sut;
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
private readonly IMappingMatcher _sut;
public MappingMatcherTests()
{

View File

@@ -30,14 +30,14 @@ namespace WireMock.Net.Tests.Owin
{
public class WireMockMiddlewareTests
{
private WireMockMiddleware _sut;
private readonly WireMockMiddleware _sut;
private Mock<IWireMockMiddlewareOptions> _optionsMock;
private Mock<IOwinRequestMapper> _requestMapperMock;
private Mock<IOwinResponseMapper> _responseMapperMock;
private Mock<IMappingMatcher> _matcherMock;
private Mock<IMapping> _mappingMock;
private Mock<IContext> _contextMock;
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
private readonly Mock<IOwinRequestMapper> _requestMapperMock;
private readonly Mock<IOwinResponseMapper> _responseMapperMock;
private readonly Mock<IMappingMatcher> _matcherMock;
private readonly Mock<IMapping> _mappingMock;
private readonly Mock<IContext> _contextMock;
public WireMockMiddlewareTests()
{

View File

@@ -4,7 +4,7 @@ using WireMock.Matchers.Request;
using WireMock.RequestBuilders;
using Xunit;
namespace WireMock.Net.Tests
namespace WireMock.Net.Tests.RequestBuilders
{
public class RequestBuilderUsingMethodTests
{

View File

@@ -5,7 +5,7 @@ using WireMock.Matchers.Request;
using WireMock.RequestBuilders;
using Xunit;
namespace WireMock.Net.Tests
namespace WireMock.Net.Tests.RequestBuilders
{
public class RequestBuilderWithBodyTests
{

View File

@@ -5,7 +5,7 @@ using WireMock.Matchers.Request;
using WireMock.RequestBuilders;
using Xunit;
namespace WireMock.Net.Tests
namespace WireMock.Net.Tests.RequestBuilders
{
public class RequestBuilderWithCookieTests
{

View File

@@ -2,12 +2,10 @@
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests
namespace WireMock.Net.Tests.RequestBuilders
{
public class RequestBuilderWithHeaderTests
{

View File

@@ -2,12 +2,10 @@
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests
namespace WireMock.Net.Tests.RequestBuilders
{
public class RequestBuilderWithParamTests
{

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using NFluent;
using WireMock.Matchers.Request;
using WireMock.Models;

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Moq;
using NFluent;

View File

@@ -1,5 +1,4 @@
using System;
using NFluent;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;

View File

@@ -1,5 +1,4 @@
using System;
using NFluent;
using NFluent;
using WireMock.Models;
using WireMock.Util;
using Xunit;

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using NFluent;
using Xunit;
using WireMock.RequestBuilders;

View File

@@ -1,4 +1,3 @@
using System;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using NFluent;
using WireMock.Matchers;
using Xunit;

View File

@@ -1,5 +1,4 @@
using System;
using NFluent;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;

View File

@@ -4,7 +4,7 @@ using WireMock.Models;
using WireMock.ResponseBuilders;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseCreateTests
{

View File

@@ -6,7 +6,7 @@ using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithBodyTests
{

View File

@@ -4,7 +4,7 @@ using WireMock.Models;
using WireMock.ResponseBuilders;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithCallbackTests
{

View File

@@ -7,7 +7,7 @@ using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHandlebarsJsonPathTests
{

View File

@@ -7,7 +7,7 @@ using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHandlebarsLinqTests
{

View File

@@ -5,7 +5,7 @@ using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHandlebarsRegexTests
{

View File

@@ -2,19 +2,19 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
#if NET452
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif
using Newtonsoft.Json;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
#if NET452
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHandlebarsTests
{

View File

@@ -6,7 +6,7 @@ using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHeadersTests
{

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithProxyTests : IDisposable
{
private readonly FluentMockServer _server;
private readonly Guid _guid;
public ResponseWithProxyTests()
{
_guid = Guid.NewGuid();
_server = FluentMockServer.Start();
_server.Given(Request.Create().UsingPost().WithPath($"/{_guid}"))
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 42 }).WithHeader("Content-Type", "application/json"));
}
[Fact]
public async Task Response_WithProxy()
{
// Assign
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}/{_guid}"), "POST", "::1", new BodyData { BodyAsJson = new { a = 1 } }, headers);
var response = Response.Create().WithProxy(_server.Urls[0]);
// Act
var responseMessage = await response.ProvideResponseAsync(request);
// Assert
Check.That(responseMessage.Body).IsEqualTo("{\"p\":42}");
Check.That(responseMessage.StatusCode).IsEqualTo(201);
Check.That(responseMessage.Headers["Content-Type"].ToString()).IsEqualTo("application/json");
}
public void Dispose()
{
_server?.Dispose();
}
}
}

View File

@@ -0,0 +1,103 @@
using NFluent;
using WireMock.Net.StandAlone;
using Xunit;
namespace WireMock.Net.Tests.StandAlone
{
public class SimpleCommandLineParserTests
{
private readonly SimpleCommandLineParser _parser;
public SimpleCommandLineParserTests()
{
_parser = new SimpleCommandLineParser();
}
[Fact]
public void SimpleCommandLineParser_Parse_Arguments()
{
// Assign
_parser.Parse(new[] { "--test1", "one", "--test2", "two", "--test3", "three" });
// Act
string value1 = _parser.GetStringValue("test1");
string value2 = _parser.GetStringValue("test2");
string value3 = _parser.GetStringValue("test3");
// Assert
Check.That(value1).IsEqualTo("one");
Check.That(value2).IsEqualTo("two");
Check.That(value3).IsEqualTo("three");
}
[Fact]
public void SimpleCommandLineParser_Parse_ArgumentsWithSingleQuotes()
{
// Assign
_parser.Parse(new[] { "'--test1", "one'", "'--test2", "two'", "'--test3", "three'" });
// Act
string value1 = _parser.GetStringValue("test1");
string value2 = _parser.GetStringValue("test2");
string value3 = _parser.GetStringValue("test3");
// Assert
Check.That(value1).IsEqualTo("one");
Check.That(value2).IsEqualTo("two");
Check.That(value3).IsEqualTo("three");
}
[Fact]
public void SimpleCommandLineParser_Parse_ArgumentsMixed()
{
// Assign
_parser.Parse(new[] { "'--test1", "one'", "--test2", "two", "--test3", "three" });
// Act
string value1 = _parser.GetStringValue("test1");
string value2 = _parser.GetStringValue("test2");
string value3 = _parser.GetStringValue("test3");
// Assert
Check.That(value1).IsEqualTo("one");
Check.That(value2).IsEqualTo("two");
Check.That(value3).IsEqualTo("three");
}
[Fact]
public void SimpleCommandLineParser_Parse_GetBoolValue()
{
// Assign
_parser.Parse(new[] { "'--test1", "false'", "--test2", "true" });
// Act
bool value1 = _parser.GetBoolValue("test1");
bool value2 = _parser.GetBoolValue("test2");
bool value3 = _parser.GetBoolValue("test3", true);
// Assert
Check.That(value1).IsEqualTo(false);
Check.That(value2).IsEqualTo(true);
Check.That(value3).IsEqualTo(true);
}
[Fact]
public void SimpleCommandLineParser_Parse_GetIntValue()
{
// Assign
_parser.Parse(new[] { "'--test1", "42'", "--test2", "55" });
// Act
int? value1 = _parser.GetIntValue("test1");
int? value2 = _parser.GetIntValue("test2");
int? value3 = _parser.GetIntValue("test3", 100);
int? value4 = _parser.GetIntValue("test4");
// Assert
Check.That(value1).IsEqualTo(42);
Check.That(value2).IsEqualTo(55);
Check.That(value3).IsEqualTo(100);
Check.That(value4).IsNull();
}
}
}

View File

@@ -14,31 +14,31 @@ namespace WireMock.Net.Tests.Util
public void FileHelper_ReadAllTextWithRetryAndDelay()
{
// Assign
var _staticMappingHandlerMock = new Mock<IFileSystemHandler>();
_staticMappingHandlerMock.Setup(m => m.ReadMappingFile(It.IsAny<string>())).Returns("text");
var staticMappingHandlerMock = new Mock<IFileSystemHandler>();
staticMappingHandlerMock.Setup(m => m.ReadMappingFile(It.IsAny<string>())).Returns("text");
// Act
string result = FileHelper.ReadAllTextWithRetryAndDelay(_staticMappingHandlerMock.Object, @"c:\temp");
string result = FileHelper.ReadAllTextWithRetryAndDelay(staticMappingHandlerMock.Object, @"c:\temp");
// Assert
Check.That(result).Equals("text");
// Verify
_staticMappingHandlerMock.Verify(m => m.ReadMappingFile(@"c:\temp"), Times.Once);
staticMappingHandlerMock.Verify(m => m.ReadMappingFile(@"c:\temp"), Times.Once);
}
[Fact]
public void FileHelper_ReadAllTextWithRetryAndDelay_Throws()
{
// Assign
var _staticMappingHandlerMock = new Mock<IFileSystemHandler>();
_staticMappingHandlerMock.Setup(m => m.ReadMappingFile(It.IsAny<string>())).Throws<NotSupportedException>();
var staticMappingHandlerMock = new Mock<IFileSystemHandler>();
staticMappingHandlerMock.Setup(m => m.ReadMappingFile(It.IsAny<string>())).Throws<NotSupportedException>();
// Act
Check.ThatCode(() => FileHelper.ReadAllTextWithRetryAndDelay(_staticMappingHandlerMock.Object, @"c:\temp")).Throws<IOException>();
Check.ThatCode(() => FileHelper.ReadAllTextWithRetryAndDelay(staticMappingHandlerMock.Object, @"c:\temp")).Throws<IOException>();
// Verify
_staticMappingHandlerMock.Verify(m => m.ReadMappingFile(@"c:\temp"), Times.Exactly(3));
staticMappingHandlerMock.Verify(m => m.ReadMappingFile(@"c:\temp"), Times.Exactly(3));
}
}
}

View File

@@ -13,6 +13,10 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<Compile Remove="FluentMockServerTests.Proxy2.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />