Compare commits

..

4 Commits
1.4.6 ... 1.4.7

Author SHA1 Message Date
Stef Heyenrath
cee73023c7 1.4.7 2021-03-21 09:22:18 +01:00
Ben Arnold
6f7d2c83f5 Remove an approximate two second delay in response to the first request from a new socket connection, only occuring on some Windows 10 machines. (#597)
A side-effect of this fix is that is also allows connections to IPv6 addresses.
2021-03-21 09:12:19 +01:00
Stef Heyenrath
2fb0f92a2d Use Handlebars.Net.Helpers Version="2.1.2" (#595) 2021-03-19 15:17:39 +01:00
Stef Heyenrath
ddf2b49240 wip (#594) 2021-03-18 14:29:13 +01:00
12 changed files with 196 additions and 80 deletions

View File

@@ -1,3 +1,8 @@
# 1.4.7 (21 March 2021)
- [#594](https://github.com/WireMock-Net/WireMock.Net/pull/594) - Add possibility to the WithBody() to use IBodyData [feature] contributed by [StefH](https://github.com/StefH)
- [#595](https://github.com/WireMock-Net/WireMock.Net/pull/595) - Use Handlebars.Net.Helpers Version="2.1.2" [feature] contributed by [StefH](https://github.com/StefH)
- [#597](https://github.com/WireMock-Net/WireMock.Net/pull/597) - Remove 2 second delay from first response and add IPv6 address support [bug, feature] contributed by [benagain](https://github.com/benagain)
# 1.4.6 (26 February 2021)
- [#587](https://github.com/WireMock-Net/WireMock.Net/pull/587) - Fix WithCallback logic when using other fluent builder statements [bug] contributed by [StefH](https://github.com/StefH)
- [#569](https://github.com/WireMock-Net/WireMock.Net/issues/569) - WithCallback circumvent the rest of the builder [bug]
@@ -43,6 +48,7 @@
- [#549](https://github.com/WireMock-Net/WireMock.Net/issues/549) - WithProxy(...) does not save the mappings to file [bug]
# 1.3.8 (03 December 2020)
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
- [#542](https://github.com/WireMock-Net/WireMock.Net/pull/542) - Create dotnet-wiremock tool [feature] contributed by [StefH](https://github.com/StefH)
- [#543](https://github.com/WireMock-Net/WireMock.Net/pull/543) - Add support for .NET 5 [feature] contributed by [StefH](https://github.com/StefH)
- [#544](https://github.com/WireMock-Net/WireMock.Net/pull/544) - Use Java 11 in Azure Pipelines (needed for SonarCloud) [feature] contributed by [StefH](https://github.com/StefH)
@@ -50,9 +56,6 @@
- [#547](https://github.com/WireMock-Net/WireMock.Net/pull/547) - Fix Proxying with SSL and NetCoreApp3.1 [bug] contributed by [StefH](https://github.com/StefH)
- [#524](https://github.com/WireMock-Net/WireMock.Net/issues/524) - Proxying with SSL Not Working in .NET Core 3.1 [bug]
# 1.3.7 (17 November 2020)
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
# 1.3.6 (10 November 2020)
- [#529](https://github.com/WireMock-Net/WireMock.Net/pull/529) - Add assertions for ClientIP, Url and ProxyUrl [feature] contributed by [akamud](https://github.com/akamud)
- [#535](https://github.com/WireMock-Net/WireMock.Net/pull/535) - WithCallback should use also use enum HttpStatusCode [bug] contributed by [StefH](https://github.com/StefH)

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.4.6</VersionPrefix>
<VersionPrefix>1.4.7</VersionPrefix>
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>

View File

@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.4.6
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.4.7

View File

@@ -1,70 +1,79 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using log4net;
using log4net.Config;
using log4net.Repository;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
namespace WireMock.Net.StandAlone.NETCoreApp
{
static class Program
{
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
// private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
private static int sleepTime = 30000;
private static WireMockServer _server;
static void Main(string[] args)
{
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using log4net;
using log4net.Config;
using log4net.Repository;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
using WireMock.Util;
namespace WireMock.Net.StandAlone.NETCoreApp
{
static class Program
{
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
// private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
private static int sleepTime = 30000;
private static WireMockServer _server;
static void Main(string[] args)
{
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
if (!WireMockServerSettingsParser.TryParseArguments(args, out var settings, new WireMockLog4NetLogger()))
{
return;
}
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
_server = WireMockServer.Start(settings);
_server
.Given(Request.Create()
.UsingAnyMethod())
.RespondWith(Response.Create()
.WithTransformer()
.WithBody("{{Random Type=\"Integer\" Min=100 Max=999999}} {{DateTime.Now}} {{DateTime.Now \"yyyy-MMM\"}} {{String.Format (DateTime.Now) \"MMM-dd\"}}"));
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
Console.CancelKeyPress += (s, e) =>
{
Stop("CancelKeyPress");
};
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
{
Stop("AssemblyLoadContext.Default.Unloading");
};
while (true)
{
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running : {_server.IsStarted}");
Thread.Sleep(sleepTime);
}
}
private static void Stop(string why)
{
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
_server.Stop();
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
}
}
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
_server = WireMockServer.Start(settings);
_server.Given(Request.Create().WithPath("/api/sap")
.UsingPost()
.WithBody((IBodyData xmlData) => {
//xmlData is always null
return true;
}))
.RespondWith(Response.Create().WithStatusCode(System.Net.HttpStatusCode.OK));
_server
.Given(Request.Create()
.UsingAnyMethod())
.RespondWith(Response.Create()
.WithTransformer()
.WithBody("{{Random Type=\"Integer\" Min=100 Max=999999}} {{DateTime.Now}} {{DateTime.Now \"yyyy-MMM\"}} {{String.Format (DateTime.Now) \"MMM-dd\"}}"));
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
Console.CancelKeyPress += (s, e) =>
{
Stop("CancelKeyPress");
};
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
{
Stop("AssemblyLoadContext.Default.Unloading");
};
while (true)
{
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running : {_server.IsStarted}");
Thread.Sleep(sleepTime);
}
}
private static void Stop(string why)
{
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
_server.Stop();
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
}
}
}

View File

@@ -2,6 +2,7 @@ using JetBrains.Annotations;
using System;
using System.Linq;
using WireMock.Types;
using WireMock.Util;
using WireMock.Validation;
namespace WireMock.Matchers.Request
@@ -26,6 +27,11 @@ namespace WireMock.Matchers.Request
/// </summary>
public Func<object, bool> JsonFunc { get; }
/// <summary>
/// The body data function for BodyData
/// </summary>
public Func<IBodyData, bool> BodyDataFunc { get; }
/// <summary>
/// The matchers.
/// </summary>
@@ -88,6 +94,16 @@ namespace WireMock.Matchers.Request
JsonFunc = func;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="func">The function.</param>
public RequestMessageBodyMatcher([NotNull] Func<IBodyData, bool> func)
{
Check.NotNull(func, nameof(func));
BodyDataFunc = func;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
@@ -158,6 +174,11 @@ namespace WireMock.Matchers.Request
return MatchScores.ToScore(DataFunc(requestMessage?.BodyData?.BodyAsBytes));
}
if (BodyDataFunc != null)
{
return MatchScores.ToScore(BodyDataFunc(requestMessage?.BodyData));
}
return MatchScores.Mismatch;
}
}

View File

@@ -24,7 +24,7 @@ namespace WireMock.Owin
{
if (urlDetail.IsHttps)
{
kestrelOptions.Listen(System.Net.IPAddress.Any, urlDetail.Port, listenOptions =>
kestrelOptions.ListenAnyIP(urlDetail.Port, listenOptions =>
{
if (wireMockMiddlewareOptions.CustomCertificateDefined)
{
@@ -45,7 +45,7 @@ namespace WireMock.Owin
}
else
{
kestrelOptions.Listen(System.Net.IPAddress.Any, urlDetail.Port);
kestrelOptions.ListenAnyIP(urlDetail.Port);
}
}
}

View File

@@ -106,7 +106,7 @@ namespace WireMock.Owin
foreach (string address in addresses)
{
Urls.Add(address.Replace("0.0.0.0", "localhost"));
Urls.Add(address.Replace("0.0.0.0", "localhost").Replace("[::]", "localhost"));
PortUtils.TryExtract(address, out bool isHttps, out string protocol, out string host, out int port);
Ports.Add(port);

View File

@@ -2,7 +2,8 @@
using System;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Util;
namespace WireMock.RequestBuilders
{
/// <summary>
@@ -63,10 +64,17 @@ namespace WireMock.RequestBuilders
IRequestBuilder WithBody([NotNull] Func<byte[], bool> func);
/// <summary>
/// WithBody: func (object)
/// WithBody: func (json object)
/// </summary>
/// <param name="func">The function.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody([NotNull] Func<object, bool> func);
/// <summary>
/// WithBody: func (BodyData object)
/// </summary>
/// <param name="func">The function.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithBody([NotNull] Func<IBodyData, bool> func);
}
}

View File

@@ -3,6 +3,7 @@
using System;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Util;
using WireMock.Validation;
namespace WireMock.RequestBuilders
@@ -71,5 +72,14 @@ namespace WireMock.RequestBuilders
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{IBodyData, bool})"/>
public IRequestBuilder WithBody(Func<IBodyData, bool> func)
{
Check.NotNull(func, nameof(func));
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
}
}

View File

@@ -121,12 +121,12 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Handlebars.Net.Helpers" Version="2.1.1" />
<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.1.1" />
<PackageReference Include="Handlebars.Net.Helpers.Json" Version="2.1.1" />
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.1.1" />
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.1.1" />
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.1.1" />
<PackageReference Include="Handlebars.Net.Helpers" Version="2.1.2" />
<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.1.2" />
<PackageReference Include="Handlebars.Net.Helpers.Json" Version="2.1.2" />
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.1.2" />
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.1.2" />
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.1.2" />
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
</ItemGroup>

View File

@@ -54,6 +54,25 @@ namespace WireMock.Net.Tests
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
}
[Fact]
public void Request_WithBody_FuncBodyData()
{
// Assign
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((IBodyData b) => b != null);
// Act
var body = new BodyData
{
BodyAsJson = 123,
DetectedBodyType = BodyType.Json
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
}
[Fact]
public void Request_WithBody_FuncByteArray()
{

View File

@@ -305,5 +305,51 @@ namespace WireMock.Net.Tests
server.Stop();
}
#if !NET452
[Fact]
public async Task WireMockServer_Should_respond_to_ipv4_loopback()
{
// Assign
var server = WireMockServer.Start();
server
.Given(Request.Create()
.WithPath("/*"))
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBody("from ipv4 loopback"));
// Act
var response = await new HttpClient().GetStringAsync($"http://127.0.0.1:{server.Ports[0]}/foo");
// Assert
Check.That(response).IsEqualTo("from ipv4 loopback");
server.Stop();
}
[Fact]
public async Task WireMockServer_Should_respond_to_ipv6_loopback()
{
// Assign
var server = WireMockServer.Start();
server
.Given(Request.Create()
.WithPath("/*"))
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBody("from ipv6 loopback"));
// Act
var response = await new HttpClient().GetStringAsync($"http://[::1]:{server.Ports[0]}/foo");
// Assert
Check.That(response).IsEqualTo("from ipv6 loopback");
server.Stop();
}
#endif
}
}