Compare commits

..

15 Commits

Author SHA1 Message Date
Stef Heyenrath
6784614814 1.0.1.5 2017-03-21 14:49:45 +01:00
Stef Heyenrath
e9ee4e91f9 HttpListener : Stop fix 2017-03-21 14:45:34 +01:00
Stef Heyenrath
9fcfb3109f fix MappingsSave 2017-03-21 10:52:32 +01:00
Stef Heyenrath
d0cdfe5dc3 add coveralls.io badge 2017-03-21 09:10:25 +01:00
Stef Heyenrath
f06b89fa06 FluentMockServer_ReadStaticMappings 2017-03-21 09:05:57 +01:00
Stef Heyenrath
e9e4ee7e9d fix AppVeyor tests 2017-03-21 08:59:49 +01:00
Stef Heyenrath
d62c81acd8 test 2017-03-21 08:14:56 +01:00
Stef Heyenrath
3bdc9c375b added sdk to global.json 2017-03-21 08:06:47 +01:00
Stef Heyenrath
780e14f214 DotNetCore.1.0.1-SDK.1.0.0.Preview2-003133-x64.exe 2017-03-20 23:12:51 +01:00
Stef Heyenrath
f50e87c9ba dotnet-1.1.1-sdk-win-x64.exe 2017-03-20 21:01:14 +01:00
Stef Heyenrath
5145ecb396 dotnet test 2017-03-20 20:55:24 +01:00
Stef Heyenrath
d731aefc82 test test 2017-03-20 18:55:37 +01:00
Stef Heyenrath
5ac375ef26 opencover dotnet 2017-03-20 18:25:44 +01:00
Stef Heyenrath
ffd5322587 OpenCover xunit 2017-03-20 18:21:04 +01:00
Stef Heyenrath
81211d1ce3 opencover xunit 2017-03-20 18:17:21 +01:00
13 changed files with 93 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) w
[![Build status](https://ci.appveyor.com/api/projects/status/b3n6q3ygbww4lyls?svg=true)](https://ci.appveyor.com/project/StefH/wiremock-net)
[![codecov](https://codecov.io/gh/StefH/WireMock.Net/branch/master/graph/badge.svg)](https://codecov.io/gh/StefH/WireMock.Net)
[![Coverage Status](https://coveralls.io/repos/github/StefH/WireMock.Net/badge.svg?branch=master)](https://coveralls.io/github/StefH/WireMock.Net?branch=master)
[![NuGet Badge](https://buildstats.info/nuget/WireMock.Net)](https://www.nuget.org/packages/WireMock.Net)
## Stubbing

View File

@@ -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"

View File

@@ -1,3 +1,6 @@
{
"projects": [ "src", "test" ]
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003133"
}
}

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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",

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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();

View File

@@ -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]

View File

@@ -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" }
}
}
},