mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-21 00:08:05 +01:00
Compare commits
11 Commits
stef-847-r
...
stef-849
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88ff2a72db | ||
|
|
d5026e83b5 | ||
|
|
b6b17d80cc | ||
|
|
c8ad9f49e4 | ||
|
|
0a4aca9ae9 | ||
|
|
e5ed6036ee | ||
|
|
7b534635b9 | ||
|
|
1562958172 | ||
|
|
35d42a5c0d | ||
|
|
429d6830ae | ||
|
|
38634ac65a |
@@ -1,3 +1,8 @@
|
||||
# 1.5.11 (24 November 2022)
|
||||
- [#836](https://github.com/WireMock-Net/WireMock.Net/pull/836) - Add Settings.QueryParameterMultipleValueSupport [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#848](https://github.com/WireMock-Net/WireMock.Net/pull/848) - Use try-catch when adding or removing logEntry [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#846](https://github.com/WireMock-Net/WireMock.Net/issues/846) - Exception ArgumentOutOfRangeException [bug]
|
||||
|
||||
# 1.5.10 (06 November 2022)
|
||||
- [#843](https://github.com/WireMock-Net/WireMock.Net/pull/843) - Webhook Templating: Use the transformed URL to create the HttpRequestMessage contributed by [ggradnig](https://github.com/ggradnig)
|
||||
- [#845](https://github.com/WireMock-Net/WireMock.Net/pull/845) - Add WireMockNullLogger as valid commandline logger option [feature] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.5.10</VersionPrefix>
|
||||
<VersionPrefix>1.5.11</VersionPrefix>
|
||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
@@ -20,6 +20,13 @@
|
||||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- https://github.com/coverlet-coverage/coverlet/issues/1391 -->
|
||||
<PropertyGroup Condition="$(MSBuildProjectName.Contains('.Tests'))">
|
||||
<CollectCoverage>true</CollectCoverage>
|
||||
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
|
||||
<CoverletOutputFormat>opencover</CoverletOutputFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../../resources/WireMock.Net-Logo.png" Pack="true" PackagePath="" />
|
||||
<!--<None Include="../../PackageReadme.md" Pack="true" PackagePath=""/>-->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
rem https://github.com/StefH/GitHubReleaseNotes
|
||||
|
||||
SET version=1.5.10
|
||||
SET version=1.5.11
|
||||
|
||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# 1.5.10 (06 November 2022)
|
||||
- #843 Webhook Templating: Use the transformed URL to create the HttpRequestMessage
|
||||
- #845 Add WireMockNullLogger as valid commandline logger option [feature]
|
||||
# 1.5.11 (24 November 2022)
|
||||
- #836 Add Settings.QueryParameterMultipleValueSupport [feature]
|
||||
- #848 Use try-catch when adding or removing logEntry [bug]
|
||||
- #846 Exception ArgumentOutOfRangeException [bug]
|
||||
|
||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||
@@ -43,14 +43,12 @@ jobs:
|
||||
command: 'build'
|
||||
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
|
||||
arguments: '--configuration Debug --framework net6.0'
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: 'Execute Unit tests'
|
||||
|
||||
- task: CmdLine@2
|
||||
inputs:
|
||||
command: 'test'
|
||||
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
|
||||
arguments: '--no-build --configuration Debug --framework net6.0 --collect:"XPlat Code Coverage" --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
|
||||
|
||||
script: 'dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --no-build --configuration Debug --framework net6.0'
|
||||
displayName: 'Execute Unit Tests with Coverage'
|
||||
|
||||
- task: SonarCloudAnalyze@1
|
||||
displayName: 'SonarCloud: Run Code Analysis'
|
||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||
@@ -76,7 +74,7 @@ jobs:
|
||||
- task: PublishBuildArtifacts@1
|
||||
displayName: Publish coverage file
|
||||
inputs:
|
||||
PathtoPublish: '/home/vsts/work/1/s/test/WireMock.Net.Tests/coverage.net6.0.opencover.xml'
|
||||
PathtoPublish: './test/WireMock.Net.Tests/coverage.net6.0.opencover.xml'
|
||||
|
||||
- job: Windows_Build_Test
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>WireMock.Net.Service</RootNamespace>
|
||||
<AssemblyName>WireMock.Net.Service</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net452" />
|
||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
||||
<package id="System.Net.Http" version="4.3.4" targetFramework="net452" />
|
||||
<package id="System.Net.Http" version="4.3.4" targetFramework="net452" requireReinstallation="true" />
|
||||
<package id="XPath2" version="1.1.3" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -104,7 +104,7 @@ public class RequestMessageBodyMatcher : IRequestMatcher
|
||||
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="func">The function.</param>
|
||||
public RequestMessageBodyMatcher(Func<IBodyData, bool> func)
|
||||
public RequestMessageBodyMatcher(Func<IBodyData?, bool> func)
|
||||
{
|
||||
BodyDataFunc = Guard.NotNull(func);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ public class RequestMessageParamMatcher : IRequestMatcher
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="ignoreCase">Defines if the key should be matched using case-ignore.</param>
|
||||
/// <param name="values">The values.</param>
|
||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, string[]? values) : this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, ignoreCase, false, MatchOperator.And, value)).Cast<IStringMatcher>().ToArray())
|
||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, params string[]? values) :
|
||||
this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, ignoreCase, false, MatchOperator.And, value)).Cast<IStringMatcher>().ToArray())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ public class RequestMessageParamMatcher : IRequestMatcher
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="ignoreCase">Defines if the key should be matched using case-ignore.</param>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, IStringMatcher[]? matchers)
|
||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, params IStringMatcher[]? matchers)
|
||||
{
|
||||
MatchBehaviour = matchBehaviour;
|
||||
Key = Guard.NotNull(key);
|
||||
@@ -95,7 +96,7 @@ public class RequestMessageParamMatcher : IRequestMatcher
|
||||
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
|
||||
}
|
||||
|
||||
var valuesPresentInRequestMessage = ((RequestMessage)requestMessage).GetParameter(Key!, IgnoreCase ?? false);
|
||||
var valuesPresentInRequestMessage = ((RequestMessage)requestMessage).GetParameter(Key, IgnoreCase ?? false);
|
||||
if (valuesPresentInRequestMessage == null)
|
||||
{
|
||||
// Key is not present at all, just return Mismatch
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace WireMock.Owin.Mappers
|
||||
body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return new RequestMessage(urlDetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
||||
return new RequestMessage(options, urlDetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
||||
}
|
||||
|
||||
private static (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
||||
|
||||
@@ -269,29 +269,55 @@ namespace WireMock.Owin
|
||||
{
|
||||
_options.Logger.DebugRequestResponse(_logEntryMapper.Map(entry), entry.RequestMessage.Path.StartsWith("/__admin/"));
|
||||
|
||||
if (addRequest)
|
||||
// If addRequest is set to true and MaxRequestLogCount is null or does have a value greater than 0, try to add a new request log.
|
||||
if (addRequest && _options.MaxRequestLogCount is null or > 0)
|
||||
{
|
||||
_options.LogEntries.Add(entry);
|
||||
TryAddLogEntry(entry);
|
||||
}
|
||||
|
||||
if (_options.MaxRequestLogCount != null)
|
||||
// In case MaxRequestLogCount has a value greater than 0, try to delete existing request logs based on the count.
|
||||
if (_options.MaxRequestLogCount is > 0)
|
||||
{
|
||||
var logEntries = _options.LogEntries.ToList();
|
||||
foreach (var logEntry in logEntries.OrderBy(le => le.RequestMessage.DateTime).Take(logEntries.Count - _options.MaxRequestLogCount.Value))
|
||||
{
|
||||
_options.LogEntries.Remove(logEntry);
|
||||
TryRemoveLogEntry(logEntry);
|
||||
}
|
||||
}
|
||||
|
||||
if (_options.RequestLogExpirationDuration != null)
|
||||
// In case RequestLogExpirationDuration has a value greater than 0, try to delete existing request logs based on the date.
|
||||
if (_options.RequestLogExpirationDuration is > 0)
|
||||
{
|
||||
var checkTime = DateTime.UtcNow.AddHours(-_options.RequestLogExpirationDuration.Value);
|
||||
|
||||
foreach (var logEntry in _options.LogEntries.ToList().Where(le => le.RequestMessage.DateTime < checkTime))
|
||||
{
|
||||
_options.LogEntries.Remove(logEntry);
|
||||
TryRemoveLogEntry(logEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TryAddLogEntry(LogEntry logEntry)
|
||||
{
|
||||
try
|
||||
{
|
||||
_options.LogEntries.Add(logEntry);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore exception (can happen during stress testing)
|
||||
}
|
||||
}
|
||||
|
||||
private void TryRemoveLogEntry(LogEntry logEntry)
|
||||
{
|
||||
try
|
||||
{
|
||||
_options.LogEntries.Remove(logEntry);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore exception (can happen during stress testing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers
|
||||
@@ -172,5 +175,25 @@ namespace WireMock.Net.Tests.RequestMatchers
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
// Issue #849
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
|
||||
{
|
||||
// Assign
|
||||
var options = new WireMockMiddlewareOptions
|
||||
{
|
||||
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
||||
};
|
||||
var requestMessage = new RequestMessage(options, new UrlDetails("http://localhost?query=SELECT id, value FROM table WHERE id = 1&test=42"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "query", false, "SELECT id, value FROM table WHERE id = 1");
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
score.Should().Be(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
@@ -19,11 +19,11 @@ namespace WireMock.Net.Tests
|
||||
// Assign
|
||||
var spec = Request.Create().WithPath("/path/a b").UsingAnyMethod();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var body = new BodyData();
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/path/a b"), "GET", ClientIp, body);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -31,17 +31,17 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Request_WithPath_WithHeader_Match()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingAnyMethod().WithHeader("X-toto", "tata");
|
||||
|
||||
// Act
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -49,13 +49,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Request_WithPath()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo");
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -76,13 +76,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Request_WithPathFunc()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath(url => url.EndsWith("/foo"));
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -90,13 +90,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Request_WithPathRegexMatcher_HasMatch()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath(new RegexMatcher("^/foo"));
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo/bar"), "blabla", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -104,13 +104,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Request_WithPathRegexMatcher_HasNoMatch()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo");
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "blabla", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
@@ -126,10 +126,10 @@ namespace WireMock.Net.Tests
|
||||
};
|
||||
var spec = Request.Create().WithPath(new RegexMatcher(pattern));
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo/bar"), "blabla", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -137,17 +137,17 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_delete()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingDelete();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever"
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "Delete", ClientIp, body);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -155,13 +155,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_get()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingGet();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -169,13 +169,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_head()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingHead();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "HEAD", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -183,13 +183,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_post()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingPost();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -197,13 +197,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_put()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingPut();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -211,13 +211,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_patch()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingPatch();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PATCH", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
@@ -225,13 +225,13 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void Should_exclude_requests_matching_given_path_but_not_http_method()
|
||||
{
|
||||
// Arrange
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingPut();
|
||||
|
||||
// Act
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "HEAD", ClientIp);
|
||||
|
||||
// Assert
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestWithUrlTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Request_WithUrl_Regex()
|
||||
{
|
||||
// Assign
|
||||
var spec = Request.Create().WithUrl(new RegexMatcher("(some\\/service\\/v1\\/name)([?]{1})(param.source=SYSTEM){1}([&]{1})(param.id=123457890){1}$")).UsingAnyMethod();
|
||||
|
||||
// Act
|
||||
var body = new BodyData();
|
||||
var request = new RequestMessage(new UrlDetails("https://localhost/some/service/v1/name?param.source=SYSTEM¶m.id=123457890"), "POST", ClientIp, body);
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class QueryStringParserTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingSpacesAndEqualSign()
|
||||
public void Parse_With1ParamContainingSpacesSingleQuoteAndEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?q=SELECT Id from User where username='user@gmail.com'";
|
||||
@@ -287,6 +287,22 @@ public class QueryStringParserTests
|
||||
result["q"].Should().Equal(new WireMockList<string>("SELECT Id from User where username='user@gmail.com'"));
|
||||
}
|
||||
|
||||
// Issue #849
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
|
||||
{
|
||||
// Assign
|
||||
string query = "?query=SELECT id, value FROM table WHERE id = 1&test=42";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query, QueryParameterMultipleValueSupport.NoComma);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(2);
|
||||
result["query"].Should().Equal(new WireMockList<string>("SELECT id, value FROM table WHERE id = 1"));
|
||||
result["test"].Should().Equal(new WireMockList<string>("42"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithComplex()
|
||||
{
|
||||
|
||||
@@ -31,17 +31,17 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Codecov" Version="1.13.0" />
|
||||
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
|
||||
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using NFluent;
|
||||
@@ -374,6 +375,26 @@ public class WireMockServerAdminTests
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_Admin_Logging_SetMaxRequestLogCount_To_0_Should_Not_AddLogging()
|
||||
{
|
||||
// Assign
|
||||
var client = new HttpClient();
|
||||
|
||||
// Act
|
||||
var server = WireMockServer.Start();
|
||||
server.SetMaxRequestLogCount(0);
|
||||
|
||||
await client.GetAsync("http://localhost:" + server.Port + "/foo1").ConfigureAwait(false);
|
||||
await client.GetAsync("http://localhost:" + server.Port + "/foo2").ConfigureAwait(false);
|
||||
await client.GetAsync("http://localhost:" + server.Port + "/foo3").ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
server.LogEntries.Should().BeEmpty();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_Admin_WatchStaticMappings()
|
||||
{
|
||||
|
||||
46
test/WireMock.Net.Tests/WireMockServerTests.WithParam.cs
Normal file
46
test/WireMock.Net.Tests/WireMockServerTests.WithParam.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
public partial class WireMockServerTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("SELECT id, value FROM table WHERE id = 1")]
|
||||
[InlineData("select id, name, value from table where id in (1, 2, 3, 4, 5)")]
|
||||
public async Task WireMockServer_WithParam_QueryParameterMultipleValueSupport_NoComma_Should_Ignore_Comma(string queryValue)
|
||||
{
|
||||
// Arrange
|
||||
var settings = new WireMockServerSettings
|
||||
{
|
||||
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
||||
};
|
||||
var server = WireMockServer.Start(settings);
|
||||
server.Given(
|
||||
Request.Create()
|
||||
.UsingGet()
|
||||
.WithPath("/foo")
|
||||
.WithParam("query", queryValue)
|
||||
)
|
||||
.RespondWith(
|
||||
Response.Create().WithStatusCode(200)
|
||||
);
|
||||
|
||||
// Act
|
||||
var requestUri = new Uri($"http://localhost:{server.Port}/foo?query={queryValue}");
|
||||
var response = await server.CreateClient().GetAsync(requestUri).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user