mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-21 00:08:05 +01:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6784614814 | ||
|
|
e9ee4e91f9 | ||
|
|
9fcfb3109f | ||
|
|
d0cdfe5dc3 | ||
|
|
f06b89fa06 | ||
|
|
e9e4ee7e9d | ||
|
|
d62c81acd8 | ||
|
|
3bdc9c375b | ||
|
|
780e14f214 | ||
|
|
f50e87c9ba | ||
|
|
5145ecb396 | ||
|
|
d731aefc82 | ||
|
|
5ac375ef26 | ||
|
|
ffd5322587 | ||
|
|
81211d1ce3 |
@@ -3,6 +3,7 @@ A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) w
|
||||
|
||||
[](https://ci.appveyor.com/project/StefH/wiremock-net)
|
||||
[](https://codecov.io/gh/StefH/WireMock.Net)
|
||||
[](https://coveralls.io/github/StefH/WireMock.Net?branch=master)
|
||||
[](https://www.nuget.org/packages/WireMock.Net)
|
||||
|
||||
## Stubbing
|
||||
|
||||
16
appveyor.yml
16
appveyor.yml
@@ -1,6 +1,6 @@
|
||||
os: Visual Studio 2015
|
||||
|
||||
version: 1.0.0.{build}
|
||||
version: 1.0.1.{build}
|
||||
|
||||
configuration:
|
||||
- Debug
|
||||
@@ -36,15 +36,19 @@ build_script:
|
||||
|
||||
- dotnet pack -c %CONFIGURATION% --no-build --version-suffix %LABEL% -o .\artifacts .\src\WireMock.Net\project.json
|
||||
|
||||
test_script:
|
||||
#test_script:
|
||||
# test WireMock.Net.Tests
|
||||
- cd .\test\WireMock.Net.Tests
|
||||
- dotnet test -c %CONFIGURATION% --no-build
|
||||
# - cd .\test\WireMock.Net.Tests
|
||||
# - dotnet test -c %CONFIGURATION% --no-build
|
||||
# - cd ..
|
||||
# - cd ..
|
||||
|
||||
after_test:
|
||||
test_script:
|
||||
- nuget.exe install OpenCover -ExcludeVersion
|
||||
- nuget.exe install coveralls.net -ExcludeVersion
|
||||
- OpenCover\tools\OpenCover.Console.exe -register:user -target:"nunit3-console.exe" -targetargs:"\".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452\win7-x64\WireMock.Net.Tests.dll\" --result=myresults.xml;format=AppVeyor" -returntargetcode -filter:"+[WireMock.Net]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:coverage.xml
|
||||
# - OpenCover\tools\OpenCover.Console.exe -register:user -target:nunit3-console.exe -targetargs:"\".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452\win7-x64\WireMock.Net.Tests.dll\" --result=myresults.xml;format=AppVeyor" -returntargetcode -filter:"+[WireMock.Net]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:coverage.xml
|
||||
# - OpenCover\tools\OpenCover.Console.exe -register:user -target:xunit.console.clr4.exe "-targetargs:"\".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452\win7-x64\WireMock.Net.Tests.dll\" --result=myresults.xml;format=AppVeyor" -filter:"+[WireMock.Net]*" -output:coverage.xml
|
||||
- OpenCover\tools\OpenCover.Console.exe -register:user -target:"dotnet.exe" -searchdirs:".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452\win7-x64" -oldstyle -targetargs:"test .\test\WireMock.Net.Tests" -returntargetcode -filter:"+[WireMock.Net]*" -output:coverage.xml
|
||||
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
|
||||
- pip install codecov
|
||||
- codecov -f "coverage.xml"
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"projects": [ "src", "test" ]
|
||||
"projects": [ "src", "test" ],
|
||||
"sdk": {
|
||||
"version": "1.0.0-preview2-003133"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace WireMock.Http
|
||||
/// </summary>
|
||||
public class TinyHttpServer
|
||||
{
|
||||
private readonly Action<HttpListenerContext> _httpHandler;
|
||||
private readonly Action<HttpListenerContext, CancellationToken> _httpHandler;
|
||||
|
||||
private readonly HttpListener _listener;
|
||||
|
||||
private CancellationTokenSource _cts;
|
||||
private readonly CancellationTokenSource _cts;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this server is started.
|
||||
@@ -33,6 +33,7 @@ namespace WireMock.Http
|
||||
/// <value>
|
||||
/// The urls.
|
||||
/// </value>
|
||||
[PublicAPI]
|
||||
public List<Uri> Urls { get; } = new List<Uri>();
|
||||
|
||||
/// <summary>
|
||||
@@ -41,6 +42,7 @@ namespace WireMock.Http
|
||||
/// <value>
|
||||
/// The ports.
|
||||
/// </value>
|
||||
[PublicAPI]
|
||||
public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
/// <summary>
|
||||
@@ -48,11 +50,13 @@ namespace WireMock.Http
|
||||
/// </summary>
|
||||
/// <param name="uriPrefixes">The uriPrefixes.</param>
|
||||
/// <param name="httpHandler">The http handler.</param>
|
||||
public TinyHttpServer([NotNull] Action<HttpListenerContext> httpHandler, [NotNull] params string[] uriPrefixes)
|
||||
public TinyHttpServer([NotNull] Action<HttpListenerContext, CancellationToken> httpHandler, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
Check.NotNull(httpHandler, nameof(httpHandler));
|
||||
Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
|
||||
_httpHandler = httpHandler;
|
||||
|
||||
// Create a listener.
|
||||
@@ -70,22 +74,26 @@ namespace WireMock.Http
|
||||
/// <summary>
|
||||
/// Start the server.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public void Start()
|
||||
{
|
||||
_listener.Start();
|
||||
|
||||
IsStarted = true;
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
Task.Run(
|
||||
async () =>
|
||||
{
|
||||
using (_listener)
|
||||
//using (_listener)
|
||||
{
|
||||
while (!_cts.Token.IsCancellationRequested)
|
||||
{
|
||||
HttpListenerContext context = await _listener.GetContextAsync();
|
||||
_httpHandler(context);
|
||||
_httpHandler(context, _cts.Token);
|
||||
}
|
||||
|
||||
_listener.Stop();
|
||||
IsStarted = false;
|
||||
}
|
||||
},
|
||||
_cts.Token);
|
||||
@@ -94,8 +102,11 @@ namespace WireMock.Http
|
||||
/// <summary>
|
||||
/// Stop the server.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public void Stop()
|
||||
{
|
||||
_listener?.Stop();
|
||||
|
||||
_cts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace WireMock.Server
|
||||
#region Mappings
|
||||
private ResponseMessage MappingsSave(RequestMessage requestMessage)
|
||||
{
|
||||
string folder = Directory.GetCurrentDirectory() + AdminMappingsFolder;
|
||||
string folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
|
||||
if (!Directory.Exists(folder))
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Validation;
|
||||
using System.Threading;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
@@ -255,7 +256,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public void Stop()
|
||||
{
|
||||
_httpServer.Stop();
|
||||
_httpServer?.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -432,13 +433,17 @@ namespace WireMock.Server
|
||||
/// The handle request.
|
||||
/// </summary>
|
||||
/// <param name="ctx">The HttpListenerContext.</param>
|
||||
private async void HandleRequestAsync(HttpListenerContext ctx)
|
||||
/// <param name="cancel">The CancellationToken.</param>
|
||||
private async void HandleRequestAsync(HttpListenerContext ctx, CancellationToken cancel)
|
||||
{
|
||||
if (cancel.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
if (_requestProcessingDelay > TimeSpan.Zero)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
Task.Delay(_requestProcessingDelay.Value).Wait();
|
||||
Task.Delay(_requestProcessingDelay.Value, cancel).Wait(cancel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.1.3",
|
||||
"version": "1.0.1.5",
|
||||
"title": "WireMock.Net",
|
||||
"description": "Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.",
|
||||
"authors": [ "Alexandre Victoor", "Stef Heyenrath" ],
|
||||
@@ -15,7 +15,7 @@
|
||||
"projectUrl": "https://github.com/StefH/WireMock.Net",
|
||||
"iconUrl": "https://raw.githubusercontent.com/StefH/WireMock.Net/master/WireMock.Net-Logo.png",
|
||||
"licenseUrl": "https://raw.githubusercontent.com/StefH/WireMock.Net/master/LICENSE",
|
||||
"releaseNotes": "Updated Start() method and added ReadStaticMapping."
|
||||
"releaseNotes": "Fix StartAndStop from listener."
|
||||
},
|
||||
|
||||
"buildOptions": {
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
"dependencies": {
|
||||
"JetBrains.Annotations": {
|
||||
"version": "10.2.1",
|
||||
"version": "10.4.0",
|
||||
"type": "build"
|
||||
},
|
||||
"Handlebars.Net": "1.8.0",
|
||||
|
||||
@@ -20,6 +20,26 @@ namespace WireMock.Net.Tests
|
||||
{
|
||||
private FluentMockServer _server;
|
||||
|
||||
// For for AppVeyor + OpenCover
|
||||
private string GetCurrentFolder()
|
||||
{
|
||||
string current = Directory.GetCurrentDirectory();
|
||||
if (!current.EndsWith("WireMock.Net.Tests"))
|
||||
return Path.Combine(current, "test", "WireMock.Net.Tests");
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FluentMockServer_StartStop()
|
||||
{
|
||||
var server1 = FluentMockServer.Start("http://localhost:9090/");
|
||||
server1.Stop();
|
||||
|
||||
var server2 = FluentMockServer.Start("http://localhost:9090/");
|
||||
server2.Stop();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FluentMockServer_ReadStaticMapping_WithNonGuidFilename()
|
||||
{
|
||||
@@ -28,7 +48,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
string folder = Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings", "documentdb_root.json");
|
||||
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", "documentdb_root.json");
|
||||
_server.ReadStaticMapping(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
@@ -46,7 +66,7 @@ namespace WireMock.Net.Tests
|
||||
string guid = "00000002-ee28-4f29-ae63-1ac9b0802d86";
|
||||
|
||||
_server = FluentMockServer.Start();
|
||||
string folder = Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings", guid + ".json");
|
||||
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", guid + ".json");
|
||||
_server.ReadStaticMapping(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
@@ -61,7 +81,10 @@ namespace WireMock.Net.Tests
|
||||
[Test]
|
||||
public void FluentMockServer_ReadStaticMappings()
|
||||
{
|
||||
_server = FluentMockServer.Start(new FluentMockServerSettings { ReadStaticMappings = true });
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings");
|
||||
_server.ReadStaticMappings(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
Check.That(mappings).HasSize(2);
|
||||
@@ -307,7 +330,7 @@ namespace WireMock.Net.Tests
|
||||
watch.Stop();
|
||||
|
||||
// then
|
||||
Check.That(watch.ElapsedMilliseconds).IsGreaterThan(200);
|
||||
Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -327,13 +350,13 @@ namespace WireMock.Net.Tests
|
||||
watch.Stop();
|
||||
|
||||
// then
|
||||
Check.That(watch.ElapsedMilliseconds).IsGreaterThan(200);
|
||||
Check.That(watch.ElapsedMilliseconds).IsStrictlyGreaterThan(200);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void ShutdownServer()
|
||||
{
|
||||
_server.Stop();
|
||||
_server?.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace WireMock.Net.Tests.Http
|
||||
var port = PortUtil.FindFreeTcpPort();
|
||||
bool called = false;
|
||||
var urlPrefix = "http://localhost:" + port + "/";
|
||||
var server = new TinyHttpServer(ctx => called = true, urlPrefix);
|
||||
var server = new TinyHttpServer((ctx, token) => called = true, urlPrefix);
|
||||
server.Start();
|
||||
|
||||
// when
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using NUnit.Framework;
|
||||
@@ -103,7 +104,7 @@ namespace WireMock.Net.Tests
|
||||
{
|
||||
private static volatile RequestMessage _lastRequestMessage;
|
||||
|
||||
private MapperServer(Action<HttpListenerContext> httpHandler, string urlPrefix) : base(httpHandler, urlPrefix)
|
||||
private MapperServer(Action<HttpListenerContext, CancellationToken> httpHandler, string urlPrefix) : base(httpHandler, urlPrefix)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ namespace WireMock.Net.Tests
|
||||
int port = PortUtil.FindFreeTcpPort();
|
||||
UrlPrefix = "http://localhost:" + port + "/";
|
||||
var server = new MapperServer(
|
||||
context =>
|
||||
(context, token) =>
|
||||
{
|
||||
LastRequestMessage = new HttpListenerRequestMapper().Map(context.Request);
|
||||
context.Response.Close();
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace WireMock.Net.Tests
|
||||
var responseReady = new AutoResetEvent(false);
|
||||
HttpListenerResponse response = null;
|
||||
_server = new TinyHttpServer(
|
||||
context =>
|
||||
(context, token) =>
|
||||
{
|
||||
response = context.Response;
|
||||
responseReady.Set();
|
||||
|
||||
@@ -334,7 +334,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsLessThan(1.0);
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(1.0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -350,7 +350,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsLessThan(1.0).And.IsGreaterThan(0.5);
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -366,7 +366,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsLessThan(0.1).And.IsGreaterThan(0.05);
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -2,19 +2,24 @@
|
||||
"version": "1.0.0-*",
|
||||
"authors": [ "Stef Heyenrath" ],
|
||||
|
||||
"buildOptions": { "debugType": "portable" },
|
||||
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.Testing.Abstractions": "1.0.0-preview2-003121",
|
||||
"Moq": "4.7.1",
|
||||
"NUnit": "3.6.1",
|
||||
"dotnet-test-nunit": "3.4.0-beta-3",
|
||||
"NFluent": "2.0.0-alpha",
|
||||
"SimMetrics.Net": "1.0.1.0",
|
||||
"WireMock.Net": { "target": "project" }
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net452": {
|
||||
"frameworkAssemblies": {
|
||||
"System.Net.Http": { "type": "build" }
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"dotnet-test-nunit": "3.4.0-beta-3",
|
||||
"Moq": "4.7.0",
|
||||
"NFluent": "1.3.1",
|
||||
"NUnit": "3.6.0",
|
||||
"SimMetrics.Net": "1.0.1.0",
|
||||
"WireMock.Net": { "target": "project" }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user