mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-28 20:32:13 +01:00
Version 2.x (#1359)
* Version 2.x * Setup .NET 9 * 12 * cleanup some #if for NETSTANDARD1_3 * cleanup + fix tests for net8 * openapi * NO ConfigureAwait(false) + cleanup * . * #endif * HashSet * WireMock.Net.NUnit * HttpContext * Add WebSockets (#1423) * Add WebSockets * Add tests * fix * more tests * Add tests * ... * remove IOwin * - * tests * fluent * ok * match * . * byte[] * x * func * func * byte * trans * ... * frameworks......... * jmes * xxx * sc * using var httpClient = new HttpClient(); * usings * maxRetries * up * xunit v3 * ct * --- * ct * ct2 * T Unit * WireMock.Net.TUnitTests / 10 * t unit first * --project * no tunit * t2 * --project * --project * ci - --project * publish ./test/wiremock-coverage.xml * windows * . * log * ... * log * goed * BodyType * . * . * --scenario * ... * pact * ct * . * WireMock.Net.RestClient.AwesomeAssertions (#1427) * WireMock.Net.RestClient.AwesomeAssertions * ok * atpath * fix test * sonar fixes * ports * proxy test * FIX? * --- * await Task.Delay(100, _ct); * ? * --project * Aspire: use IDistributedApplicationEventingSubscriber (#1428) * broadcast * ok * more tsts * . * Collection * up * . * 2 * remove nfluent * <VersionPrefix>2.0.0-preview-02</VersionPrefix> * ... * . * nuget icon * . * <PackageReference Include="JmesPath.Net" Version="1.1.0" /> * x * 500 * . * fix some warnings * ws
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' != 'net45' and '$(TargetFramework)' != 'net452' and '$(TargetFramework)' != 'net461' ">
|
||||
<ItemGroup Condition=" '$(TargetFramework)' != 'net48' ">
|
||||
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.1.0" />
|
||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="13.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace WireMock.Net.Aspire.Tests.Facts;
|
||||
|
||||
public sealed class DockerIsRunningInLinuxContainerModeFactAttribute : FactAttribute
|
||||
{
|
||||
private const string SkipReason = "Docker is not running in Linux container mode. Skipping test.";
|
||||
|
||||
public DockerIsRunningInLinuxContainerModeFactAttribute()
|
||||
public DockerIsRunningInLinuxContainerModeFactAttribute(
|
||||
[CallerFilePath] string? sourceFilePath = null,
|
||||
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||
{
|
||||
if (!DockerUtils.IsDockerRunningLinuxContainerMode.Value)
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Net.Http.Json;
|
||||
using FluentAssertions;
|
||||
using AwesomeAssertions;
|
||||
using Projects;
|
||||
using WireMock.Net.Aspire.Tests.Facts;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace WireMock.Net.Aspire.Tests;
|
||||
|
||||
public class IntegrationTests(ITestOutputHelper output)
|
||||
public class IntegrationTests
|
||||
{
|
||||
private record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary);
|
||||
|
||||
@@ -27,11 +26,11 @@ public class IntegrationTests(ITestOutputHelper output)
|
||||
var weatherForecasts1 = await httpClient.GetFromJsonAsync<WeatherForecast[]>("/weatherforecast");
|
||||
|
||||
// Assert 1
|
||||
weatherForecasts1.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
weatherForecasts1.Should().BeEquivalentTo(
|
||||
[
|
||||
new WeatherForecast(new DateOnly(2024, 5, 24), -10, "Freezing"),
|
||||
new WeatherForecast(new DateOnly(2024, 5, 25), +33, "Hot")
|
||||
});
|
||||
]);
|
||||
|
||||
// Act 2
|
||||
var weatherForecasts2 = await httpClient.GetFromJsonAsync<WeatherForecast[]>("/weatherforecast2");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
@@ -13,21 +14,21 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Hosting.Testing" Version="13.1.0" />
|
||||
<PackageReference Include="Aspire.Hosting.Testing" Version="13.1.1" />
|
||||
<PackageReference Include="Codecov" Version="1.13.0" />
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.70" />
|
||||
<PackageReference Include="xunit" Version="2.8.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using AwesomeAssertions;
|
||||
|
||||
namespace WireMock.Net.Aspire.Tests;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Net.Sockets;
|
||||
using FluentAssertions;
|
||||
using AwesomeAssertions;
|
||||
using Moq;
|
||||
using WireMock.Util;
|
||||
|
||||
|
||||
16963
test/WireMock.Net.Aspire.Tests/coverage.opencover.xml
Normal file
16963
test/WireMock.Net.Aspire.Tests/coverage.opencover.xml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using AwesomeAssertions;
|
||||
using WireMock.Net.Extensions.Routing.Extensions;
|
||||
using WireMock.Server;
|
||||
@@ -28,7 +26,7 @@ public sealed class WireMockRouterTests
|
||||
_sut.Map(HttpMethod.Get.ToString(), DefaultUrlPattern, _ => handlerResult);
|
||||
using var client = _server.CreateClient();
|
||||
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern);
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern, TestContext.Current.CancellationToken);
|
||||
|
||||
result.Should().Be(handlerResult);
|
||||
}
|
||||
@@ -40,7 +38,7 @@ public sealed class WireMockRouterTests
|
||||
_sut.Map(HttpMethod.Get.ToString(), DefaultUrlPattern, _ => Task.FromResult(handlerResult));
|
||||
using var client = _server.CreateClient();
|
||||
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern);
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern, TestContext.Current.CancellationToken);
|
||||
|
||||
result.Should().Be(handlerResult);
|
||||
}
|
||||
@@ -55,7 +53,7 @@ public sealed class WireMockRouterTests
|
||||
async _ => await Task.FromResult(handlerResult));
|
||||
using var client = _server.CreateClient();
|
||||
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern);
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern, TestContext.Current.CancellationToken);
|
||||
|
||||
result.Should().Be(handlerResult);
|
||||
}
|
||||
@@ -74,7 +72,7 @@ public sealed class WireMockRouterTests
|
||||
_sut.Map(HttpMethod.Get.ToString(), DefaultUrlPattern, _ => HandleRequestAsync());
|
||||
using var client = _server.CreateClient();
|
||||
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern);
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern, TestContext.Current.CancellationToken);
|
||||
|
||||
result.Should().Be(handlerResult);
|
||||
}
|
||||
@@ -93,8 +91,8 @@ public sealed class WireMockRouterTests
|
||||
_sut.MapGet(DefaultUrlPattern, _ => HandleRequestAsync());
|
||||
using var client = _server.CreateClient();
|
||||
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern);
|
||||
var result = await client.GetFromJsonAsync<int>(DefaultUrlPattern, TestContext.Current.CancellationToken);
|
||||
|
||||
result.Should().Be(handlerResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Authors>Gennadii Saltyshchak</Authors>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<DebugType>full</DebugType>
|
||||
@@ -14,24 +15,24 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.1.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
|
||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.Extensions.Routing\WireMock.Net.Extensions.Routing.csproj" />
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.Extensions.Routing\WireMock.Net.Extensions.Routing.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using AwesomeAssertions;
|
||||
using WireMock.Net.TestWebApplication;
|
||||
|
||||
namespace WireMock.Net.Middleware.Tests;
|
||||
@@ -18,11 +18,11 @@ public class IntegrationTests
|
||||
using var client = factory.CreateClient();
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync(requestUri);
|
||||
var response = await client.GetAsync(requestUri, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var stringResponse = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
|
||||
stringResponse.Should().Be(expectedResponse);
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ public class IntegrationTests
|
||||
request.Headers.Add("X-WireMock-Response-Delay", "10");
|
||||
|
||||
// Act
|
||||
var response = await client.SendAsync(request);
|
||||
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var stringResponse = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
|
||||
stringResponse.Should().Be(expectedResponse);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
@@ -13,20 +14,20 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Codecov" Version="1.13.0" />
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.70" />
|
||||
<PackageReference Include="xunit" Version="2.8.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
51302
test/WireMock.Net.Middleware.Tests/coverage.opencover.xml
Normal file
51302
test/WireMock.Net.Middleware.Tests/coverage.opencover.xml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
@@ -9,7 +10,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TUnit" Version="0.2.195" />
|
||||
<PackageReference Include="TUnit" Version="1.17.29" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,27 +2,23 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.0.0" />
|
||||
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="WireMock.Net" Version="1.23.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
|
||||
<PackageReference Include="WireMock.Net" Version="1.25.0" />
|
||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
@@ -33,6 +29,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="JetBrains.Annotations" Version="2025.2.4" />
|
||||
<PackageReference Update="SonarAnalyzer.CSharp" Version="10.11.0.117924" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ using WireMock.Server;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
public partial class WireMockServerTests
|
||||
public class WireMockServerTests
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithMultiPartBody_Using_MimePartMatchers()
|
||||
{
|
||||
@@ -85,19 +87,19 @@ public partial class WireMockServerTests
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act 1
|
||||
var response1 = await client.PostAsync("/multipart", formDataContent);
|
||||
var response1 = await client.PostAsync("/multipart", formDataContent, _ct);
|
||||
|
||||
// Assert 1
|
||||
response1.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var content1 = await response1.Content.ReadAsStringAsync();
|
||||
var content1 = await response1.Content.ReadAsStringAsync(_ct);
|
||||
content1.Should().Be("POST;This is some plain text");
|
||||
|
||||
// Act 2
|
||||
var response2 = await client.PostAsync("/multipart2", formDataContent);
|
||||
var response2 = await client.PostAsync("/multipart2", formDataContent, _ct);
|
||||
|
||||
// Assert 1
|
||||
response2.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var content2 = await response2.Content.ReadAsStringAsync();
|
||||
var content2 = await response2.Content.ReadAsStringAsync(_ct);
|
||||
content2.Should().Be("OK");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using RestEase;
|
||||
using VerifyXunit;
|
||||
using WireMock.Client;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.AdminApi;
|
||||
|
||||
@@ -41,9 +38,9 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
var getMappingsResult = await api.GetMappingsAsync().ConfigureAwait(false);
|
||||
var getMappingsResult = await api.GetMappingsAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
await Verifier.Verify(getMappingsResult, VerifySettings);
|
||||
await Verify(getMappingsResult, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -54,9 +51,9 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var client = server.CreateClient();
|
||||
var getMappingsResult = await client.GetStringAsync("/__admin/mappings").ConfigureAwait(false);
|
||||
var getMappingsResult = await client.GetStringAsync("/__admin/mappings", TestContext.Current.CancellationToken);
|
||||
|
||||
await Verifier.VerifyJson(getMappingsResult, VerifySettings);
|
||||
await VerifyJson(getMappingsResult, VerifySettings);
|
||||
}
|
||||
|
||||
public WireMockServer Given_WithBodyAsProtoBuf_AddedToServer()
|
||||
@@ -149,5 +146,4 @@ message HelloReply {
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -59,7 +59,7 @@ server
|
||||
)
|
||||
.WithGuid("c9929240-7ae8-4a5d-8ed8-0913479f6eeb")
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(208)
|
||||
.WithStatusCode(306)
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
@as = 1,
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
|
||||
using RestEase;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Client;
|
||||
using WireMock.Constants;
|
||||
using WireMock.Models;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.AdminApi;
|
||||
|
||||
@@ -35,17 +31,18 @@ public partial class WireMockAdminApiTests
|
||||
public async Task HttpClient_PostMappingsAsync_ForProtoBufMapping(string mappingFile, string guid)
|
||||
{
|
||||
// Arrange
|
||||
var cancelationToken = TestContext.Current.CancellationToken;
|
||||
var mappingsJson = ReadMappingFile(mappingFile);
|
||||
|
||||
using var server = WireMockServer.StartWithAdminInterface();
|
||||
var httpClient = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, WireMockConstants.ContentTypeJson));
|
||||
var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, WireMockConstants.ContentTypeJson), cancelationToken);
|
||||
result.EnsureSuccessStatusCode();
|
||||
|
||||
// Assert
|
||||
var mapping = await httpClient.GetStringAsync($"/__admin/mappings/{guid}");
|
||||
var mapping = await httpClient.GetStringAsync($"/__admin/mappings/{guid}", cancelationToken);
|
||||
mapping = RemoveLineContainingUpdatedAt(mapping);
|
||||
mapping.Should().Be(mappingsJson);
|
||||
}
|
||||
@@ -72,15 +69,15 @@ public partial class WireMockAdminApiTests
|
||||
Title = "test 2",
|
||||
Description = "description 2"
|
||||
};
|
||||
var result = await api.PostMappingsAsync(new[] { model1, model2 }).ConfigureAwait(false);
|
||||
var result = await api.PostMappingsAsync([model1, model2], TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNotNull();
|
||||
Check.That(result.Status).IsNotNull();
|
||||
Check.That(result.Guid).IsNull();
|
||||
Check.That(server.Mappings.Where(m => !m.IsAdminInterface)).HasSize(2);
|
||||
Check.That(server.Mappings.Single(x => x.Title == "test 1").Description).IsEqualTo("description 1");
|
||||
Check.That(server.Mappings.Single(x => x.Title == "test 2").Description).IsEqualTo("description 2");
|
||||
result.Should().NotBeNull();
|
||||
result.Status.Should().NotBeNull();
|
||||
result.Guid.Should().BeNull();
|
||||
server.Mappings.Where(m => !m.IsAdminInterface).Should().HaveCount(2);
|
||||
server.Mappings.Single(x => x.Title == "test 1").Description.Should().Be("description 1");
|
||||
server.Mappings.Single(x => x.Title == "test 2").Description.Should().Be("description 2");
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -91,7 +88,7 @@ public partial class WireMockAdminApiTests
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(200, 200)]
|
||||
[InlineData("200", "200")]
|
||||
public async Task IWireMockAdminApi_PostMappingAsync_WithStatusCode(object statusCode, object expectedStatusCode)
|
||||
public async Task IWireMockAdminApi_PostMappingAsync_WithStatusCode(object? statusCode, object? expectedStatusCode)
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
@@ -105,19 +102,19 @@ public partial class WireMockAdminApiTests
|
||||
Priority = 500,
|
||||
Title = "test"
|
||||
};
|
||||
var result = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
var result = await api.PostMappingAsync(model, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNotNull();
|
||||
Check.That(result.Status).IsNotNull();
|
||||
Check.That(result.Guid).IsNotNull();
|
||||
result.Should().NotBeNull();
|
||||
result.Status.Should().NotBeNull();
|
||||
result.Guid.Should().NotBeNull();
|
||||
|
||||
var mapping = server.Mappings.Single(m => m.Priority == 500);
|
||||
Check.That(mapping).IsNotNull();
|
||||
Check.That(mapping.Title).Equals("test");
|
||||
mapping.Should().NotBeNull();
|
||||
mapping.Title.Should().Be("test");
|
||||
|
||||
var response = await mapping.ProvideResponseAsync(new RequestMessage(new UrlDetails("http://localhost/1"), "GET", "")).ConfigureAwait(false);
|
||||
Check.That(response.Message.StatusCode).Equals(expectedStatusCode);
|
||||
var response = await mapping.ProvideResponseAsync(Mock.Of<HttpContext>(), new RequestMessage(new UrlDetails("http://localhost/1"), "GET", ""));
|
||||
response.Message.StatusCode.Should().Be(expectedStatusCode);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -172,5 +169,4 @@ public partial class WireMockAdminApiTests
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,21 +1,11 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using RestEase;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Scenarios;
|
||||
using WireMock.Admin.Settings;
|
||||
@@ -31,11 +21,9 @@ using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.AdminApi;
|
||||
|
||||
[UsesVerify]
|
||||
public partial class WireMockAdminApiTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
@@ -57,6 +45,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_OK()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var adminUsername = $"username_{Guid.NewGuid()}";
|
||||
var adminPassword = $"password_{Guid.NewGuid()}";
|
||||
var server = WireMockServer.Start(w =>
|
||||
@@ -69,10 +58,10 @@ public partial class WireMockAdminApiTests
|
||||
.WithAuthorization(adminUsername, adminPassword);
|
||||
|
||||
// Act 1
|
||||
await api.WaitForHealthAsync().ConfigureAwait(false);
|
||||
await api.WaitForHealthAsync(cancellationToken: cancellationToken);
|
||||
|
||||
// Act 2
|
||||
var status = await api.GetHealthAsync().ConfigureAwait(false);
|
||||
var status = await api.GetHealthAsync(cancellationToken);
|
||||
status.Should().Be("Healthy");
|
||||
}
|
||||
|
||||
@@ -90,7 +79,7 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
Func<Task> act = () => api.WaitForHealthAsync(maxRetries: 3);
|
||||
Func<Task> act = () => api.WaitForHealthAsync(maxRetries: 3, cancellationToken: TestContext.Current.CancellationToken);
|
||||
await act.Should().ThrowAsync<InvalidOperationException>();
|
||||
}
|
||||
|
||||
@@ -102,8 +91,8 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var settings = await api.GetSettingsAsync().ConfigureAwait(false);
|
||||
Check.That(settings).IsNotNull();
|
||||
var settings = await api.GetSettingsAsync(TestContext.Current.CancellationToken);
|
||||
settings.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -118,10 +107,10 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0] + "/foo");
|
||||
|
||||
// Act
|
||||
var settings = await api.GetSettingsAsync().ConfigureAwait(false);
|
||||
var settings = await api.GetSettingsAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(settings).IsNotNull();
|
||||
settings.Should().NotBeNull();
|
||||
|
||||
// Cleanup
|
||||
server.Stop();
|
||||
@@ -137,8 +126,8 @@ public partial class WireMockAdminApiTests
|
||||
|
||||
// Act
|
||||
var settings = new SettingsModel();
|
||||
var status = await api.PostSettingsAsync(settings).ConfigureAwait(false);
|
||||
Check.That(status.Status).Equals("Settings updated");
|
||||
var status = await api.PostSettingsAsync(settings, TestContext.Current.CancellationToken);
|
||||
status.Status.Should().Be("Settings updated");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -150,8 +139,8 @@ public partial class WireMockAdminApiTests
|
||||
|
||||
// Act
|
||||
var settings = new SettingsModel();
|
||||
var status = await api.PutSettingsAsync(settings).ConfigureAwait(false);
|
||||
Check.That(status.Status).Equals("Settings updated");
|
||||
var status = await api.PutSettingsAsync(settings, TestContext.Current.CancellationToken);
|
||||
status.Status.Should().Be("Settings updated");
|
||||
}
|
||||
|
||||
// https://github.com/wiremock/WireMock.Net/issues/325
|
||||
@@ -170,16 +159,16 @@ public partial class WireMockAdminApiTests
|
||||
Priority = 500,
|
||||
Title = "test"
|
||||
};
|
||||
var result = await api.PutMappingAsync(new Guid("a0000000-0000-0000-0000-000000000000"), model).ConfigureAwait(false);
|
||||
var result = await api.PutMappingAsync(new Guid("a0000000-0000-0000-0000-000000000000"), model, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsNotNull();
|
||||
Check.That(result.Status).Equals("Mapping added or updated");
|
||||
Check.That(result.Guid).IsNotNull();
|
||||
result.Should().NotBeNull();
|
||||
result.Status.Should().Be("Mapping added or updated");
|
||||
result.Guid.Should().NotBeNull();
|
||||
|
||||
var mapping = server.Mappings.Single(m => m.Priority == 500);
|
||||
Check.That(mapping).IsNotNull();
|
||||
Check.That(mapping.Title).Equals("test");
|
||||
mapping.Should().NotBeNull();
|
||||
mapping.Title.Should().Be("test");
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -190,6 +179,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_FindRequestsAsync()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
@@ -200,16 +190,17 @@ public partial class WireMockAdminApiTests
|
||||
.RespondWith(Response.Create());
|
||||
|
||||
var serverUrl = "http://localhost:" + server.Ports[0];
|
||||
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(serverUrl + "/foo", cancellationToken);
|
||||
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
|
||||
|
||||
// Act
|
||||
var requests = await api.FindRequestsAsync(new RequestModel { Methods = new[] { "GET" } }).ConfigureAwait(false);
|
||||
var requests = await api.FindRequestsAsync(new RequestModel { Methods = new[] { "GET" } }, cancellationToken);
|
||||
|
||||
// Assert
|
||||
requests.Should().HaveCount(1);
|
||||
var requestLogged = requests.First();
|
||||
requestLogged.Request.Method.Should().Be("GET");
|
||||
requestLogged.Request!.Method.Should().Be("GET");
|
||||
requestLogged.Request.Body.Should().BeNull();
|
||||
requestLogged.Request.Path.Should().Be("/foo");
|
||||
}
|
||||
@@ -218,6 +209,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_FindRequestsByMappingGuidAsync_Found()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var mappingGuid = Guid.NewGuid();
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
@@ -231,25 +223,25 @@ public partial class WireMockAdminApiTests
|
||||
|
||||
var serverUrl = "http://localhost:" + server.Ports[0];
|
||||
using var client = new HttpClient();
|
||||
await client.GetAsync(serverUrl + "/foo").ConfigureAwait(false);
|
||||
await client.GetAsync(serverUrl + "/foo?bar=baz").ConfigureAwait(false);
|
||||
await client.GetAsync(serverUrl + "/foo", cancellationToken);
|
||||
await client.GetAsync(serverUrl + "/foo?bar=baz", cancellationToken);
|
||||
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
|
||||
|
||||
// Act
|
||||
var logEntryModels = await api.FindRequestsByMappingGuidAsync(mappingGuid).ConfigureAwait(false);
|
||||
var logEntryModels = await api.FindRequestsByMappingGuidAsync(mappingGuid, cancellationToken);
|
||||
|
||||
// Assert
|
||||
logEntryModels.Should().HaveCount(2);
|
||||
logEntryModels[0].Should().NotBeNull();
|
||||
logEntryModels[0]!.Request.Method.Should().Be("GET");
|
||||
logEntryModels[0]!.Request.Body.Should().BeNull();
|
||||
logEntryModels[0]!.Request.Path.Should().Be("/foo");
|
||||
logEntryModels[0]!.Request.Query.Should().BeNullOrEmpty();
|
||||
logEntryModels[0].Request!.Method.Should().Be("GET");
|
||||
logEntryModels[0].Request!.Body.Should().BeNull();
|
||||
logEntryModels[0].Request!.Path.Should().Be("/foo");
|
||||
logEntryModels[0].Request!.Query.Should().BeNullOrEmpty();
|
||||
logEntryModels[1].Should().NotBeNull();
|
||||
logEntryModels[1]!.Request.Method.Should().Be("GET");
|
||||
logEntryModels[1]!.Request.Body.Should().BeNull();
|
||||
logEntryModels[1]!.Request.Path.Should().Be("/foo");
|
||||
logEntryModels[1]!.Request.Query.Should().BeEquivalentTo(new Dictionary<string, WireMockList<string>>
|
||||
logEntryModels[1].Request!.Method.Should().Be("GET");
|
||||
logEntryModels[1].Request!.Body.Should().BeNull();
|
||||
logEntryModels[1].Request!.Path.Should().Be("/foo");
|
||||
logEntryModels[1].Request!.Query.Should().BeEquivalentTo(new Dictionary<string, WireMockList<string>>
|
||||
{
|
||||
{"bar", new WireMockList<string>("baz")}
|
||||
});
|
||||
@@ -259,6 +251,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_FindRequestsByMappingGuidAsync_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
@@ -270,11 +263,12 @@ public partial class WireMockAdminApiTests
|
||||
.RespondWith(Response.Create());
|
||||
|
||||
var serverUrl = "http://localhost:" + server.Ports[0];
|
||||
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(serverUrl + "/foo", cancellationToken);
|
||||
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
|
||||
|
||||
// Act
|
||||
var logEntryModels = await api.FindRequestsByMappingGuidAsync(Guid.NewGuid()).ConfigureAwait(false);
|
||||
var logEntryModels = await api.FindRequestsByMappingGuidAsync(Guid.NewGuid(), cancellationToken);
|
||||
|
||||
// Assert
|
||||
logEntryModels.Should().BeEmpty();
|
||||
@@ -291,7 +285,7 @@ public partial class WireMockAdminApiTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await server.CreateClient().GetAsync("/__admin/requests/find?mappingGuid=x");
|
||||
var result = await server.CreateClient().GetAsync("/__admin/requests/find?mappingGuid=x", TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
result.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||
@@ -301,30 +295,33 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetRequestsAsync()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
Logger = new WireMockNullLogger()
|
||||
});
|
||||
var serverUrl = "http://localhost:" + server.Ports[0];
|
||||
await new HttpClient().GetAsync(serverUrl + "/foo").ConfigureAwait(false);
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(serverUrl + "/foo", cancellationToken);
|
||||
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
|
||||
|
||||
// Act
|
||||
var requests = await api.GetRequestsAsync().ConfigureAwait(false);
|
||||
var requests = await api.GetRequestsAsync(cancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(requests).HasSize(1);
|
||||
requests.Should().HaveCount(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("GET");
|
||||
Check.That(requestLogged.Request.Body).IsNull();
|
||||
Check.That(requestLogged.Request.Path).IsEqualTo("/foo");
|
||||
requestLogged.Request.Method.Should().Be("GET");
|
||||
requestLogged.Request.Body.Should().BeNull();
|
||||
requestLogged.Request.Path.Should().Be("/foo");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetRequestsAsync_JsonApi()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
@@ -341,26 +338,28 @@ public partial class WireMockAdminApiTests
|
||||
request.Content = new StringContent(data);
|
||||
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(jsonApiContentType);
|
||||
|
||||
var response = await new HttpClient().SendAsync(request);
|
||||
Check.That(response).IsNotNull();
|
||||
using var client = new HttpClient();
|
||||
var response = await client.SendAsync(request, cancellationToken);
|
||||
response.Should().NotBeNull();
|
||||
|
||||
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
|
||||
|
||||
// Act
|
||||
var requests = await api.GetRequestsAsync().ConfigureAwait(false);
|
||||
var requests = await api.GetRequestsAsync(cancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(requests).HasSize(1);
|
||||
requests.Should().HaveCount(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("POST");
|
||||
Check.That(requestLogged.Request.Body).IsNotNull();
|
||||
Check.That(requestLogged.Request.Body).Contains("T000001");
|
||||
requestLogged.Request.Method.Should().Be("POST");
|
||||
requestLogged.Request.Body.Should().NotBeNull();
|
||||
requestLogged.Request.Body.Should().Contain("T000001");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetMappingAsync_WithBodyModelMatcherModel_WithoutMethods_ShouldReturnCorrectMappingModel()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
@@ -384,7 +383,7 @@ public partial class WireMockAdminApiTests
|
||||
},
|
||||
Response = new ResponseModel { Body = "world" }
|
||||
};
|
||||
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
var postMappingResult = await api.PostMappingAsync(model, cancellationToken);
|
||||
|
||||
// Assert
|
||||
postMappingResult.Should().NotBeNull();
|
||||
@@ -392,9 +391,9 @@ public partial class WireMockAdminApiTests
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
var getMappingResult = await api.GetMappingAsync(guid, cancellationToken);
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
await Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -403,6 +402,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetMappingAsync_WithProxy_And_ProxyUrlReplaceSettings()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
@@ -435,7 +435,7 @@ public partial class WireMockAdminApiTests
|
||||
}
|
||||
}
|
||||
};
|
||||
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
var postMappingResult = await api.PostMappingAsync(model, cancellationToken);
|
||||
|
||||
// Assert
|
||||
postMappingResult.Should().NotBeNull();
|
||||
@@ -443,9 +443,9 @@ public partial class WireMockAdminApiTests
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
var getMappingResult = await api.GetMappingAsync(guid, cancellationToken);
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
await Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -454,6 +454,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetMappingAsync_WithProxy_And_ProxyUrlReplaceSettings_And_TransformTemplate()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f06");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
@@ -484,7 +485,7 @@ public partial class WireMockAdminApiTests
|
||||
}
|
||||
}
|
||||
};
|
||||
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
var postMappingResult = await api.PostMappingAsync(model, cancellationToken);
|
||||
|
||||
// Assert
|
||||
postMappingResult.Should().NotBeNull();
|
||||
@@ -492,9 +493,9 @@ public partial class WireMockAdminApiTests
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
var getMappingResult = await api.GetMappingAsync(guid, cancellationToken);
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
await Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -503,6 +504,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetRequestsAsync_Json()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
@@ -518,20 +520,21 @@ public partial class WireMockAdminApiTests
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(jsonAcceptHeader));
|
||||
request.Content = new StringContent(data);
|
||||
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(jsonApiContentType);
|
||||
var response = await new HttpClient().SendAsync(request);
|
||||
Check.That(response).IsNotNull();
|
||||
using var client = new HttpClient();
|
||||
var response = await client.SendAsync(request, cancellationToken);
|
||||
response.Should().NotBeNull();
|
||||
|
||||
var api = RestClient.For<IWireMockAdminApi>(serverUrl);
|
||||
|
||||
// Act
|
||||
var requests = await api.GetRequestsAsync().ConfigureAwait(false);
|
||||
var requests = await api.GetRequestsAsync(cancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(requests).HasSize(1);
|
||||
requests.Should().HaveCount(1);
|
||||
var requestLogged = requests.First();
|
||||
Check.That(requestLogged.Request.Method).IsEqualTo("POST");
|
||||
Check.That(requestLogged.Request.Body).IsNotNull();
|
||||
Check.That(requestLogged.Request.Body).Contains("T000001");
|
||||
requestLogged.Request.Method.Should().Be("POST");
|
||||
requestLogged.Request.Body.Should().NotBeNull();
|
||||
requestLogged.Request.Body.Should().Contain("T000001");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -553,11 +556,11 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var request = await api.PostFileAsync("filename.txt", "abc").ConfigureAwait(false);
|
||||
var request = await api.PostFileAsync("filename.txt", "abc", TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(request.Guid).IsNull();
|
||||
Check.That(request.Status).Contains("File");
|
||||
request.Guid.Should().BeNull();
|
||||
request.Status.Should().Contain("File");
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.GetMappingFolder(), Times.Once);
|
||||
@@ -586,11 +589,11 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var request = await api.PutFileAsync("filename.txt", "abc-abc").ConfigureAwait(false);
|
||||
var request = await api.PutFileAsync("filename.txt", "abc-abc", TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(request.Guid).IsNull();
|
||||
Check.That(request.Status).Contains("File");
|
||||
request.Guid.Should().BeNull();
|
||||
request.Status.Should().Contain("File");
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.WriteFile(It.Is<string>(p => p == "filename.txt"), It.IsAny<byte[]>()), Times.Once);
|
||||
@@ -601,7 +604,7 @@ public partial class WireMockAdminApiTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IWireMockAdminApi_PutFileAsync_NotFound()
|
||||
public async Task IWireMockAdminApi_PutFileAsync_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var filesystemHandlerMock = new Mock<IFileSystemHandler>(MockBehavior.Strict);
|
||||
@@ -617,7 +620,8 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act and Assert
|
||||
Check.ThatAsyncCode(() => api.PutFileAsync("filename.txt", "xxx")).Throws<ApiException>();
|
||||
Func<Task> act = () => api.PutFileAsync("filename.txt", "xxx", TestContext.Current.CancellationToken);
|
||||
await act.Should().ThrowAsync<ApiException>();
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
|
||||
@@ -627,7 +631,7 @@ public partial class WireMockAdminApiTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IWireMockAdminApi_GetFileAsync_NotFound()
|
||||
public async Task IWireMockAdminApi_GetFileAsync_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var filesystemHandlerMock = new Mock<IFileSystemHandler>(MockBehavior.Strict);
|
||||
@@ -644,7 +648,8 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act and Assert
|
||||
Check.ThatAsyncCode(() => api.GetFileAsync("filename.txt")).Throws<ApiException>();
|
||||
Func<Task> act = () => api.GetFileAsync("filename.txt", TestContext.Current.CancellationToken);
|
||||
await act.Should().ThrowAsync<ApiException>();
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
|
||||
@@ -672,10 +677,10 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
string file = await api.GetFileAsync("filename.txt").ConfigureAwait(false);
|
||||
string file = await api.GetFileAsync("filename.txt", TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
Check.That(file).Equals(data);
|
||||
file.Should().Be(data);
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
|
||||
@@ -703,7 +708,7 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
await api.DeleteFileAsync("filename.txt").ConfigureAwait(false);
|
||||
await api.DeleteFileAsync("filename.txt", TestContext.Current.CancellationToken);
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
|
||||
@@ -714,7 +719,7 @@ public partial class WireMockAdminApiTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IWireMockAdminApi_DeleteFileAsync_NotFound()
|
||||
public async Task IWireMockAdminApi_DeleteFileAsync_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var filesystemHandlerMock = new Mock<IFileSystemHandler>(MockBehavior.Strict);
|
||||
@@ -731,7 +736,8 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act and Assert
|
||||
Check.ThatAsyncCode(() => api.DeleteFileAsync("filename.txt")).Throws<ApiException>();
|
||||
Func<Task> act = () => api.DeleteFileAsync("filename.txt", TestContext.Current.CancellationToken);
|
||||
await act.Should().ThrowAsync<ApiException>();
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
|
||||
@@ -741,7 +747,7 @@ public partial class WireMockAdminApiTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IWireMockAdminApi_FileExistsAsync_NotFound()
|
||||
public async Task IWireMockAdminApi_FileExistsAsync_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var filesystemHandlerMock = new Mock<IFileSystemHandler>(MockBehavior.Strict);
|
||||
@@ -757,7 +763,8 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act and Assert
|
||||
Check.ThatAsyncCode(() => api.FileExistsAsync("filename.txt")).Throws<ApiException>();
|
||||
Func<Task> act = () => api.FileExistsAsync("filename.txt", TestContext.Current.CancellationToken);
|
||||
await act.Should().ThrowAsync<ApiException>();
|
||||
|
||||
// Verify
|
||||
filesystemHandlerMock.Verify(fs => fs.FileExists(It.Is<string>(p => p == "filename.txt")), Times.Once);
|
||||
@@ -775,7 +782,7 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var status = await api.DeleteScenarioAsync(name).ConfigureAwait(false);
|
||||
var status = await api.DeleteScenarioAsync(name, TestContext.Current.CancellationToken);
|
||||
status.Status.Should().Be("No scenario found by name 'x'.");
|
||||
}
|
||||
|
||||
@@ -788,7 +795,7 @@ public partial class WireMockAdminApiTests
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var status = await api.ResetScenarioAsync(name).ConfigureAwait(false);
|
||||
var status = await api.ResetScenarioAsync(name, TestContext.Current.CancellationToken);
|
||||
status.Status.Should().Be("No scenario found by name 'x'.");
|
||||
}
|
||||
|
||||
@@ -805,7 +812,7 @@ public partial class WireMockAdminApiTests
|
||||
{
|
||||
State = null
|
||||
};
|
||||
var status = await api.PutScenarioStateAsync("x", update).ConfigureAwait(false);
|
||||
var status = await api.PutScenarioStateAsync("x", update, TestContext.Current.CancellationToken);
|
||||
status.Status.Should().Be("No scenario found by name 'x'.");
|
||||
}
|
||||
|
||||
@@ -839,7 +846,7 @@ public partial class WireMockAdminApiTests
|
||||
{
|
||||
State = null
|
||||
};
|
||||
var status = await api.PutScenarioStateAsync("s1", update).ConfigureAwait(false);
|
||||
var status = await api.PutScenarioStateAsync("s1", update, TestContext.Current.CancellationToken);
|
||||
status.Status.Should().Be("Scenario state set to ''");
|
||||
}
|
||||
|
||||
@@ -866,13 +873,13 @@ public partial class WireMockAdminApiTests
|
||||
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
var getMappingResult = await api.GetMappingAsync(guid, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
await Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -881,6 +888,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetMappingCodeByGuidAsync()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
|
||||
@@ -901,13 +909,13 @@ public partial class WireMockAdminApiTests
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
var mappings = await api.GetMappingsAsync().ConfigureAwait(false);
|
||||
var mappings = await api.GetMappingsAsync(cancellationToken);
|
||||
mappings.Should().HaveCount(1);
|
||||
|
||||
var code = await api.GetMappingCodeAsync(guid).ConfigureAwait(false);
|
||||
var code = await api.GetMappingCodeAsync(guid, cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
await Verifier.Verify(code).DontScrubDateTimes().DontScrubGuids();
|
||||
await Verify(code).DontScrubDateTimes().DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -916,6 +924,7 @@ public partial class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetMappingsCode()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var guid1 = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var guid2 = Guid.Parse("1b731398-4a5b-457f-a6e3-d65e541c428f");
|
||||
var guid3 = Guid.Parse("f74fd144-df53-404f-8e35-da22a640bd5f");
|
||||
@@ -991,7 +1000,7 @@ public partial class WireMockAdminApiTests
|
||||
.WithGuid(guid5)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(HttpStatusCode.AlreadyReported)
|
||||
.WithStatusCode(HttpStatusCode.Unused)
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
@as = 1,
|
||||
@@ -1023,13 +1032,13 @@ text
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
var mappings = await api.GetMappingsAsync().ConfigureAwait(false);
|
||||
var mappings = await api.GetMappingsAsync(cancellationToken);
|
||||
mappings.Should().HaveCount(5);
|
||||
|
||||
var code = await api.GetMappingsCodeAsync().ConfigureAwait(false);
|
||||
var code = await api.GetMappingsCodeAsync(cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
await Verifier.Verify(code).DontScrubDateTimes().DontScrubGuids();
|
||||
await Verify(code).DontScrubDateTimes().DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -1038,13 +1047,13 @@ text
|
||||
public async Task IWireMockAdminApi_OpenApiConvert_Yml()
|
||||
{
|
||||
// Arrange
|
||||
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore.yml"));
|
||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore.yml"));
|
||||
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var mappings = await api.OpenApiConvertAsync(openApiDocument).ConfigureAwait(false);
|
||||
var mappings = await api.OpenApiConvertAsync(openApiDocument, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
server.MappingModels.Should().BeEmpty();
|
||||
@@ -1057,13 +1066,13 @@ text
|
||||
public async Task IWireMockAdminApi_OpenApiConvert_Json()
|
||||
{
|
||||
// Arrange
|
||||
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
|
||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
|
||||
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var mappings = await api.OpenApiConvertAsync(openApiDocument).ConfigureAwait(false);
|
||||
var mappings = await api.OpenApiConvertAsync(openApiDocument, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
server.MappingModels.Should().BeEmpty();
|
||||
@@ -1076,13 +1085,13 @@ text
|
||||
public async Task IWireMockAdminApi_OpenApiSave_Json()
|
||||
{
|
||||
// Arrange
|
||||
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
|
||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore-openapi3.json"));
|
||||
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var statusModel = await api.OpenApiSaveAsync(openApiDocument).ConfigureAwait(false);
|
||||
var statusModel = await api.OpenApiSaveAsync(openApiDocument, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
statusModel.Status.Should().Be("OpenApi document converted to Mappings");
|
||||
@@ -1095,13 +1104,13 @@ text
|
||||
public async Task IWireMockAdminApi_OpenApiSave_Yml()
|
||||
{
|
||||
// Arrange
|
||||
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "petstore.yml"));
|
||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "petstore.yml"));
|
||||
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var mappings = await api.OpenApiConvertAsync(openApiDocument).ConfigureAwait(false);
|
||||
var mappings = await api.OpenApiConvertAsync(openApiDocument, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
server.MappingModels.Should().BeEmpty();
|
||||
@@ -1118,7 +1127,7 @@ text
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var status = await api.ReloadStaticMappingsAsync().ConfigureAwait(false);
|
||||
var status = await api.ReloadStaticMappingsAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
status.Status.Should().Be("Static Mappings reloaded");
|
||||
@@ -1128,5 +1137,4 @@ text
|
||||
{
|
||||
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings", filename));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.IdentityModel.Protocols;
|
||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Moq;
|
||||
using WireMock.Authentication;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Authentication;
|
||||
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Client;
|
||||
using WireMock.Client.Extensions;
|
||||
using WireMock.Net.Tests.VerifyExtensions;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Client.Builders;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
[UsesVerify]
|
||||
public class AdminApiMappingBuilderTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
|
||||
static AdminApiMappingBuilderTests()
|
||||
{
|
||||
VerifyNewtonsoftJson.Enable(VerifySettings);
|
||||
@@ -30,6 +21,8 @@ public class AdminApiMappingBuilderTests
|
||||
[Fact]
|
||||
public async Task GetMappingBuilder_BuildAndPostAsync()
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
|
||||
using var server = WireMockServer.StartWithAdminInterface();
|
||||
|
||||
var api = RestEase.RestClient.For<IWireMockAdminApi>(server.Url!);
|
||||
@@ -56,16 +49,15 @@ public class AdminApiMappingBuilderTests
|
||||
);
|
||||
|
||||
// Act
|
||||
var status = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
|
||||
var status = await mappingBuilder.BuildAndPostAsync(ct);
|
||||
|
||||
// Assert
|
||||
status.Status.Should().Be("Mapping added");
|
||||
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
var getMappingResult = await api.GetMappingAsync(guid, ct);
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
await Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections;
|
||||
using FluentAssertions;
|
||||
using WireMock.Extensions;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Extensions;
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using WireMock.Extensions;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Extensions;
|
||||
|
||||
|
||||
46
test/WireMock.Net.Tests/Extensions/HttpClientExtensions.cs
Normal file
46
test/WireMock.Net.Tests/Extensions/HttpClientExtensions.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !NET5_0_OR_GREATER
|
||||
namespace System.Net.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for HttpClient to provide CancellationToken support in frameworks before .NET 5.0.
|
||||
/// </summary>
|
||||
internal static class HttpClientExtensions
|
||||
{
|
||||
public static Task<Stream> GetStreamAsync(this HttpClient client, string requestUri, CancellationToken _)
|
||||
{
|
||||
return client.GetStreamAsync(requestUri);
|
||||
}
|
||||
|
||||
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string requestUri, CancellationToken _)
|
||||
{
|
||||
return client.GetAsync(requestUri);
|
||||
}
|
||||
|
||||
public static Task<string> GetStringAsync(this HttpClient client, string requestUri, CancellationToken _)
|
||||
{
|
||||
return client.GetStringAsync(requestUri);
|
||||
}
|
||||
|
||||
public static Task<string> GetStringAsync(this HttpClient client, Uri requestUri, CancellationToken _)
|
||||
{
|
||||
return client.GetStringAsync(requestUri);
|
||||
}
|
||||
|
||||
public static Task<HttpResponseMessage> PostAsync(this HttpClient client, string requestUri, HttpContent content, CancellationToken _)
|
||||
{
|
||||
return client.PostAsync(requestUri, content);
|
||||
}
|
||||
|
||||
public static Task<HttpResponseMessage> PostAsync(this HttpClient client, Uri requestUri, HttpContent content, CancellationToken _)
|
||||
{
|
||||
return client.PostAsync(requestUri, content);
|
||||
}
|
||||
|
||||
public static Task<HttpResponseMessage> SendAsync(this HttpClient client, HttpRequestMessage request, CancellationToken _)
|
||||
{
|
||||
return client.SendAsync(request);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
31
test/WireMock.Net.Tests/Extensions/HttpContentExtensions.cs
Normal file
31
test/WireMock.Net.Tests/Extensions/HttpContentExtensions.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !NET5_0_OR_GREATER
|
||||
namespace System.Net.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for HttpContent to provide CancellationToken support in frameworks before .NET 5.0.
|
||||
/// </summary>
|
||||
internal static class HttpContentExtensions
|
||||
{
|
||||
public static Task<string> ReadAsStringAsync(this HttpContent content, CancellationToken _)
|
||||
{
|
||||
return content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
public static Task<string> ReadAsStringAsync(this StringContent content, CancellationToken _)
|
||||
{
|
||||
return content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
public static Task<byte[]> ReadAsByteArrayAsync(this HttpContent content, CancellationToken _)
|
||||
{
|
||||
return content.ReadAsByteArrayAsync();
|
||||
}
|
||||
|
||||
public static Task<byte[]> ReadAsByteArrayAsync(this ByteArrayContent content, CancellationToken _)
|
||||
{
|
||||
return content.ReadAsByteArrayAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Xunit;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace WireMock.Net.Tests.Facts;
|
||||
|
||||
@@ -14,7 +13,9 @@ public sealed class IgnoreOnContinuousIntegrationFact : FactAttribute
|
||||
private static readonly bool IsContinuousIntegrationGithub = bool.TryParse(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), out var isGH) && isGH;
|
||||
private static readonly bool IsContinuousIntegration = IsContinuousIntegrationAzure || IsContinuousIntegrationGithub;
|
||||
|
||||
public IgnoreOnContinuousIntegrationFact()
|
||||
public IgnoreOnContinuousIntegrationFact(
|
||||
[CallerFilePath] string? sourceFilePath = null,
|
||||
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||
{
|
||||
if (IsContinuousIntegration)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
// Copyright © WireMock.Net
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using WireMock.Net.Testcontainers.Utils;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Facts;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class RunOnDockerPlatformFact : FactAttribute
|
||||
{
|
||||
public RunOnDockerPlatformFact(string platform)
|
||||
public RunOnDockerPlatformFact(
|
||||
string platform,
|
||||
[CallerFilePath] string? sourceFilePath = null,
|
||||
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||
{
|
||||
if (TestcontainersUtils.GetImageOSAsync.Value.Result != OSPlatform.Create(platform))
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,39 +0,0 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using WireMock.FluentAssertions;
|
||||
|
||||
namespace WireMock.Net.Tests.FluentAssertions;
|
||||
|
||||
public static class WireMockAssertionsExtensions
|
||||
{
|
||||
[CustomAssertion]
|
||||
public static AndWhichConstraint<WireMockAssertions, string> AtAbsoluteUrl2(this WireMockAssertions assertions,
|
||||
string absoluteUrl, string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var (filter, condition) = assertions.BuildFilterAndCondition(request => string.Equals(request.AbsoluteUrl, absoluteUrl, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Execute.Assertion
|
||||
.BecauseOf(because, becauseArgs)
|
||||
.Given(() => assertions.RequestMessages)
|
||||
.ForCondition(requests => assertions.CallsCount == 0 || requests.Any())
|
||||
.FailWith(
|
||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
||||
absoluteUrl
|
||||
)
|
||||
.Then
|
||||
.ForCondition(condition)
|
||||
.FailWith(
|
||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but didn't find it among the calls to {1}.",
|
||||
_ => absoluteUrl,
|
||||
requests => requests.Select(request => request.AbsoluteUrl)
|
||||
);
|
||||
|
||||
assertions.FilterRequestMessages(filter);
|
||||
|
||||
return new AndWhichConstraint<WireMockAssertions, string>(assertions, absoluteUrl);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,22 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.FluentAssertions;
|
||||
using System.Net.Http.Json;
|
||||
using WireMock.AwesomeAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.FluentAssertions;
|
||||
|
||||
public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
private readonly WireMockServer _server;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly int _portUsed;
|
||||
@@ -29,14 +27,13 @@ public class WireMockAssertionsTests : IDisposable
|
||||
_server.Given(Request.Create().UsingAnyMethod()).RespondWith(Response.Create().WithSuccess());
|
||||
|
||||
_portUsed = _server.Ports.First();
|
||||
|
||||
_httpClient = new HttpClient { BaseAddress = new Uri(_server.Url!) };
|
||||
_httpClient = _server.CreateClient();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_AtAbsoluteUrl_WhenACallWasNotMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
@@ -46,7 +43,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived0Calls_AtAbsoluteUrl_WhenACallWasNotMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(0).Calls()
|
||||
@@ -54,9 +51,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -64,19 +61,19 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrl2_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrl2_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
.AtAbsoluteUrl2($"http://localhost:{_portUsed}/anyurl");
|
||||
.AtAbsoluteUrl($"http://localhost:{_portUsed}/anyurl");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrlUsingPost_WhenAPostCallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrlUsingPost_WhenAPostCallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.PostAsync("anyurl", new StringContent("")).ConfigureAwait(false);
|
||||
await _httpClient.PostAsync("anyurl", new StringContent(""), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -88,9 +85,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived2Calls_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(2).Calls()
|
||||
@@ -100,7 +97,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -110,7 +107,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsoluteUrlWildcardMatcher_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -132,7 +129,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsoluteUrl_Should_ThrowWhenNoCallsMatchingTheAbsoluteUrlWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -146,7 +143,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_AtAbsolutePath_WhenACallWasNotMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
@@ -156,7 +153,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived0Calls_AtAbsolutePath_WhenACallWasNotMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(0).Calls()
|
||||
@@ -164,9 +161,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -174,9 +171,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsolutePathUsingPost_WhenAPostCallWasMadeToAbsolutePath_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsolutePathUsingPost_WhenAPostCallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.PostAsync("anypath", new StringContent("")).ConfigureAwait(false);
|
||||
await _httpClient.PostAsync("anypath", new StringContent(""), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -188,9 +185,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived2Calls_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(2).Calls()
|
||||
@@ -200,7 +197,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -210,7 +207,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsolutePathWildcardMatcher_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -232,7 +229,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsolutePath_Should_ThrowWhenNoCallsMatchingTheAbsolutePathWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -243,11 +240,111 @@ public class WireMockAssertionsTests : IDisposable
|
||||
.WithMessage($"Expected _server to have been called at address matching the absolute path \"/anypath\", but didn't find it among the calls to {{\"/\"}}.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_AtPath_WhenACallWasNotMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
.AtPath("anypath");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived0Calls_AtPath_WhenACallWasNotMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(0).Calls()
|
||||
.AtPath("anypath");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Call_AtPath_WhenACallWasMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
.AtPath("/anypath");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Call_AtPathUsingPost_WhenAPostCallWasMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.PostAsync("anypath", new StringContent(""), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
.AtPath("/anypath")
|
||||
.And
|
||||
.UsingPost();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived2Calls_AtPath_WhenACallWasMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(2).Calls()
|
||||
.AtPath("/anypath");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtPath_WhenACallWasMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.AtPath(new WildcardMatcher("/any*"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtPathWildcardMatcher_WhenACallWasMadeToPath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.AtPath("/anypath");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HaveReceivedACall_AtPath_Should_ThrowWhenNoCallsWereMade()
|
||||
{
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
.AtPath("anypath");
|
||||
|
||||
act.Should()
|
||||
.Throw<Exception>()
|
||||
.WithMessage("Expected _server to have been called at address matching the path \"anypath\", but no calls were made.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtPath_Should_ThrowWhenNoCallsMatchingThePathWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
.AtPath("/anypath");
|
||||
|
||||
act.Should()
|
||||
.Throw<Exception>()
|
||||
.WithMessage($"Expected _server to have been called at address matching the path \"/anypath\", but didn't find it among the calls to {{\"/\"}}.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_WithHeader_WhenACallWasMadeWithExpectedHeader_Should_BeOK()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -258,7 +355,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
public async Task HaveReceivedACall_WithHeader_WhenACallWasMadeWithExpectedHeaderWithValue_Should_BeOK()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -270,10 +367,10 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("1").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("1", _ct);
|
||||
|
||||
_httpClient.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("EN"));
|
||||
await _httpClient.GetAsync("2").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("2", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -285,7 +382,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderNameWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -301,7 +398,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -309,7 +406,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
act.Should()
|
||||
.Throw<Exception>()
|
||||
.WithMessage("Expected _server to have been called with Header \"Accept\" and Values {\"missing-value\"}, but didn't find it among the calls with Header(s)*");
|
||||
.WithMessage("Expected _server to have been called with Header \"Accept\" and Values {\"missing-value\"}, but didn't find it among the calls with Header*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -319,7 +416,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
await httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -347,7 +444,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
Authorization = new AuthenticationHeaderValue("Bearer", "invalidToken")
|
||||
}
|
||||
});
|
||||
}, _ct);
|
||||
|
||||
// Act 2
|
||||
var task2 = client2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
|
||||
@@ -356,7 +453,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
Authorization = new AuthenticationHeaderValue("Bearer", "validToken")
|
||||
}
|
||||
});
|
||||
}, _ct);
|
||||
|
||||
await Task.WhenAll(task1, task2);
|
||||
|
||||
@@ -373,7 +470,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtUrl_WhenACallWasMadeToUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -383,7 +480,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtUrlWildcardMatcher_WhenACallWasMadeToUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -405,7 +502,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtUrl_Should_ThrowWhenNoCallsMatchingTheUrlWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -423,7 +520,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));
|
||||
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -453,7 +550,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));
|
||||
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -467,7 +564,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
|
||||
_server.Should()
|
||||
@@ -490,7 +587,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_FromClientIP_Should_ThrowWhenNoCallsFromClientIPWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
|
||||
Action act = () => _server.Should()
|
||||
@@ -505,7 +602,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_UsingPost_WhenACallWasNotMadeUsingPost_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
@@ -517,9 +614,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
var tasks = new[]
|
||||
{
|
||||
_httpClient.DeleteAsync("anyurl"),
|
||||
_httpClient.DeleteAsync("anyurl"),
|
||||
_httpClient.GetAsync("anyurl")
|
||||
_httpClient.DeleteAsync("anyurl", _ct),
|
||||
_httpClient.DeleteAsync("anyurl", _ct),
|
||||
_httpClient.GetAsync("anyurl", _ct)
|
||||
};
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@@ -544,7 +641,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingOptions_Should_ThrowWhenCallsWereNotMadeUsingOptions()
|
||||
{
|
||||
await _httpClient.PostAsync("anyurl", new StringContent("anycontent")).ConfigureAwait(false);
|
||||
await _httpClient.PostAsync("anyurl", new StringContent("anycontent"), _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -555,7 +652,6 @@ public class WireMockAssertionsTests : IDisposable
|
||||
.WithMessage("Expected _server to have been called using method \"OPTIONS\", but didn't find it among the methods {\"POST\"}.");
|
||||
}
|
||||
|
||||
#if !NET452
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingConnect_WhenACallWasMadeUsingConnect_Should_BeOK()
|
||||
{
|
||||
@@ -565,18 +661,17 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Add("Host", new Uri(_server.Urls[0]).Authority);
|
||||
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("CONNECT"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("CONNECT"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.UsingConnect();
|
||||
}
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingDelete_WhenACallWasMadeUsingDelete_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("DELETE"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("DELETE"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -586,7 +681,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingGet_WhenACallWasMadeUsingGet_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -596,7 +691,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingHead_WhenACallWasMadeUsingHead_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("HEAD"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("HEAD"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -606,7 +701,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingOptions_WhenACallWasMadeUsingOptions_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("OPTIONS"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("OPTIONS"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -618,7 +713,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[InlineData("Post")]
|
||||
public async Task HaveReceivedACall_UsingPost_WhenACallWasMadeUsingPost_Should_BeOK(string method)
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(method), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(method), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -626,7 +721,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrlUsingPost_ShouldChain()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrlUsingPost_ShouldChain()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.Start();
|
||||
@@ -648,9 +743,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
var tasks = new[]
|
||||
{
|
||||
httpClient.GetAsync($"{server.Url}/a"),
|
||||
httpClient.PostAsync($"{server.Url}/b", new StringContent("B")),
|
||||
httpClient.PostAsync($"{server.Url}/c", new StringContent("C"))
|
||||
httpClient.GetAsync($"{server.Url}/a", _ct),
|
||||
httpClient.PostAsync($"{server.Url}/b", new StringContent("B"), _ct),
|
||||
httpClient.PostAsync($"{server.Url}/c", new StringContent("C"), _ct)
|
||||
};
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@@ -703,7 +798,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingPatch_WhenACallWasMadeUsingPatch_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -713,7 +808,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingPut_WhenACallWasMadeUsingPut_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PUT"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PUT"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -723,7 +818,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingTrace_WhenACallWasMadeUsingTrace_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("TRACE"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("TRACE"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -733,7 +828,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingAnyMethod_WhenACallWasMadeUsingGet_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -781,7 +876,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"), _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -836,7 +931,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
x = "y"
|
||||
};
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody);
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody, _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -891,7 +986,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
x = "123"
|
||||
};
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody);
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody, _ct);
|
||||
|
||||
// Assert
|
||||
Action act = () => server
|
||||
@@ -922,7 +1017,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("123"));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("123"), _ct);
|
||||
|
||||
// Assert
|
||||
Action act = () => server
|
||||
@@ -953,7 +1048,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new ByteArrayContent([5]));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new ByteArrayContent([5]), _ct);
|
||||
|
||||
// Assert
|
||||
Action act = () => server
|
||||
@@ -984,7 +1079,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PutAsync($"{server.Url}/a", new ByteArrayContent([100]));
|
||||
await httpClient.PutAsync($"{server.Url}/a", new ByteArrayContent([100]), _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -1027,7 +1122,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"), _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -1065,13 +1160,13 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
// Act : HTTP GET
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(server.Url!);
|
||||
await httpClient.GetAsync(server.Url, _ct);
|
||||
|
||||
// Act : HTTP POST
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url!);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url);
|
||||
request.Headers.Add("TestHeader", ["Value", "Value2"]);
|
||||
|
||||
await httpClient.SendAsync(request);
|
||||
await httpClient.SendAsync(request, _ct);
|
||||
|
||||
// Assert
|
||||
server.Should().HaveReceivedACall().UsingPost().And.WithHeader("TestHeader", ["Value", "Value2"]);
|
||||
@@ -1090,13 +1185,13 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
// Act : HTTP GET
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(server.Url!);
|
||||
await httpClient.GetAsync(server.Url, _ct);
|
||||
|
||||
// Act : HTTP POST
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url!);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url);
|
||||
request.Headers.Add("TestHeader", ["Value", "Value2"]);
|
||||
|
||||
await httpClient.SendAsync(request);
|
||||
await httpClient.SendAsync(request, _ct);
|
||||
|
||||
// Assert
|
||||
server.Should().HaveReceivedACall().UsingPost().And.WitHeaderKey("TestHeader");
|
||||
|
||||
1
test/WireMock.Net.Tests/GlobalUsings.cs
Normal file
1
test/WireMock.Net.Tests/GlobalUsings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using AwesomeAssertions;
|
||||
@@ -1,43 +1,36 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Grpc;
|
||||
|
||||
public class ProtoBufUtilsTests
|
||||
{
|
||||
private static readonly IProtoBufUtils ProtoBufUtils = new ProtoBufUtils();
|
||||
private static readonly ProtoBufUtils _sut = new();
|
||||
|
||||
[Fact]
|
||||
public async Task GetProtoBufMessageWithHeader_MultipleProtoFiles()
|
||||
{
|
||||
// Arrange
|
||||
var greet = await ReadProtoFileAsync("greet1.proto");
|
||||
var request = await ReadProtoFileAsync("request.proto");
|
||||
var greet = ReadProtoFile("greet1.proto");
|
||||
var request = ReadProtoFile("request.proto");
|
||||
|
||||
// Act
|
||||
var responseBytes = await ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(
|
||||
var responseBytes = await _sut.GetProtoBufMessageWithHeaderAsync(
|
||||
[greet, request],
|
||||
"greet.HelloRequest",
|
||||
new
|
||||
"greet.HelloRequest", new
|
||||
{
|
||||
name = "hello"
|
||||
}
|
||||
},
|
||||
cancellationToken: TestContext.Current.CancellationToken
|
||||
);
|
||||
|
||||
// Assert
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAcKBWhlbGxv");
|
||||
}
|
||||
|
||||
private static Task<string> ReadProtoFileAsync(string filename)
|
||||
private static string ReadProtoFile(string filename)
|
||||
{
|
||||
return File.ReadAllTextAsync(Path.Combine(Directory.GetCurrentDirectory(), "Grpc", filename));
|
||||
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Grpc", filename));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Grpc;
|
||||
|
||||
@@ -18,12 +12,13 @@ public class ProtoDefinitionHelperTests
|
||||
public async Task FromDirectory_Greet_ShouldReturnModifiedProtoFiles()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var directory = Path.Combine(Directory.GetCurrentDirectory(), "Grpc", "Test");
|
||||
var expectedFilename = "SubFolder/request.proto";
|
||||
var expectedComment = $"// {expectedFilename}";
|
||||
|
||||
// Act
|
||||
var protoDefinitionData = await ProtoDefinitionDataHelper.FromDirectory(directory);
|
||||
var protoDefinitionData = await ProtoDefinitionDataHelper.FromDirectory(directory, cancellationToken);
|
||||
var protoDefinitions = protoDefinitionData.ToList("greet");
|
||||
|
||||
// Assert
|
||||
@@ -39,7 +34,7 @@ public class ProtoDefinitionHelperTests
|
||||
resolver.Exists("x").Should().BeFalse();
|
||||
|
||||
// Act + Assert
|
||||
var text = await resolver.OpenText(expectedFilename).ReadToEndAsync();
|
||||
var text = resolver.OpenText(expectedFilename).ReadToEnd();
|
||||
text.Should().StartWith(expectedComment);
|
||||
System.Action action = () => resolver.OpenText("x");
|
||||
action.Should().Throw<FileNotFoundException>();
|
||||
@@ -52,7 +47,7 @@ public class ProtoDefinitionHelperTests
|
||||
var directory = Path.Combine(Directory.GetCurrentDirectory(), "Grpc", "ot");
|
||||
|
||||
// Act
|
||||
var protoDefinitionData = await ProtoDefinitionDataHelper.FromDirectory(directory);
|
||||
var protoDefinitionData = await ProtoDefinitionDataHelper.FromDirectory(directory, TestContext.Current.CancellationToken);
|
||||
var protoDefinitions = protoDefinitionData.ToList("trace_service");
|
||||
|
||||
// Assert
|
||||
@@ -65,11 +60,11 @@ public class ProtoDefinitionHelperTests
|
||||
{
|
||||
rejected_spans = 1,
|
||||
error_message = "abc"
|
||||
}
|
||||
},
|
||||
cancellationToken: TestContext.Current.CancellationToken
|
||||
);
|
||||
|
||||
// Assert
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAcIARIDYWJj");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,26 +1,19 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using ExampleIntegrationTest.Lookup;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Greet;
|
||||
using Grpc.Net.Client;
|
||||
using ExampleIntegrationTest.Lookup;
|
||||
using WireMock.Constants;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WireMock.Net.Tests;
|
||||
@@ -140,7 +133,7 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/greet.Greeter/SayHello", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/greet.Greeter/SayHello", protoBuf, TestContext.Current.CancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
@@ -152,6 +145,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf(string data)
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var bytes = Convert.FromBase64String(data);
|
||||
var jsonMatcher = new JsonMatcher(new { name = "stef" });
|
||||
|
||||
@@ -178,11 +172,11 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/greet.Greeter/SayHello", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/greet.Greeter/SayHello", protoBuf, cancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAcKBWhlbGxv");
|
||||
}
|
||||
@@ -191,6 +185,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes_Empty()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
using var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
@@ -212,11 +207,11 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayNothing", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayNothing", protoBuf, cancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAA=");
|
||||
}
|
||||
@@ -225,6 +220,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes_Timestamp()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
using var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
@@ -254,11 +250,11 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayTimestamp", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayTimestamp", protoBuf, cancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAsKCQiL96C1BhCMYA==");
|
||||
}
|
||||
@@ -267,6 +263,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes_Duration()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
using var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
@@ -296,11 +293,11 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayDuration", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayDuration", protoBuf, cancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAsKCQiL96C1BhCMYA==");
|
||||
}
|
||||
@@ -309,6 +306,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_ServerProtoDefinition_WithWellKnownTypes()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var bytes = Convert.FromBase64String("CgRzdGVm");
|
||||
|
||||
using var server = WireMockServer.Start();
|
||||
@@ -335,11 +333,11 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayNothing", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/Greeter/SayNothing", protoBuf, cancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAA=");
|
||||
}
|
||||
@@ -348,6 +346,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_MultipleFiles()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var bytes = Convert.FromBase64String("CgRzdGVm");
|
||||
var jsonMatcher = new JsonMatcher(new { name = "stef" });
|
||||
|
||||
@@ -376,11 +375,11 @@ message Other {
|
||||
protoBuf.Headers.ContentType = new MediaTypeHeaderValue("application/grpc-web");
|
||||
|
||||
var client = server.CreateClient();
|
||||
var response = await client.PostAsync("/grpc/greet.Greeter/SayOther", protoBuf);
|
||||
var response = await client.PostAsync("/grpc/greet.Greeter/SayOther", protoBuf, cancellationToken);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAcKBWhlbGxv");
|
||||
}
|
||||
@@ -389,6 +388,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_InlineProtoDefinition_UsingGrpcGeneratedClient()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
var jsonMatcher = new JsonMatcher(new { name = "stef" });
|
||||
@@ -415,7 +415,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
var reply = await client.SayHelloAsync(new HelloRequest { Name = "stef" });
|
||||
var reply = await client.SayHelloAsync(new HelloRequest { Name = "stef" }, cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Message.Should().Be("hello stef POST");
|
||||
@@ -425,6 +425,7 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_MappingProtoDefinition_UsingGrpcGeneratedClient()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
var jsonMatcher = new JsonMatcher(new { name = "stef" });
|
||||
@@ -453,7 +454,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
var reply = await client.SayHelloAsync(new HelloRequest { Name = "stef" });
|
||||
var reply = await client.SayHelloAsync(new HelloRequest { Name = "stef" }, cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Message.Should().Be("hello stef POST");
|
||||
@@ -465,6 +466,7 @@ message Other {
|
||||
// Arrange
|
||||
var id = $"test-{Guid.NewGuid()}";
|
||||
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
var jsonMatcher = new JsonMatcher(new { name = "stef" });
|
||||
@@ -491,7 +493,7 @@ message Other {
|
||||
);
|
||||
|
||||
// Act
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(server.Url!);
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(server.Url!, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Then_ReplyMessage_Should_BeCorrect(reply);
|
||||
@@ -501,7 +503,8 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes_Empty_UsingGrpcGeneratedClient()
|
||||
{
|
||||
// Arrange
|
||||
var definition = await File.ReadAllTextAsync("./Grpc/greet.proto");
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var definition = File.ReadAllText("./Grpc/greet.proto");
|
||||
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
@@ -522,7 +525,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
var reply = await client.SayNothingAsync(new Empty());
|
||||
var reply = await client.SayNothingAsync(new Empty(), cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Should().Be(new Empty());
|
||||
@@ -534,7 +537,8 @@ message Other {
|
||||
// Arrange
|
||||
const int seconds = 1722301323;
|
||||
const int nanos = 12300;
|
||||
var definition = await File.ReadAllTextAsync("./Grpc/greet.proto");
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var definition = File.ReadAllText("./Grpc/greet.proto");
|
||||
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
@@ -563,7 +567,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
var reply = await client.SayTimestampAsync(new MyMessageTimestamp { Ts = Timestamp.FromDateTime(DateTime.UtcNow) });
|
||||
var reply = await client.SayTimestampAsync(new MyMessageTimestamp { Ts = Timestamp.FromDateTime(DateTime.UtcNow) }, cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Ts.Should().Be(new Timestamp { Seconds = seconds, Nanos = nanos });
|
||||
@@ -575,7 +579,8 @@ message Other {
|
||||
// Arrange
|
||||
const int seconds = 1722301323;
|
||||
const int nanos = 12300;
|
||||
var definition = await File.ReadAllTextAsync("./Grpc/greet.proto");
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var definition = File.ReadAllText("./Grpc/greet.proto");
|
||||
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
@@ -604,7 +609,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
var reply = await client.SayDurationAsync(new MyMessageDuration { Du = Duration.FromTimeSpan(TimeSpan.MinValue) });
|
||||
var reply = await client.SayDurationAsync(new MyMessageDuration { Du = Duration.FromTimeSpan(TimeSpan.MinValue) }, cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Du.Should().Be(new Duration { Seconds = seconds, Nanos = nanos });
|
||||
@@ -614,7 +619,8 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_Enum_UsingGrpcGeneratedClient()
|
||||
{
|
||||
// Arrange
|
||||
var definition = await File.ReadAllTextAsync("./Grpc/greet.proto");
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var definition = File.ReadAllText("./Grpc/greet.proto");
|
||||
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
@@ -640,7 +646,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
var reply = await client.SayHelloAsync(new HelloRequest());
|
||||
var reply = await client.SayHelloAsync(new HelloRequest(), cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Message.Should().Be("hello");
|
||||
@@ -651,11 +657,12 @@ message Other {
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_Enum_UsingPolicyGrpcGeneratedClient()
|
||||
{
|
||||
// Arrange
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
const int seconds = 1722301323;
|
||||
const int nanos = 12300;
|
||||
const string version = "test";
|
||||
const string correlationId = "correlation";
|
||||
var definition = await File.ReadAllTextAsync("./Grpc/policy.proto");
|
||||
var definition = File.ReadAllText("./Grpc/policy.proto");
|
||||
|
||||
using var server = WireMockServer.Start(useHttp2: true);
|
||||
|
||||
@@ -690,7 +697,7 @@ message Other {
|
||||
var channel = GrpcChannel.ForAddress(server.Url!);
|
||||
var client = new PolicyService.PolicyServiceClient(channel);
|
||||
|
||||
var reply = await client.GetVersionAsync(new GetVersionRequest());
|
||||
var reply = await client.GetVersionAsync(new GetVersionRequest(), cancellationToken: cancellationToken);
|
||||
|
||||
// Assert
|
||||
reply.Version.Should().Be(version);
|
||||
@@ -702,10 +709,11 @@ message Other {
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_FromJson_UsingGrpcGeneratedClient()
|
||||
{
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = Given_When_ServerStarted_And_RunningOnHttpAndGrpc();
|
||||
await Given_When_ProtoBufMappingIsAddedViaAdminInterfaceAsync(server, "protobuf-mapping-1.json");
|
||||
await Given_When_ProtoBufMappingIsAddedViaAdminInterfaceAsync(server, "protobuf-mapping-1.json", cancellationToken);
|
||||
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(server.Urls[1]);
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(server.Urls[1], cancellationToken);
|
||||
|
||||
Then_ReplyMessage_Should_BeCorrect(reply);
|
||||
}
|
||||
@@ -713,22 +721,21 @@ message Other {
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithBodyAsProtoBuf_ServerProtoDefinitionFromJson_UsingGrpcGeneratedClient()
|
||||
{
|
||||
var cancellationToken = TestContext.Current.CancellationToken;
|
||||
var server = Given_When_ServerStarted_And_RunningOnHttpAndGrpc();
|
||||
Given_ProtoDefinition_IsAddedOnServerLevel(server);
|
||||
await Given_When_ProtoBufMappingIsAddedViaAdminInterfaceAsync(server, "protobuf-mapping-3.json");
|
||||
await Given_When_ProtoBufMappingIsAddedViaAdminInterfaceAsync(server, "protobuf-mapping-3.json", cancellationToken);
|
||||
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(server.Urls[1]);
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(server.Urls[1], cancellationToken);
|
||||
|
||||
Then_ReplyMessage_Should_BeCorrect(reply);
|
||||
}
|
||||
|
||||
private static WireMockServer Given_When_ServerStarted_And_RunningOnHttpAndGrpc()
|
||||
{
|
||||
var ports = PortUtils.FindFreeTcpPorts(2);
|
||||
|
||||
var settings = new WireMockServerSettings
|
||||
{
|
||||
Urls = [$"http://*:{ports[0]}/", $"grpc://*:{ports[1]}/"],
|
||||
Urls = [$"http://*:0", $"grpc://*:0/"],
|
||||
StartAdminInterface = true
|
||||
};
|
||||
return WireMockServer.Start(settings);
|
||||
@@ -739,23 +746,23 @@ message Other {
|
||||
server.AddProtoDefinition("my-greeter", ReadProtoFile("greet.proto"));
|
||||
}
|
||||
|
||||
private static async Task Given_When_ProtoBufMappingIsAddedViaAdminInterfaceAsync(WireMockServer server, string filename)
|
||||
private static async Task Given_When_ProtoBufMappingIsAddedViaAdminInterfaceAsync(WireMockServer server, string filename, CancellationToken cancellationToken)
|
||||
{
|
||||
var mappingsJson = ReadMappingFile(filename);
|
||||
|
||||
using var httpClient = server.CreateClient();
|
||||
|
||||
var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, WireMockConstants.ContentTypeJson));
|
||||
var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, WireMockConstants.ContentTypeJson), cancellationToken);
|
||||
result.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
private static async Task<HelloReply> When_GrpcClient_Calls_SayHelloAsync(string address)
|
||||
private static async Task<HelloReply> When_GrpcClient_Calls_SayHelloAsync(string address, CancellationToken cancellationToken)
|
||||
{
|
||||
var channel = GrpcChannel.ForAddress(address);
|
||||
|
||||
var client = new Greeter.GreeterClient(channel);
|
||||
|
||||
return await client.SayHelloAsync(new HelloRequest { Name = "stef" });
|
||||
return await client.SayHelloAsync(new HelloRequest { Name = "stef" }, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
private static void Then_ReplyMessage_Should_BeCorrect(HelloReply reply)
|
||||
@@ -772,5 +779,4 @@ message Other {
|
||||
{
|
||||
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Grpc", filename));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Handlers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Handlers;
|
||||
|
||||
@@ -19,28 +16,31 @@ public class LocalFileSystemHandlerTests
|
||||
string result = _sut.GetMappingFolder();
|
||||
|
||||
// Assert
|
||||
Check.That(result).EndsWith(Path.Combine("__admin", "mappings"));
|
||||
result.Should().EndWith(Path.Combine("__admin", "mappings"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_CreateFolder_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.CreateFolder(null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.CreateFolder(null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_WriteMappingFile_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.WriteMappingFile(null, null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.WriteMappingFile(null, null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_ReadResponseBodyAsFile_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.ReadResponseBodyAsFile(null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.ReadResponseBodyAsFile(null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,42 +50,47 @@ public class LocalFileSystemHandlerTests
|
||||
var result = _sut.FileExists("x.x");
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsFalse();
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_FileExists_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.FileExists(null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.FileExists(null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_ReadFile_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.ReadFile(null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.ReadFile(null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_ReadFileAsString_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.ReadFileAsString(null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.ReadFileAsString(null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_WriteFile_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.WriteFile(null, null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.WriteFile(null, null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_DeleteFile_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.DeleteFile(null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.DeleteFile(null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -95,13 +100,17 @@ public class LocalFileSystemHandlerTests
|
||||
string result = _sut.GetUnmatchedRequestsFolder();
|
||||
|
||||
// Assert
|
||||
Check.That(result).EndsWith(Path.Combine("requests", "unmatched"));
|
||||
result.Should().EndWith(Path.Combine("requests", "unmatched"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_WriteUnmatchedRequest()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.WriteUnmatchedRequest(null, null)).Throws<ArgumentNullException>();
|
||||
Action act = () => _sut.WriteUnmatchedRequest(null, null);
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Http;
|
||||
|
||||
public class ByteArrayContentHelperTests
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public async Task ByteArrayContentHelperTests_Create_WithNullContentType()
|
||||
{
|
||||
@@ -22,7 +22,7 @@ public class ByteArrayContentHelperTests
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
(await result.ReadAsByteArrayAsync(_ct)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -39,7 +39,7 @@ public class ByteArrayContentHelperTests
|
||||
var result = ByteArrayContentHelper.Create(content, contentType);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
result.Headers.ContentType?.ToString().Should().Be(expected);
|
||||
(await result.ReadAsByteArrayAsync(_ct)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Http;
|
||||
using WireMock.Models;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Http;
|
||||
|
||||
@@ -17,6 +14,8 @@ public class HttpRequestMessageHelperTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public void HttpRequestMessageHelper_Create()
|
||||
{
|
||||
@@ -28,7 +27,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Headers.GetValues("x")).ContainsExactly("value-1");
|
||||
message.Headers.GetValues("x").Should().Equal(new[] { "value-1" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -46,7 +45,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||
(await message.Content!.ReadAsByteArrayAsync(_ct)).Should().Equal(Encoding.UTF8.GetBytes("hi"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -64,7 +63,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("0123");
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("0123");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -82,7 +81,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -101,8 +100,8 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json");
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/json" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -121,8 +120,8 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/json; charset=utf-8" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -142,8 +141,8 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("multipart/form-data");
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "multipart/form-data" });
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +162,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Content!.Headers.GetValues("Content-Type")).ContainsExactly("application/xml");
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/xml" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -182,7 +181,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Content!.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=UTF-8");
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/xml; charset=UTF-8" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -201,7 +200,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(message.Content!.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=Ascii");
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/xml; charset=Ascii" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -242,8 +241,8 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals(body);
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("multipart/form-data");
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be(body);
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "multipart/form-data" });
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -270,4 +269,7 @@ public class HttpRequestMessageHelperTests
|
||||
// Assert
|
||||
message.Content?.Headers.ContentLength.Should().Be(resultShouldBe ? value : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using FluentAssertions;
|
||||
using WireMock.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Http;
|
||||
|
||||
public class StringContentHelperTests
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public void StringContentHelper_Create_WithNullContentType()
|
||||
public async Task StringContentHelper_Create_WithNullContentType()
|
||||
{
|
||||
// Act
|
||||
var result = StringContentHelper.Create("test", null);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||
(await result.ReadAsStringAsync(_ct)).Should().Be("test");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -25,7 +26,7 @@ public class StringContentHelperTests
|
||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||
[InlineData("application/soap+xml;charset=UTF-8", "application/soap+xml; charset=UTF-8")]
|
||||
[InlineData("application/soap+xml;charset=UTF-8;action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"", "application/soap+xml; charset=UTF-8; action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"")]
|
||||
public void StringContentHelper_Create(string test, string expected)
|
||||
public async Task StringContentHelper_Create(string test, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||
@@ -34,7 +35,7 @@ public class StringContentHelperTests
|
||||
var result = StringContentHelper.Create("test", contentType);
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||
result.Headers.ContentType?.ToString().Should().Be(expected);
|
||||
(await result.ReadAsStringAsync(_ct)).Should().Be("test");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
@@ -18,11 +13,9 @@ using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
[UsesVerify]
|
||||
public class MappingBuilderTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
@@ -158,7 +151,7 @@ public class MappingBuilderTests
|
||||
var mappings = _sut.GetMappings();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(mappings, VerifySettings).DontScrubGuids();
|
||||
return Verify(mappings, VerifySettings).DontScrubGuids();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -168,7 +161,7 @@ public class MappingBuilderTests
|
||||
var json = _sut.ToJson();
|
||||
|
||||
// Verify
|
||||
return Verifier.VerifyJson(json, VerifySettings).DontScrubGuids();
|
||||
return VerifyJson(json, VerifySettings).DontScrubGuids();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -178,7 +171,7 @@ public class MappingBuilderTests
|
||||
var code = _sut.ToCSharpCode(MappingConverterType.Server);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code, VerifySettings).DontScrubGuids();
|
||||
return Verify(code, VerifySettings).DontScrubGuids();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -188,7 +181,7 @@ public class MappingBuilderTests
|
||||
var code = _sut.ToCSharpCode(MappingConverterType.Builder);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code, VerifySettings).DontScrubGuids();
|
||||
return Verify(code, VerifySettings).DontScrubGuids();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -259,5 +252,4 @@ public class MappingBuilderTests
|
||||
_fileSystemHandlerMock.Verify(fs => fs.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(_numMappings));
|
||||
_fileSystemHandlerMock.VerifyNoOtherCalls();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -80,7 +77,7 @@ public class CSharpCodeMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("CSharpCodeMatcher");
|
||||
name.Should().Be("CSharpCodeMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,6 +90,6 @@ public class CSharpCodeMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
patterns.Should().ContainSingle("x");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -52,7 +49,7 @@ public class ContentTypeMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("ContentTypeMatcher");
|
||||
name.Should().Be("ContentTypeMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,6 +62,6 @@ public class ContentTypeMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
patterns.Should().ContainSingle("x");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -18,7 +16,7 @@ public class ExactMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("ExactMatcher");
|
||||
name.Should().Be("ExactMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -31,7 +29,7 @@ public class ExactMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
patterns.Should().ContainSingle("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -44,7 +42,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("X").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -57,7 +55,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("x").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +68,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("y").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -83,7 +81,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("x").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -96,7 +94,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("x").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -112,7 +110,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("x").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(score);
|
||||
result.Should().Be(score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -125,7 +123,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("caR").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -138,7 +136,7 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("cat").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -151,6 +149,6 @@ public class ExactMatcherTests
|
||||
double result = matcher.IsMatch("cat").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -19,7 +18,7 @@ public class ExactObjectMatcherTests
|
||||
var name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("ExactObjectMatcher");
|
||||
name.Should().Be("ExactObjectMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -33,7 +32,7 @@ public class ExactObjectMatcherTests
|
||||
var score = matcher.IsMatch(checkValue).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0);
|
||||
score.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,7 +46,7 @@ public class ExactObjectMatcherTests
|
||||
var score = matcher.IsMatch(new { x = 500, s = "s" }).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0);
|
||||
score.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,6 +60,6 @@ public class ExactObjectMatcherTests
|
||||
var score = matcher.IsMatch(new { x = 500, s = "s" }).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0);
|
||||
score.Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using AnyOfTypes;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class FormUrlEncodedMatcherTest
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Theory]
|
||||
[InlineData("*=*")]
|
||||
[InlineData("name=John Doe")]
|
||||
@@ -29,12 +26,12 @@ public class FormUrlEncodedMatcherTest
|
||||
public async Task FormUrlEncodedMatcher_IsMatch(params string[] patterns)
|
||||
{
|
||||
// Arrange
|
||||
var content = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
var content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string, string>("name", "John Doe"),
|
||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||
});
|
||||
var contentAsString = await content.ReadAsStringAsync();
|
||||
]);
|
||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||
|
||||
var matcher = new FormUrlEncodedMatcher(patterns.Select(p => new AnyOf<string, StringPattern>(p)).ToArray());
|
||||
|
||||
@@ -60,12 +57,12 @@ public class FormUrlEncodedMatcherTest
|
||||
public async Task FormUrlEncodedMatcher_IsMatch_And(bool expected, params string[] patterns)
|
||||
{
|
||||
// Arrange
|
||||
var content = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
var content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string, string>("name", "John Doe"),
|
||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||
});
|
||||
var contentAsString = await content.ReadAsStringAsync();
|
||||
]);
|
||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||
|
||||
var matcher = new FormUrlEncodedMatcher(patterns.Select(p => new AnyOf<string, StringPattern>(p)).ToArray(), true, MatchOperator.And);
|
||||
|
||||
@@ -80,12 +77,12 @@ public class FormUrlEncodedMatcherTest
|
||||
public async Task FormUrlEncodedMatcher_IsMatch_And_MatchAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
var content = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
var content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string, string>("name", "John Doe"),
|
||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||
});
|
||||
var contentAsString = await content.ReadAsStringAsync();
|
||||
]);
|
||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||
|
||||
// The expectation is that the matcher requires all properties to be present in the content.
|
||||
var matcher = new FormUrlEncodedMatcher(["name=*", "email=*", "required=*"], matchOperator: MatchOperator.And);
|
||||
|
||||
428
test/WireMock.Net.Tests/Matchers/FuncMatcherTests.cs
Normal file
428
test/WireMock.Net.Tests/Matchers/FuncMatcherTests.cs
Normal file
@@ -0,0 +1,428 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using WireMock.Matchers;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class FuncMatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_Should_Return_Perfect_When_Function_Returns_True()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_Should_Return_Mismatch_When_Function_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch("other");
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_Should_Handle_Null_String()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == null;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act - passing null as object, not as string
|
||||
var result = matcher.IsMatch((object?)null);
|
||||
|
||||
// Assert - null object doesn't match, returns mismatch
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_With_ByteArray_Input_Should_Return_Mismatch()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(new byte[] { 1, 2, 3 });
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_With_Null_Object_Should_Return_Mismatch()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch((object?)null);
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_Should_Handle_Exception()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => throw new InvalidOperationException("Test exception");
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
result.Exception.Should().NotBeNull();
|
||||
result.Exception.Should().BeOfType<InvalidOperationException>();
|
||||
result.Exception!.Message.Should().Be("Test exception");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_IsMatch_Should_Return_Perfect_When_Function_Returns_True()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length == 3;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(new byte[] { 1, 2, 3 });
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_IsMatch_Should_Return_Mismatch_When_Function_Returns_False()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length == 3;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(new byte[] { 1, 2, 3, 4, 5 });
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_IsMatch_Should_Handle_Null_ByteArray()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b == null;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act - passing null as object, not as byte[]
|
||||
var result = matcher.IsMatch((object?)null);
|
||||
|
||||
// Assert - null object doesn't match, returns mismatch
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_IsMatch_With_String_Input_Should_Return_Mismatch()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length > 0;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_IsMatch_Should_Handle_Exception()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => throw new InvalidOperationException("Bytes exception");
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(new byte[] { 1, 2, 3 });
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
result.Exception.Should().NotBeNull();
|
||||
result.Exception.Should().BeOfType<InvalidOperationException>();
|
||||
result.Exception!.Message.Should().Be("Bytes exception");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_With_Contains_Logic_Should_Work()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s?.Contains("foo") == true;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result1 = matcher.IsMatch("foo");
|
||||
var result2 = matcher.IsMatch("foobar");
|
||||
var result3 = matcher.IsMatch("bar");
|
||||
|
||||
// Assert
|
||||
result1.IsPerfect().Should().BeTrue();
|
||||
result2.IsPerfect().Should().BeTrue();
|
||||
result3.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_With_Length_Logic_Should_Work()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length > 2;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result1 = matcher.IsMatch(new byte[] { 1 });
|
||||
var result2 = matcher.IsMatch(new byte[] { 1, 2 });
|
||||
var result3 = matcher.IsMatch(new byte[] { 1, 2, 3 });
|
||||
|
||||
// Assert
|
||||
result1.IsPerfect().Should().BeFalse();
|
||||
result2.IsPerfect().Should().BeFalse();
|
||||
result3.IsPerfect().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_Name_Should_Return_FuncMatcher()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act & Assert
|
||||
matcher.Name.Should().Be("FuncMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_MatchBehaviour_Should_Return_AcceptOnMatch_By_Default()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act & Assert
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_MatchBehaviour_Should_Return_Custom_Value_For_String()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func, MatchBehaviour.RejectOnMatch);
|
||||
|
||||
// Act & Assert
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.RejectOnMatch);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_MatchBehaviour_Should_Return_Custom_Value_For_Bytes()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null;
|
||||
var matcher = new FuncMatcher(func, MatchBehaviour.RejectOnMatch);
|
||||
|
||||
// Act & Assert
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.RejectOnMatch);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_GetCSharpCodeArguments_For_String_Should_Return_Correct_Code()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var code = matcher.GetCSharpCodeArguments();
|
||||
|
||||
// Assert
|
||||
code.Should().Be("new FuncMatcher(/* Func<string?, bool> function */, WireMock.Matchers.MatchBehaviour.AcceptOnMatch)");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_GetCSharpCodeArguments_For_Bytes_Should_Return_Correct_Code()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var code = matcher.GetCSharpCodeArguments();
|
||||
|
||||
// Assert
|
||||
code.Should().Be("new FuncMatcher(/* Func<byte[]?, bool> function */, WireMock.Matchers.MatchBehaviour.AcceptOnMatch)");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_With_RejectOnMatch_For_String_Should_Invert_Result_When_True()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func, MatchBehaviour.RejectOnMatch);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_With_RejectOnMatch_For_String_Should_Invert_Result_When_False()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func, MatchBehaviour.RejectOnMatch);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch("other");
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_With_RejectOnMatch_For_Bytes_Should_Invert_Result_When_True()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length > 0;
|
||||
var matcher = new FuncMatcher(func, MatchBehaviour.RejectOnMatch);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(new byte[] { 1, 2, 3 });
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_With_RejectOnMatch_For_Bytes_Should_Invert_Result_When_False()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length > 0;
|
||||
var matcher = new FuncMatcher(func, MatchBehaviour.RejectOnMatch);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(new byte[0]);
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_IsMatch_With_Integer_Input_Should_Return_Mismatch()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s == "test";
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(42);
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_IsMatch_With_Integer_Input_Should_Return_Mismatch()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result = matcher.IsMatch(42);
|
||||
|
||||
// Assert
|
||||
result.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_With_Empty_String_Should_Work()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => string.IsNullOrEmpty(s);
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result1 = matcher.IsMatch("");
|
||||
var result2 = matcher.IsMatch("test");
|
||||
|
||||
// Assert
|
||||
result1.IsPerfect().Should().BeTrue();
|
||||
result2.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_With_Empty_Array_Should_Work()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length == 0;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result1 = matcher.IsMatch(new byte[0]);
|
||||
var result2 = matcher.IsMatch(new byte[] { 1 });
|
||||
|
||||
// Assert
|
||||
result1.IsPerfect().Should().BeTrue();
|
||||
result2.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_String_With_Complex_Logic_Should_Work()
|
||||
{
|
||||
// Arrange
|
||||
Func<string?, bool> func = s => s != null && s.Length > 3 && s.StartsWith("t") && s.EndsWith("t");
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result1 = matcher.IsMatch("test");
|
||||
var result2 = matcher.IsMatch("tart");
|
||||
var result3 = matcher.IsMatch("tes");
|
||||
var result4 = matcher.IsMatch("best");
|
||||
|
||||
// Assert
|
||||
result1.IsPerfect().Should().BeTrue();
|
||||
result2.IsPerfect().Should().BeTrue();
|
||||
result3.IsPerfect().Should().BeFalse();
|
||||
result4.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FuncMatcher_For_Bytes_With_Specific_Byte_Check_Should_Work()
|
||||
{
|
||||
// Arrange
|
||||
Func<byte[]?, bool> func = b => b != null && b.Length > 0 && b[0] == 0xFF;
|
||||
var matcher = new FuncMatcher(func);
|
||||
|
||||
// Act
|
||||
var result1 = matcher.IsMatch(new byte[] { 0xFF, 0x00 });
|
||||
var result2 = matcher.IsMatch(new byte[] { 0x00, 0xFF });
|
||||
|
||||
// Assert
|
||||
result1.IsPerfect().Should().BeTrue();
|
||||
result2.IsPerfect().Should().BeFalse();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if GRAPHQL
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using GraphQLParser.Exceptions;
|
||||
using WireMock.Exceptions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -232,5 +227,4 @@ public class GraphQLMatcherTests
|
||||
// Assert
|
||||
action.Should().Throw<GraphQLSyntaxErrorException>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -20,7 +18,7 @@ public class JmesPathMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JmesPathMatcher");
|
||||
name.Should().Be("JmesPathMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -33,7 +31,7 @@ public class JmesPathMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
patterns.Should().ContainSingle("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,7 +45,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(bytes).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -60,7 +58,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(null).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -73,7 +71,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(string.Empty).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -87,7 +85,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(o).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +98,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch("").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -113,7 +111,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch("x").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -126,7 +124,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(new { things = new { name = "RequiredThing" } }).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -149,7 +147,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(jobject).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -162,7 +160,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -175,7 +173,7 @@ public class JmesPathMatcherTests
|
||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
match.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -203,4 +201,4 @@ public class JmesPathMatcherTests
|
||||
// Assert
|
||||
score.Should().Be(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -45,7 +41,7 @@ public class JsonMatcherTests
|
||||
var name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonMatcher");
|
||||
name.Should().Be("JsonMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -58,7 +54,7 @@ public class JsonMatcherTests
|
||||
var value = matcher.Value;
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
value.Should().Be("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -108,7 +104,7 @@ public class JsonMatcherTests
|
||||
var match = matcher.IsMatch(bytes).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -122,7 +118,7 @@ public class JsonMatcherTests
|
||||
var match = matcher.IsMatch(s).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -136,7 +132,7 @@ public class JsonMatcherTests
|
||||
var match = matcher.IsMatch(o).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -527,4 +523,4 @@ public class JsonMatcherTests
|
||||
// Assert
|
||||
Assert.Equal(1.0, score);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -23,7 +19,7 @@ public class JsonPartialMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonPartialMatcher");
|
||||
name.Should().Be("JsonPartialMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -36,7 +32,7 @@ public class JsonPartialMatcherTests
|
||||
object value = matcher.Value;
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
value.Should().Be("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -86,7 +82,7 @@ public class JsonPartialMatcherTests
|
||||
double match = matcher.IsMatch(bytes).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +96,7 @@ public class JsonPartialMatcherTests
|
||||
double match = matcher.IsMatch(s).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -114,7 +110,7 @@ public class JsonPartialMatcherTests
|
||||
double match = matcher.IsMatch(o).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -417,7 +413,7 @@ public class JsonPartialMatcherTests
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string? input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
@@ -466,4 +462,4 @@ public class JsonPartialMatcherTests
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -23,7 +19,7 @@ public class JsonPartialWildcardMatcherTests
|
||||
var name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonPartialWildcardMatcher");
|
||||
name.Should().Be("JsonPartialWildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -36,7 +32,7 @@ public class JsonPartialWildcardMatcherTests
|
||||
var value = matcher.Value;
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
value.Should().Be("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -86,7 +82,7 @@ public class JsonPartialWildcardMatcherTests
|
||||
var match = matcher.IsMatch(bytes).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +96,7 @@ public class JsonPartialWildcardMatcherTests
|
||||
var match = matcher.IsMatch(s).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -114,7 +110,7 @@ public class JsonPartialWildcardMatcherTests
|
||||
var match = matcher.IsMatch(o).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -338,7 +334,7 @@ public class JsonPartialWildcardMatcherTests
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||
public void JsonPartialWildcardMatcher_IsMatch_StringInputWithInvalidMatch(string value, string? input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(value);
|
||||
@@ -420,4 +416,4 @@ public class JsonPartialWildcardMatcherTests
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -21,7 +17,7 @@ public class JsonPathMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonPathMatcher");
|
||||
name.Should().Be("JsonPathMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -34,7 +30,7 @@ public class JsonPathMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
patterns.Should().ContainSingle("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -48,7 +44,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(bytes).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +57,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(null).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -74,7 +70,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(string.Empty).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -88,7 +84,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(o).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -101,7 +97,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch("").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -114,7 +110,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch("x").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -127,7 +123,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(new { Id = 1, Name = "Test" }).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -140,7 +136,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(new { things = new { name = "x" } }).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -154,7 +150,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(json).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -168,7 +164,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(json).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
match.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -187,7 +183,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(jobject).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -200,7 +196,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
match.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -213,7 +209,7 @@ public class JsonPathMatcherTests
|
||||
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
match.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -233,7 +229,7 @@ public class JsonPathMatcherTests
|
||||
}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1.0);
|
||||
match.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -255,7 +251,7 @@ public class JsonPathMatcherTests
|
||||
}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1.0);
|
||||
match.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -277,7 +273,7 @@ public class JsonPathMatcherTests
|
||||
}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
match.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -295,7 +291,7 @@ public class JsonPathMatcherTests
|
||||
}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
match.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -313,7 +309,7 @@ public class JsonPathMatcherTests
|
||||
}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0.0);
|
||||
match.Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -337,7 +333,7 @@ public class JsonPathMatcherTests
|
||||
}")).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1.0);
|
||||
match.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -387,4 +383,4 @@ public class JsonPathMatcherTests
|
||||
// Assert
|
||||
match.Should().Be(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -99,7 +99,7 @@ public class LinqMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("LinqMatcher");
|
||||
name.Should().Be("LinqMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -112,6 +112,6 @@ public class LinqMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
patterns.Should().ContainExactly("x");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -11,16 +9,16 @@ public class MatchBehaviourHelperTests
|
||||
[Fact]
|
||||
public void MatchBehaviourHelper_Convert_AcceptOnMatch()
|
||||
{
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0);
|
||||
MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0).Should().Be(0.0);
|
||||
MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5).Should().Be(0.5);
|
||||
MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchBehaviourHelper_Convert_RejectOnMatch()
|
||||
{
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0)).IsEqualTo(1.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5)).IsEqualTo(0.0);
|
||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0)).IsEqualTo(0.0);
|
||||
MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0).Should().Be(1.0);
|
||||
MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5).Should().Be(0.0);
|
||||
MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0).Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if MIMEKIT
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -98,5 +94,4 @@ public class MimePartMatcherTests
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Perfect);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if GRAPHQL
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using WireMock.GraphQL.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers.Models;
|
||||
|
||||
@@ -94,5 +90,4 @@ public class WireMockCustomScalarGraphTypeTests
|
||||
// Assert
|
||||
result.Should().Be("someString");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -17,14 +14,14 @@ public class NotNullOrEmptyMatcherTests
|
||||
var name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("NotNullOrEmptyMatcher");
|
||||
name.Should().Be("NotNullOrEmptyMatcher");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData(new byte[0], 0.0)]
|
||||
[InlineData(new byte[] { 48 }, 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[] data, double expected)
|
||||
public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[]? data, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
@@ -38,7 +35,7 @@ public class NotNullOrEmptyMatcherTests
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_String(string @string, double expected)
|
||||
public void NotNullOrEmptyMatcher_IsMatch_String(string? @string, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
@@ -52,11 +49,11 @@ public class NotNullOrEmptyMatcherTests
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string @string, double expected)
|
||||
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string? @string, double expected)
|
||||
{
|
||||
// Act
|
||||
var matcher = new NotNullOrEmptyMatcher();
|
||||
var result = matcher.IsMatch((object)@string).Score;
|
||||
var result = matcher.IsMatch((object?)@string).Score;
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
@@ -82,4 +79,4 @@ public class NotNullOrEmptyMatcherTests
|
||||
// Assert
|
||||
patterns.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using ProtoBuf;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class ProtoBufMatcherTests
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
private const string MessageType = "greet.HelloRequest";
|
||||
|
||||
private static IdOrTexts ProtoDefinition => new(null, @"
|
||||
@@ -41,7 +38,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType);
|
||||
var result = await matcher.DecodeAsync(bytes).ConfigureAwait(false);
|
||||
var result = await matcher.DecodeAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Should().BeEquivalentTo(new { name = "stef" });
|
||||
@@ -55,7 +52,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType);
|
||||
var result = await matcher.IsMatchAsync(bytes).ConfigureAwait(false);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Perfect);
|
||||
@@ -71,7 +68,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType, matcher: jsonMatcher);
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Perfect);
|
||||
@@ -86,7 +83,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType);
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Mismatch);
|
||||
@@ -101,11 +98,10 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, "greet.Greeter.X");
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Mismatch);
|
||||
result.Exception.Should().BeOfType<ArgumentException>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -20,7 +16,7 @@ public class RegexMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("RegexMatcher");
|
||||
name.Should().Be("RegexMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -33,7 +29,7 @@ public class RegexMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
patterns.Should().ContainSingle("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -44,8 +40,8 @@ public class RegexMatcherTests
|
||||
bool case2 = new RegexMatcher("X", true).IgnoreCase;
|
||||
|
||||
// Assert
|
||||
Check.That(case1).IsFalse();
|
||||
Check.That(case2).IsTrue();
|
||||
case1.Should().BeFalse();
|
||||
case2.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -58,7 +54,7 @@ public class RegexMatcherTests
|
||||
double result = matcher.IsMatch("Hello world!").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0d);
|
||||
result.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -71,7 +67,7 @@ public class RegexMatcherTests
|
||||
double result = matcher.IsMatch(null).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0d);
|
||||
result.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -110,7 +106,7 @@ public class RegexMatcherTests
|
||||
double result = matcher.IsMatch("hello").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0d);
|
||||
result.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -123,6 +119,6 @@ public class RegexMatcherTests
|
||||
double result = matcher.IsMatch("hello").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -18,7 +17,7 @@ public class SimMetricsMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
||||
name.Should().Be("SimMetricsMatcher.Levenstein");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -31,7 +30,7 @@ public class SimMetricsMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
patterns.Should().ContainSingle("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -44,7 +43,7 @@ public class SimMetricsMatcherTests
|
||||
double result = matcher.IsMatch("The car drives in the street.").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||
result.Should().BeLessThan(1.0).And.BeGreaterThan(0.5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -57,7 +56,7 @@ public class SimMetricsMatcherTests
|
||||
double result = matcher.IsMatch("Hello").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||
result.Should().BeLessThan(0.1).And.BeGreaterThan(0.05);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +69,7 @@ public class SimMetricsMatcherTests
|
||||
double result = matcher.IsMatch("test").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -83,6 +82,6 @@ public class SimMetricsMatcherTests
|
||||
double result = matcher.IsMatch("test").Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using AnyOfTypes;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -124,7 +121,7 @@ public class WildcardMatcherTest
|
||||
var name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("WildcardMatcher");
|
||||
name.Should().Be("WildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -137,7 +134,7 @@ public class WildcardMatcherTest
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||
patterns.Should().Equal(new[] { new AnyOf<string, StringPattern>("x") });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -149,6 +146,6 @@ public class WildcardMatcherTest
|
||||
// Act
|
||||
var result = matcher.IsMatch("m").Score;
|
||||
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
@@ -19,7 +17,7 @@ public class XPathMatcherTests
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("XPathMatcher");
|
||||
name.Should().Be("XPathMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -32,7 +30,7 @@ public class XPathMatcherTests
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
patterns.Should().ContainSingle("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -49,7 +47,7 @@ public class XPathMatcherTests
|
||||
double result = matcher.IsMatch(xml).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,7 +79,7 @@ public class XPathMatcherTests
|
||||
double result = matcher.IsMatch(input).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -114,7 +112,7 @@ public class XPathMatcherTests
|
||||
double result = matcher.IsMatch(input).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -131,6 +129,6 @@ public class XPathMatcherTests
|
||||
double result = matcher.IsMatch(xml).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
result.Should().Be(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Logging;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
public class ObservableLogEntriesTest
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_LogEntriesChanged_WithException_Should_LogError()
|
||||
{
|
||||
@@ -45,7 +40,7 @@ public class ObservableLogEntriesTest
|
||||
server.LogEntriesChanged += (sender, args) => throw new Exception();
|
||||
|
||||
// Act
|
||||
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}").ConfigureAwait(false);
|
||||
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}", _ct);
|
||||
|
||||
// Assert
|
||||
loggerMock.Verify(l => l.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
@@ -69,10 +64,10 @@ public class ObservableLogEntriesTest
|
||||
server.LogEntriesChanged += (sender, args) => count++;
|
||||
|
||||
// Act 1a
|
||||
await server.CreateClient().GetAsync(path).ConfigureAwait(false);
|
||||
await server.CreateClient().GetAsync(path, _ct);
|
||||
|
||||
// Act 1b
|
||||
await server.CreateClient().GetAsync(path).ConfigureAwait(false);
|
||||
await server.CreateClient().GetAsync(path, _ct);
|
||||
|
||||
// Assert
|
||||
count.Should().Be(2);
|
||||
@@ -96,13 +91,13 @@ public class ObservableLogEntriesTest
|
||||
|
||||
int count = 0;
|
||||
|
||||
void OnServerOnLogEntriesChanged(object sender, NotifyCollectionChangedEventArgs args) => count++;
|
||||
void OnServerOnLogEntriesChanged(object? sender, NotifyCollectionChangedEventArgs args) => count++;
|
||||
|
||||
// Add Handler
|
||||
server.LogEntriesChanged += OnServerOnLogEntriesChanged;
|
||||
|
||||
// Act 1
|
||||
await server.CreateClient().GetAsync(path).ConfigureAwait(false);
|
||||
await server.CreateClient().GetAsync(path, _ct);
|
||||
|
||||
// Assert 1
|
||||
count.Should().Be(1);
|
||||
@@ -111,7 +106,7 @@ public class ObservableLogEntriesTest
|
||||
server.LogEntriesChanged -= OnServerOnLogEntriesChanged;
|
||||
|
||||
// Act 2
|
||||
await server.CreateClient().GetAsync(path).ConfigureAwait(false);
|
||||
await server.CreateClient().GetAsync(path, _ct);
|
||||
|
||||
// Assert 2
|
||||
count.Should().Be(1);
|
||||
@@ -144,16 +139,16 @@ public class ObservableLogEntriesTest
|
||||
var listOfTasks = new List<Task<HttpResponseMessage>>();
|
||||
for (var i = 0; i < expectedCount; i++)
|
||||
{
|
||||
Thread.Sleep(50);
|
||||
listOfTasks.Add(http.GetAsync($"{server.Urls[0]}{path}"));
|
||||
await Task.Delay(50, _ct);
|
||||
listOfTasks.Add(http.GetAsync($"{server.Urls[0]}{path}", _ct));
|
||||
}
|
||||
var responses = await Task.WhenAll(listOfTasks).ConfigureAwait(false);
|
||||
var responses = await Task.WhenAll(listOfTasks);
|
||||
var countResponsesWithStatusNotOk = responses.Count(r => r.StatusCode != HttpStatusCode.OK);
|
||||
|
||||
// Assert
|
||||
Check.That(countResponsesWithStatusNotOk).Equals(0);
|
||||
Check.That(count).Equals(expectedCount);
|
||||
countResponsesWithStatusNotOk.Should().Be(0);
|
||||
count.Should().Be(expectedCount);
|
||||
|
||||
server.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using FluentAssertions;
|
||||
using WireMock.Net.OpenApiParser.Utils;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.OpenApiParser;
|
||||
|
||||
@@ -36,5 +33,4 @@ public class PathUtilsTests
|
||||
// Assert
|
||||
result.Should().Be("/path1/path2");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,16 +1,9 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using VerifyXunit;
|
||||
using WireMock.Net.OpenApiParser;
|
||||
using WireMock.Net.OpenApiParser.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.OpenApiParser;
|
||||
|
||||
[UsesVerify]
|
||||
public class WireMockOpenApiParserTests
|
||||
{
|
||||
private readonly DateTime _exampleDateTime = new(2024, 6, 19, 12, 34, 56, DateTimeKind.Utc);
|
||||
@@ -40,13 +33,13 @@ public class WireMockOpenApiParserTests
|
||||
ExampleValues = _exampleValuesMock.Object
|
||||
};
|
||||
|
||||
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "payroc-openapi-spec.yaml"));
|
||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "payroc-openapi-spec.yaml"));
|
||||
|
||||
// Act
|
||||
var mappings = _sut.FromText(openApiDocument, settings, out _);
|
||||
|
||||
// Verify
|
||||
await Verifier.Verify(mappings);
|
||||
await Verify(mappings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -58,13 +51,12 @@ public class WireMockOpenApiParserTests
|
||||
ExampleValues = _exampleValuesMock.Object
|
||||
};
|
||||
|
||||
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "oas-content-example.json"));
|
||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "oas-content-example.json"));
|
||||
|
||||
// Act
|
||||
var mappings = _sut.FromText(openApiDocument, settings, out _);
|
||||
|
||||
// Verify
|
||||
await Verifier.Verify(mappings);
|
||||
await Verify(mappings);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using WireMock.OpenTelemetry;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.OpenTelemetry;
|
||||
|
||||
@@ -14,12 +10,12 @@ public class OpenTelemetryOptionsParserTests
|
||||
public void TryParseArguments_Enabled_ShouldReturnOptions()
|
||||
{
|
||||
// Act
|
||||
var result = OpenTelemetryOptionsParser.TryParseArguments(new[]
|
||||
{
|
||||
var result = OpenTelemetryOptionsParser.TryParseArguments(
|
||||
[
|
||||
"--OpenTelemetryEnabled", "true",
|
||||
"--OpenTelemetryExcludeAdminRequests", "false",
|
||||
"--OpenTelemetryOtlpExporterEndpoint", "http://localhost:4317"
|
||||
}, null, out var options);
|
||||
], null, out var options);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
@@ -38,5 +34,4 @@ public class OpenTelemetryOptionsParserTests
|
||||
result.Should().BeTrue();
|
||||
options.Should().BeNull();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using FluentAssertions;
|
||||
using AwesomeAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WireMock.OpenTelemetry;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.OpenTelemetry;
|
||||
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Net.WebSockets;
|
||||
using Moq;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin.ActivityTracing;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
using WireMock.WebSockets;
|
||||
|
||||
namespace WireMock.Net.Tests.Owin.ActivityTracing;
|
||||
|
||||
public class WireMockActivitySourceTests
|
||||
public class WireMockActivitySourceTests : IDisposable
|
||||
{
|
||||
private readonly ActivityListener _activityListener;
|
||||
|
||||
public WireMockActivitySourceTests()
|
||||
{
|
||||
// Set up ActivityListener for tests
|
||||
_activityListener = new ActivityListener
|
||||
{
|
||||
ShouldListenTo = source => source.Name == WireMockActivitySource.SourceName,
|
||||
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData
|
||||
};
|
||||
|
||||
ActivitySource.AddActivityListener(_activityListener);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_activityListener?.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithRequest_ShouldSetRequestTagsAndBody_WhenEnabled()
|
||||
{
|
||||
@@ -66,7 +83,7 @@ public class WireMockActivitySourceTests
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.HttpStatusCode).Should().Be(200);
|
||||
activity.GetTagItem("otel.status_code").Should().Be("OK");
|
||||
activity.GetTagItem(WireMockSemanticConventions.OtelStatusCode).Should().Be("OK");
|
||||
activity.GetTagItem(WireMockSemanticConventions.ResponseBody).Should().Be("ok");
|
||||
}
|
||||
|
||||
@@ -85,7 +102,7 @@ public class WireMockActivitySourceTests
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.HttpStatusCode).Should().Be(500);
|
||||
activity.GetTagItem("otel.status_code").Should().Be("ERROR");
|
||||
activity.GetTagItem(WireMockSemanticConventions.OtelStatusCode).Should().Be("ERROR");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -179,17 +196,264 @@ public class WireMockActivitySourceTests
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
var exception = new InvalidOperationException("boom");
|
||||
var exception = new InvalidOperationException("Yes, Rico; Kaboom.");
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.RecordException(activity, exception);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem("otel.status_code").Should().Be("ERROR");
|
||||
activity.GetTagItem("otel.status_description").Should().Be("boom");
|
||||
activity.GetTagItem(WireMockSemanticConventions.OtelStatusCode).Should().Be("ERROR");
|
||||
activity.GetTagItem("otel.status_description").Should().Be("Yes, Rico; Kaboom.");
|
||||
activity.GetTagItem("exception.type").Should().Be(typeof(InvalidOperationException).FullName);
|
||||
activity.GetTagItem("exception.message").Should().Be("boom");
|
||||
activity.GetTagItem("exception.message").Should().Be("Yes, Rico; Kaboom.");
|
||||
activity.GetTagItem("exception.stacktrace").Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public void StartRequestActivity_ShouldCreateActivity_WithCorrectDisplayName()
|
||||
{
|
||||
// Arrange
|
||||
var requestMethod = "POST";
|
||||
var requestPath = "/api/users";
|
||||
|
||||
// Act
|
||||
using var activity = WireMockActivitySource.StartRequestActivity(requestMethod, requestPath);
|
||||
|
||||
// Assert
|
||||
activity.Should().NotBeNull();
|
||||
activity.DisplayName.Should().Be("WireMock POST /api/users");
|
||||
activity.Kind.Should().Be(ActivityKind.Server);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartWebSocketMessageActivity_ShouldCreateActivity_WithCorrectName()
|
||||
{
|
||||
// Arrange
|
||||
var mappingGuid = Guid.NewGuid();
|
||||
var direction = WebSocketMessageDirection.Receive;
|
||||
|
||||
// Act
|
||||
using var activity = WireMockActivitySource.StartWebSocketMessageActivity(direction, mappingGuid);
|
||||
|
||||
// Assert
|
||||
activity.Should().NotBeNull();
|
||||
activity.DisplayName.Should().Be("WireMock WebSocket receive");
|
||||
activity.Kind.Should().Be(ActivityKind.Server);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartWebSocketMessageActivity_ShouldSetMappingGuidTag()
|
||||
{
|
||||
// Arrange
|
||||
var mappingGuid = Guid.NewGuid();
|
||||
var direction = WebSocketMessageDirection.Send;
|
||||
|
||||
// Act
|
||||
using var activity = WireMockActivitySource.StartWebSocketMessageActivity(direction, mappingGuid);
|
||||
|
||||
// Assert
|
||||
activity.Should().NotBeNull();
|
||||
activity.GetTagItem(WireMockSemanticConventions.MappingGuid).Should().Be(mappingGuid.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartWebSocketMessageActivity_ShouldCreateActivityForSendDirection()
|
||||
{
|
||||
// Arrange
|
||||
var mappingGuid = Guid.NewGuid();
|
||||
var direction = WebSocketMessageDirection.Send;
|
||||
|
||||
// Act
|
||||
using var activity = WireMockActivitySource.StartWebSocketMessageActivity(direction, mappingGuid);
|
||||
|
||||
// Assert
|
||||
activity.Should().NotBeNull();
|
||||
activity.DisplayName.Should().Be("WireMock WebSocket send");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartWebSocketMessageActivity_ShouldCreateActivityWithListenerConfigured()
|
||||
{
|
||||
// Arrange
|
||||
var mappingGuid = Guid.NewGuid();
|
||||
var direction = WebSocketMessageDirection.Receive;
|
||||
|
||||
// Act - ActivityListener is configured in test constructor
|
||||
using var activity = WireMockActivitySource.StartWebSocketMessageActivity(direction, mappingGuid);
|
||||
|
||||
// Assert - activity should be created since listener is active
|
||||
activity.Should().NotBeNull();
|
||||
activity.DisplayName.Should().Be("WireMock WebSocket receive");
|
||||
activity.GetTagItem(WireMockSemanticConventions.MappingGuid).Should().Be(mappingGuid.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldSetMessageTypeTag()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
var messageType = WebSocketMessageType.Text;
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
messageType,
|
||||
messageSize: 100,
|
||||
endOfMessage: true
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageType).Should().Be("Text");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldSetMessageSizeTag()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Binary,
|
||||
messageSize: 256,
|
||||
endOfMessage: true
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageSize).Should().Be(256);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldSetEndOfMessageTag()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Text,
|
||||
messageSize: 50,
|
||||
endOfMessage: false
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketEndOfMessage).Should().Be(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldSetOkStatus()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Text,
|
||||
messageSize: 100,
|
||||
endOfMessage: true
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.OtelStatusCode).Should().Be("OK");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldRecordTextContent_WhenEnabled()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
var options = new ActivityTracingOptions { RecordRequestBody = true };
|
||||
var textContent = "Hello WebSocket";
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Text,
|
||||
messageSize: textContent.Length,
|
||||
endOfMessage: true,
|
||||
textContent: textContent,
|
||||
options: options
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageContent).Should().Be(textContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldNotRecordTextContent_WhenDisabled()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
var options = new ActivityTracingOptions { RecordRequestBody = false };
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Text,
|
||||
messageSize: 100,
|
||||
endOfMessage: true,
|
||||
textContent: "Hello WebSocket",
|
||||
options: options
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageContent).Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldNotRecordBinaryContent()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
var options = new ActivityTracingOptions { RecordRequestBody = true };
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Binary,
|
||||
messageSize: 100,
|
||||
endOfMessage: true,
|
||||
textContent: "should not record",
|
||||
options: options
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageContent).Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldHandleNullActivity()
|
||||
{
|
||||
// Arrange & Act - should not throw
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
null,
|
||||
WebSocketMessageType.Text,
|
||||
messageSize: 100,
|
||||
endOfMessage: true
|
||||
);
|
||||
|
||||
// Assert - no exception thrown
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnrichWithWebSocketMessage_ShouldHandleClosedMessageType()
|
||||
{
|
||||
// Arrange
|
||||
using var activity = new Activity("test").Start();
|
||||
|
||||
// Act
|
||||
WireMockActivitySource.EnrichWithWebSocketMessage(
|
||||
activity,
|
||||
WebSocketMessageType.Close,
|
||||
messageSize: 0,
|
||||
endOfMessage: true
|
||||
);
|
||||
|
||||
// Assert
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageType).Should().Be("Close");
|
||||
activity.GetTagItem(WireMockSemanticConventions.WebSocketMessageSize).Should().Be(0);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,49 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Owin.Mappers;
|
||||
using Xunit;
|
||||
#if NET452
|
||||
using IContext = Microsoft.Owin.IOwinContext;
|
||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
||||
#else
|
||||
using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
||||
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Net.Tests.Owin
|
||||
namespace WireMock.Net.Tests.Owin;
|
||||
|
||||
public class GlobalExceptionMiddlewareTests
|
||||
{
|
||||
public class GlobalExceptionMiddlewareTests
|
||||
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
|
||||
private readonly Mock<IOwinResponseMapper> _responseMapperMock;
|
||||
|
||||
private readonly GlobalExceptionMiddleware _sut;
|
||||
|
||||
public GlobalExceptionMiddlewareTests()
|
||||
{
|
||||
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
|
||||
private readonly Mock<IOwinResponseMapper> _responseMapperMock;
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupGet(o => o.Logger).Returns(Mock.Of<IWireMockLogger>());
|
||||
|
||||
private readonly GlobalExceptionMiddleware _sut;
|
||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
||||
|
||||
public GlobalExceptionMiddlewareTests()
|
||||
{
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
_sut = new GlobalExceptionMiddleware(_ => Task.CompletedTask, _optionsMock.Object, _responseMapperMock.Object);
|
||||
}
|
||||
|
||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||
_responseMapperMock.SetupAllProperties();
|
||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<IResponse>())).Returns(Task.FromResult(true));
|
||||
[Fact]
|
||||
public void GlobalExceptionMiddleware_Invoke_ValidNext_ShouldNotThrow()
|
||||
{
|
||||
// Act
|
||||
_sut.Invoke(Mock.Of<HttpContext>());
|
||||
}
|
||||
|
||||
_sut = new GlobalExceptionMiddleware(null, _optionsMock.Object, _responseMapperMock.Object);
|
||||
}
|
||||
[Fact]
|
||||
public void GlobalExceptionMiddleware_Invoke_InvalidNext_ShouldCallResponseMapperWith500()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new GlobalExceptionMiddleware(_ => throw new ArgumentException(), _optionsMock.Object, _responseMapperMock.Object);
|
||||
|
||||
[Fact]
|
||||
public void GlobalExceptionMiddleware_Invoke_NullAsNext_DoesNotInvokeNextAndDoesNotThrow()
|
||||
{
|
||||
// Act
|
||||
Check.ThatAsyncCode(() => _sut.Invoke(null)).DoesNotThrow();
|
||||
}
|
||||
// Act
|
||||
sut.Invoke(Mock.Of<HttpContext>());
|
||||
|
||||
// Verify
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.IsAny<ResponseMessage>(), It.IsAny<HttpResponse>()), Times.Once);
|
||||
_responseMapperMock.VerifyNoOtherCalls();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Owin;
|
||||
|
||||
|
||||
@@ -1,29 +1,14 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Owin;
|
||||
#if NET452
|
||||
using Microsoft.Owin;
|
||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
||||
// using Response = Microsoft.Owin.OwinResponse;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
||||
// using Response = Microsoft.AspNetCore.Http.HttpResponse;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Net.Tests.Owin.Mappers;
|
||||
|
||||
@@ -31,7 +16,7 @@ public class OwinResponseMapperTests
|
||||
{
|
||||
private static readonly Task CompletedTask = Task.FromResult(true);
|
||||
private readonly OwinResponseMapper _sut;
|
||||
private readonly Mock<IResponse> _responseMock;
|
||||
private readonly Mock<HttpResponse> _responseMock;
|
||||
private readonly Mock<Stream> _stream;
|
||||
private readonly Mock<IHeaderDictionary> _headers;
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock;
|
||||
@@ -58,7 +43,7 @@ public class OwinResponseMapperTests
|
||||
_headers.Setup(h => h.Add(It.IsAny<string>(), It.IsAny<StringValues>()));
|
||||
#endif
|
||||
|
||||
_responseMock = new Mock<IResponse>();
|
||||
_responseMock = new Mock<HttpResponse>();
|
||||
_responseMock.SetupAllProperties();
|
||||
_responseMock.SetupGet(r => r.Body).Returns(_stream.Object);
|
||||
_responseMock.SetupGet(r => r.Headers).Returns(_headers.Object);
|
||||
@@ -70,7 +55,7 @@ public class OwinResponseMapperTests
|
||||
public async Task OwinResponseMapper_MapAsync_Null()
|
||||
{
|
||||
// Act
|
||||
await _sut.MapAsync(null, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(null, _responseMock.Object);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -85,7 +70,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
@@ -106,7 +91,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
@@ -122,7 +107,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = It.IsAny<int>(), Times.Never);
|
||||
@@ -142,7 +127,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
@@ -158,7 +143,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()), Times.Never);
|
||||
@@ -176,7 +161,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 97, 98, 99, 100 }, 0, 4, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -194,7 +179,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(bytes, 0, bytes.Length, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -212,7 +197,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 123, 34, 116, 34, 58, 34, 120, 34, 125 }, 0, 9, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -228,7 +213,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
#if NET452
|
||||
@@ -270,7 +255,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[0], 0, 0, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -280,7 +265,7 @@ public class OwinResponseMapperTests
|
||||
[InlineData("abcd", BodyType.String)]
|
||||
[InlineData("", BodyType.String)]
|
||||
[InlineData(null, BodyType.None)]
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_MALFORMED_RESPONSE_CHUNK(string body, BodyType detected)
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_MALFORMED_RESPONSE_CHUNK(string? body, BodyType detected)
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
@@ -292,7 +277,7 @@ public class OwinResponseMapperTests
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = 100, Times.Once);
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Owin;
|
||||
|
||||
|
||||
@@ -1,49 +1,31 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.Util;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using System.Collections.Generic;
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.Diagnostics;
|
||||
#endif
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Requests;
|
||||
using WireMock.Settings;
|
||||
using FluentAssertions;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.RequestBuilders;
|
||||
#if NET6_0_OR_GREATER
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Owin.ActivityTracing;
|
||||
#endif
|
||||
#if NET452
|
||||
using Microsoft.Owin;
|
||||
using IContext = Microsoft.Owin.IOwinContext;
|
||||
using IRequest = Microsoft.Owin.IOwinRequest;
|
||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
||||
using IRequest = Microsoft.AspNetCore.Http.HttpRequest;
|
||||
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
||||
#endif
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Net.Tests.Owin;
|
||||
|
||||
public class WireMockMiddlewareTests
|
||||
{
|
||||
private static readonly Guid NewGuid = new("98fae52e-76df-47d9-876f-2ee32e931d9b");
|
||||
private static readonly DateTime UtcNow = new(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime UpdatedAt = new(2022, 12, 4);
|
||||
|
||||
private readonly ConcurrentDictionary<Guid, IMapping> _mappings = new();
|
||||
@@ -53,14 +35,21 @@ public class WireMockMiddlewareTests
|
||||
private readonly Mock<IMappingMatcher> _matcherMock;
|
||||
private readonly Mock<IMapping> _mappingMock;
|
||||
private readonly Mock<IRequestMatchResult> _requestMatchResultMock;
|
||||
private readonly Mock<IContext> _contextMock;
|
||||
private readonly Mock<HttpContext> _contextMock;
|
||||
private readonly Mock<IGuidUtils> _guidUtilsMock;
|
||||
private readonly Mock<IDateTimeUtils> _dateTimeUtilsMock;
|
||||
|
||||
private readonly WireMockMiddleware _sut;
|
||||
|
||||
public WireMockMiddlewareTests()
|
||||
{
|
||||
var guidUtilsMock = new Mock<IGuidUtils>();
|
||||
guidUtilsMock.Setup(g => g.NewGuid()).Returns(NewGuid);
|
||||
var wireMockMiddlewareLoggerMock = new Mock<IWireMockMiddlewareLogger>();
|
||||
|
||||
_guidUtilsMock = new Mock<IGuidUtils>();
|
||||
_guidUtilsMock.Setup(g => g.NewGuid()).Returns(NewGuid);
|
||||
|
||||
_dateTimeUtilsMock = new Mock<IDateTimeUtils>();
|
||||
_dateTimeUtilsMock.Setup(d => d.UtcNow).Returns(UtcNow);
|
||||
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
@@ -74,31 +63,34 @@ public class WireMockMiddlewareTests
|
||||
_requestMapperMock = new Mock<IOwinRequestMapper>();
|
||||
_requestMapperMock.SetupAllProperties();
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1");
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||
_responseMapperMock.SetupAllProperties();
|
||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<IResponse>())).Returns(Task.FromResult(true));
|
||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
||||
|
||||
_matcherMock = new Mock<IMappingMatcher>();
|
||||
_matcherMock.SetupAllProperties();
|
||||
// _matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((new MappingMatcherResult(), new MappingMatcherResult()));
|
||||
|
||||
_contextMock = new Mock<IContext>();
|
||||
_contextMock = new Mock<HttpContext>();
|
||||
_contextMock.SetupGet(c => c.Items).Returns(new Dictionary<object, object?>());
|
||||
|
||||
_mappingMock = new Mock<IMapping>();
|
||||
|
||||
_requestMatchResultMock = new Mock<IRequestMatchResult>();
|
||||
_requestMatchResultMock.Setup(r => r.TotalNumber).Returns(1);
|
||||
_requestMatchResultMock.Setup(r => r.MatchDetails).Returns(new List<MatchDetail>());
|
||||
_requestMatchResultMock.Setup(r => r.MatchDetails).Returns([]);
|
||||
|
||||
_sut = new WireMockMiddleware(
|
||||
null,
|
||||
_ => Task.CompletedTask,
|
||||
_optionsMock.Object,
|
||||
_requestMapperMock.Object,
|
||||
_responseMapperMock.Object,
|
||||
_matcherMock.Object,
|
||||
guidUtilsMock.Object
|
||||
wireMockMiddlewareLoggerMock.Object,
|
||||
_guidUtilsMock.Object,
|
||||
_dateTimeUtilsMock.Object
|
||||
);
|
||||
}
|
||||
|
||||
@@ -106,35 +98,13 @@ public class WireMockMiddlewareTests
|
||||
public async Task WireMockMiddleware_Invoke_NoMatch()
|
||||
{
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert and Verify
|
||||
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
|
||||
Expression<Func<ResponseMessage, bool>> match = r => (int)r.StatusCode! == 404 && ((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found";
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockMiddleware_Invoke_NoMatch_When_SaveUnmatchedRequestsIsTrue_Should_Call_LocalFileSystemHandler_WriteUnmatchedRequest()
|
||||
{
|
||||
// Arrange
|
||||
var fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
_optionsMock.Setup(o => o.FileSystemHandler).Returns(fileSystemHandlerMock.Object);
|
||||
_optionsMock.Setup(o => o.SaveUnmatchedRequests).Returns(true);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
|
||||
Expression<Func<ResponseMessage, bool>> match = r => (int)r.StatusCode! == 404 && ((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found";
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
||||
|
||||
// Verify
|
||||
fileSystemHandlerMock.Verify(f => f.WriteUnmatchedRequest("98fae52e-76df-47d9-876f-2ee32e931d9b.LogEntry.json", It.IsAny<string>()));
|
||||
fileSystemHandlerMock.VerifyNoOtherCalls();
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -142,7 +112,7 @@ public class WireMockMiddlewareTests
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1", null, new Dictionary<string, string[]>());
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.AuthenticationMatcher).Returns(new ExactMatcher());
|
||||
_mappingMock.SetupGet(m => m.IsAdminInterface).Returns(true);
|
||||
@@ -151,13 +121,13 @@ public class WireMockMiddlewareTests
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert and Verify
|
||||
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
|
||||
Expression<Func<ResponseMessage, bool>> match = r => (int?)r.StatusCode == 401;
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -165,7 +135,7 @@ public class WireMockMiddlewareTests
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1", null, new Dictionary<string, string[]> { { "h", new[] { "x" } } });
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.AuthenticationMatcher).Returns(new ExactMatcher());
|
||||
_mappingMock.SetupGet(m => m.IsAdminInterface).Returns(true);
|
||||
@@ -174,13 +144,13 @@ public class WireMockMiddlewareTests
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert and Verify
|
||||
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
|
||||
Expression<Func<ResponseMessage, bool>> match = r => (int?)r.StatusCode == 401;
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -190,7 +160,7 @@ public class WireMockMiddlewareTests
|
||||
_optionsMock.SetupGet(o => o.RequestLogExpirationDuration).Returns(1);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -198,7 +168,7 @@ public class WireMockMiddlewareTests
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1", null, new Dictionary<string, string[]>());
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.AuthenticationMatcher).Returns(new ExactMatcher());
|
||||
|
||||
@@ -225,7 +195,7 @@ public class WireMockMiddlewareTests
|
||||
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
||||
|
||||
var newMappingFromProxy = new Mapping(NewGuid, UpdatedAt, string.Empty, string.Empty, null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, false, null, null);
|
||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<HttpContext>(), It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||
|
||||
var requestBuilder = Request.Create().UsingAnyMethod();
|
||||
_mappingMock.SetupGet(m => m.RequestMatcher).Returns(requestBuilder);
|
||||
@@ -234,7 +204,7 @@ public class WireMockMiddlewareTests
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert and Verify
|
||||
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -247,7 +217,7 @@ public class WireMockMiddlewareTests
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1", null, new Dictionary<string, string[]>());
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.AuthenticationMatcher).Returns(new ExactMatcher());
|
||||
|
||||
@@ -279,16 +249,16 @@ public class WireMockMiddlewareTests
|
||||
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
||||
|
||||
var newMappingFromProxy = new Mapping(NewGuid, UpdatedAt, "my-title", "my-description", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, false, null, data: null);
|
||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<HttpContext>(), It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||
|
||||
var requestBuilder = Request.Create().UsingAnyMethod();
|
||||
_mappingMock.SetupGet(m => m.RequestMatcher).Returns(requestBuilder);
|
||||
|
||||
var result = new MappingMatcherResult (_mappingMock.Object, _requestMatchResultMock.Object);
|
||||
var result = new MappingMatcherResult(_mappingMock.Object, _requestMatchResultMock.Object);
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert and Verify
|
||||
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -296,15 +266,14 @@ public class WireMockMiddlewareTests
|
||||
_mappings.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
[Fact]
|
||||
public async Task WireMockMiddleware_Invoke_AdminPath_WithExcludeAdminRequests_ShouldNotStartActivity()
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/__admin/health"), "GET", "::1");
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.ActivityTracingOptions).Returns(new WireMock.Owin.ActivityTracing.ActivityTracingOptions
|
||||
_optionsMock.SetupGet(o => o.ActivityTracingOptions).Returns(new ActivityTracingOptions
|
||||
{
|
||||
ExcludeAdminRequests = true
|
||||
});
|
||||
@@ -320,7 +289,7 @@ public class WireMockMiddlewareTests
|
||||
ActivitySource.AddActivityListener(listener);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert
|
||||
activityStarted.Should().BeFalse();
|
||||
@@ -331,9 +300,9 @@ public class WireMockMiddlewareTests
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/api/orders"), "GET", "::1");
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.ActivityTracingOptions).Returns(new WireMock.Owin.ActivityTracing.ActivityTracingOptions
|
||||
_optionsMock.SetupGet(o => o.ActivityTracingOptions).Returns(new ActivityTracingOptions
|
||||
{
|
||||
ExcludeAdminRequests = true
|
||||
});
|
||||
@@ -349,7 +318,7 @@ public class WireMockMiddlewareTests
|
||||
ActivitySource.AddActivityListener(listener);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert
|
||||
activityStarted.Should().BeTrue();
|
||||
@@ -360,9 +329,9 @@ public class WireMockMiddlewareTests
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/api/orders"), "GET", "::1");
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<IRequest>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
_requestMapperMock.Setup(m => m.MapAsync(It.IsAny<HttpContext>(), It.IsAny<IWireMockMiddlewareOptions>())).ReturnsAsync(request);
|
||||
|
||||
_optionsMock.SetupGet(o => o.ActivityTracingOptions).Returns((WireMock.Owin.ActivityTracing.ActivityTracingOptions?)null);
|
||||
_optionsMock.SetupGet(o => o.ActivityTracingOptions).Returns((ActivityTracingOptions?)null);
|
||||
|
||||
var activityStarted = false;
|
||||
using var listener = new ActivityListener
|
||||
@@ -375,10 +344,9 @@ public class WireMockMiddlewareTests
|
||||
ActivitySource.AddActivityListener(listener);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
// Assert
|
||||
activityStarted.Should().BeFalse();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,23 +1,16 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using VerifyXunit;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Pact;
|
||||
|
||||
[UsesVerify]
|
||||
public class PactTests
|
||||
{
|
||||
[Fact]
|
||||
@@ -56,7 +49,7 @@ public class PactTests
|
||||
server.SavePact(folder, file);
|
||||
|
||||
// Assert
|
||||
await Verifier.VerifyFile(path);
|
||||
await VerifyFile(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,7 +70,7 @@ public class PactTests
|
||||
server.SavePact(folder, file);
|
||||
|
||||
// Assert
|
||||
await Verifier.VerifyFile(path);
|
||||
await VerifyFile(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -245,5 +238,4 @@ public class PactTests
|
||||
// Assert
|
||||
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using WireMock.Handlers;
|
||||
using WireMock.Proxy;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Proxy;
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.RegularExpressions;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RegularExpressions;
|
||||
|
||||
@@ -25,10 +23,10 @@ public class RegexExtendedTests
|
||||
var regexLower = new RegexExtended(guidbLower);
|
||||
var regexUpper = new RegexExtended(guidbUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
regexLower.IsMatch(inputLower).Should().Be(true);
|
||||
regexLower.IsMatch(inputUpper).Should().Be(false);
|
||||
regexUpper.IsMatch(inputUpper).Should().Be(true);
|
||||
regexUpper.IsMatch(inputLower).Should().Be(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -42,10 +40,10 @@ public class RegexExtendedTests
|
||||
var regexLower = new RegexExtended(guiddLower);
|
||||
var regexUpper = new RegexExtended(guiddUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
regexLower.IsMatch(inputLower).Should().Be(true);
|
||||
regexLower.IsMatch(inputUpper).Should().Be(false);
|
||||
regexUpper.IsMatch(inputUpper).Should().Be(true);
|
||||
regexUpper.IsMatch(inputLower).Should().Be(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,10 +57,10 @@ public class RegexExtendedTests
|
||||
var regexLower = new RegexExtended(guidnLower);
|
||||
var regexUpper = new RegexExtended(guidnUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
regexLower.IsMatch(inputLower).Should().Be(true);
|
||||
regexLower.IsMatch(inputUpper).Should().Be(false);
|
||||
regexUpper.IsMatch(inputUpper).Should().Be(true);
|
||||
regexUpper.IsMatch(inputLower).Should().Be(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -76,10 +74,10 @@ public class RegexExtendedTests
|
||||
var regexLower = new RegexExtended(guidpLower);
|
||||
var regexUpper = new RegexExtended(guidpUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
regexLower.IsMatch(inputLower).Should().Be(true);
|
||||
regexLower.IsMatch(inputUpper).Should().Be(false);
|
||||
regexUpper.IsMatch(inputUpper).Should().Be(true);
|
||||
regexUpper.IsMatch(inputLower).Should().Be(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,9 +91,9 @@ public class RegexExtendedTests
|
||||
var regexLower = new RegexExtended(guidxLower);
|
||||
var regexUpper = new RegexExtended(guidxUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
regexLower.IsMatch(inputLower).Should().Be(true);
|
||||
regexLower.IsMatch(inputUpper).Should().Be(false);
|
||||
regexUpper.IsMatch(inputUpper).Should().Be(true);
|
||||
regexUpper.IsMatch(inputLower).Should().Be(false);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -27,7 +25,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -46,7 +44,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,7 +63,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -84,7 +82,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -103,7 +101,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -122,7 +120,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -141,7 +139,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -160,7 +158,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -179,7 +177,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -198,7 +196,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -212,7 +210,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -230,7 +228,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -244,7 +242,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -258,6 +256,7 @@ public class RequestBuilderTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -18,8 +16,8 @@ public class RequestBuilderUsingMethodTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("CONNECT");
|
||||
matchers.Count.Should().Be(1);
|
||||
(matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("CONNECT");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -30,8 +28,8 @@ public class RequestBuilderUsingMethodTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("OPTIONS");
|
||||
matchers.Count.Should().Be(1);
|
||||
(matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("OPTIONS");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -42,8 +40,8 @@ public class RequestBuilderUsingMethodTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
||||
matchers.Count.Should().Be(1);
|
||||
(matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("PATCH");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -54,8 +52,8 @@ public class RequestBuilderUsingMethodTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("TRACE");
|
||||
matchers.Count.Should().Be(1);
|
||||
(matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("TRACE");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,14 +64,14 @@ public class RequestBuilderUsingMethodTests
|
||||
|
||||
// Assert 1
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageMethodMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageMethodMatcher>();
|
||||
|
||||
// Act
|
||||
requestBuilder.UsingAnyMethod();
|
||||
|
||||
// Assert 2
|
||||
matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(0);
|
||||
matchers.Count.Should().Be(0);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -69,7 +64,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -90,7 +85,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -113,7 +108,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(expected);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -134,7 +129,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(0.0);
|
||||
}
|
||||
|
||||
private class FuncType
|
||||
@@ -161,7 +156,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -180,7 +175,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -199,7 +194,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -218,7 +213,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -281,7 +276,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -305,7 +300,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -324,7 +319,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -343,7 +338,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -366,7 +361,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -389,7 +384,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -413,7 +408,7 @@ public class RequestBuilderWithBodyTests
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
double result = spec.GetMatchingScore(request, requestMatchResult);
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -434,7 +429,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -458,7 +453,7 @@ public class RequestBuilderWithBodyTests
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -484,4 +479,5 @@ public class RequestBuilderWithBodyTests
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
requestBuilder.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -22,7 +20,7 @@ public class RequestBuilderWithClientIPTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -36,7 +34,7 @@ public class RequestBuilderWithClientIPTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,7 +48,7 @@ public class RequestBuilderWithClientIPTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -64,6 +62,6 @@ public class RequestBuilderWithClientIPTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -19,8 +16,8 @@ public class RequestBuilderWithCookieTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageCookieMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -31,8 +28,8 @@ public class RequestBuilderWithCookieTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageCookieMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,7 +40,7 @@ public class RequestBuilderWithCookieTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageCookieMatcher>();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if GRAPHQL
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using GraphQL.Types;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -69,5 +65,4 @@ public class RequestBuilderWithGraphQLSchemaTests
|
||||
matchers.Should().HaveCount(1);
|
||||
((RequestMessageGraphQLMatcher)matchers[0]).Matchers.Should().ContainItemsAssignableTo<GraphQLMatcher>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -19,8 +17,8 @@ public class RequestBuilderWithHeaderTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageHeaderMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -31,8 +29,8 @@ public class RequestBuilderWithHeaderTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageHeaderMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,8 +41,8 @@ public class RequestBuilderWithHeaderTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageHeaderMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,8 +53,8 @@ public class RequestBuilderWithHeaderTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageHeaderMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -67,8 +65,8 @@ public class RequestBuilderWithHeaderTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageHeaderMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -79,7 +77,7 @@ public class RequestBuilderWithHeaderTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageHeaderMatcher>();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#if MIMEKIT
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using AwesomeAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -19,8 +16,8 @@ public class RequestBuilderWithParamTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageParamMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -31,8 +28,8 @@ public class RequestBuilderWithParamTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageParamMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,8 +40,8 @@ public class RequestBuilderWithParamTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageParamMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,7 +52,7 @@ public class RequestBuilderWithParamTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageParamMatcher>();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
@@ -27,7 +25,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,7 +43,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,7 +57,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -71,8 +69,8 @@ public class RequestBuilderWithPathTests
|
||||
var request2 = new RequestMessage(new UrlDetails("http://localhost/x2"), "blabla", ClientIp);
|
||||
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request1, requestMatchResult)).IsEqualTo(1.0);
|
||||
Check.That(requestBuilder.GetMatchingScore(request2, requestMatchResult)).IsEqualTo(1.0);
|
||||
requestBuilder.GetMatchingScore(request1, requestMatchResult).Should().Be(1.0);
|
||||
requestBuilder.GetMatchingScore(request2, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -86,7 +84,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +98,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -114,7 +112,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -133,7 +131,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -151,7 +149,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -165,7 +163,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -179,7 +177,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -193,7 +191,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -207,7 +205,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -221,7 +219,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -235,6 +233,7 @@ public class RequestBuilderWithPathTests
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
spec.GetMatchingScore(request, requestMatchResult).Should().NotBe(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -63,5 +59,4 @@ message HelloReply {
|
||||
protoBufMatcher.MessageType.Should().Be(MessageType);
|
||||
protoBufMatcher.Matcher.Should().BeOfType<JsonMatcher>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestBuilders;
|
||||
|
||||
@@ -19,8 +16,8 @@ public class RequestBuilderWithUrlTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageUrlMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -31,8 +28,8 @@ public class RequestBuilderWithUrlTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageUrlMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,8 +40,8 @@ public class RequestBuilderWithUrlTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageUrlMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,7 +52,7 @@ public class RequestBuilderWithUrlTests
|
||||
|
||||
// Assert
|
||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||
Check.That(matchers.Count).IsEqualTo(1);
|
||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||
matchers.Count.Should().Be(1);
|
||||
matchers[0].Should().BeOfType<RequestMessageUrlMatcher>();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,13 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
@@ -40,7 +34,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1d);
|
||||
score.Should().Be(1d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
|
||||
@@ -77,7 +71,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(expected);
|
||||
score.Should().Be(expected);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
|
||||
@@ -118,7 +112,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(expected);
|
||||
score.Should().Be(expected);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
|
||||
@@ -159,7 +153,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(expected);
|
||||
score.Should().Be(expected);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
|
||||
@@ -190,7 +184,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
|
||||
@@ -218,7 +212,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.IsMatch(It.IsAny<string>()), Times.Once);
|
||||
@@ -247,7 +241,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1d);
|
||||
score.Should().Be(1d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.IsMatch(It.IsAny<string>()), Times.Once);
|
||||
@@ -274,7 +268,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1d);
|
||||
score.Should().Be(1d);
|
||||
|
||||
// Verify
|
||||
objectMatcherMock.Verify(m => m.IsMatch(42), Times.Once);
|
||||
@@ -299,7 +293,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -331,7 +325,7 @@ public class RequestMessageBodyMatcherTests
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData(new byte[0], 0.0)]
|
||||
[InlineData(new byte[] { 48 }, 1.0)]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_NotNullOrEmptyObjectMatcher(byte[] bytes, double expected)
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_NotNullOrEmptyObjectMatcher(byte[]? bytes, double expected)
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
@@ -355,7 +349,7 @@ public class RequestMessageBodyMatcherTests
|
||||
[InlineData(null, 0.0)]
|
||||
[InlineData("", 0.0)]
|
||||
[InlineData("x", 1.0)]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_NotNullOrEmptyObjectMatcher(string data, double expected)
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_NotNullOrEmptyObjectMatcher(string? data, double expected)
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
@@ -398,7 +392,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
|
||||
// Verify
|
||||
objectMatcherMock.Verify(m => m.IsMatch(It.IsAny<byte[]>()), Times.Once);
|
||||
@@ -426,7 +420,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -450,7 +444,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -474,7 +468,7 @@ public class RequestMessageBodyMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -491,7 +485,7 @@ public class RequestMessageBodyMatcherTests
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
bodyData = await BodyParser.ParseAsync(bodyParserSettings);
|
||||
}
|
||||
else if (body is string s)
|
||||
{
|
||||
@@ -501,7 +495,7 @@ public class RequestMessageBodyMatcherTests
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
bodyData = await BodyParser.ParseAsync(bodyParserSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -515,7 +509,7 @@ public class RequestMessageBodyMatcherTests
|
||||
var score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// assert
|
||||
Check.That(score).IsEqualTo(shouldMatch ? 1d : 0d);
|
||||
score.Should().Be(shouldMatch ? 1d : 0d);
|
||||
}
|
||||
|
||||
public static TheoryData<object, RequestMessageBodyMatcher, bool> MatchingScoreData
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
@@ -31,7 +27,7 @@ public class RequestMessageCompositeMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +47,7 @@ public class RequestMessageCompositeMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.9d);
|
||||
score.Should().Be(0.9d);
|
||||
|
||||
// Verify
|
||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
@@ -75,7 +71,7 @@ public class RequestMessageCompositeMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
|
||||
// Verify
|
||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
@@ -23,7 +20,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,7 +35,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -54,7 +51,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +67,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -86,7 +83,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -102,7 +99,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -118,7 +115,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -134,7 +131,7 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -150,6 +147,6 @@ public class RequestMessageCookieMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if GRAPHQL
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
@@ -192,5 +188,4 @@ public class RequestMessageGraphQLMatcherTests
|
||||
stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
|
||||
stringMatcherMock.Verify(m => m.IsMatch(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
@@ -23,7 +20,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,7 +35,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -54,7 +51,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
[Fact]
|
||||
public void RequestMessageHeaderMatcher_GetMatchingScore_RejectOnMatch_HeaderDoesNotMatchPattern()
|
||||
@@ -69,7 +66,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -85,7 +82,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -101,7 +98,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -117,7 +114,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -133,7 +130,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -149,7 +146,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -165,7 +162,7 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -181,6 +178,6 @@ public class RequestMessageHeaderMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if MIMEKIT
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers;
|
||||
|
||||
@@ -215,5 +209,4 @@ AAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC
|
||||
var result = new RequestMatchResult();
|
||||
return matcher.GetMatchingScore(requestMessage, result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
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;
|
||||
|
||||
@@ -25,7 +22,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -40,7 +37,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
score.Should().Be(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,7 +52,7 @@ public class RequestMessageParamMatcherTests
|
||||
var score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +67,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||
score.Should().BeApproximately(0.66d, 0.1d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -85,7 +82,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||
score.Should().BeApproximately(0.66d, 0.1d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +97,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -115,7 +112,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -130,7 +127,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
score.Should().Be(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -145,7 +142,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
score.Should().Be(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -160,7 +157,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -175,7 +172,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -190,7 +187,7 @@ public class RequestMessageParamMatcherTests
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
score.Should().Be(1.0d);
|
||||
}
|
||||
|
||||
// Issue #849
|
||||
@@ -212,4 +209,5 @@ public class RequestMessageParamMatcherTests
|
||||
// Assert
|
||||
score.Should().Be(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
@@ -18,7 +15,7 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "posT", ClientIp);
|
||||
|
||||
// then
|
||||
Check.That(request.Method).IsEqualTo("posT");
|
||||
request.Method.Should().Be("posT");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -28,7 +25,7 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp);
|
||||
|
||||
// then
|
||||
Check.That(request.GetParameter("not_there")).IsNull();
|
||||
request.GetParameter("not_there").Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,7 +35,7 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost?foo=bar"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("foo")).ContainsExactly("bar");
|
||||
request.GetParameter("foo").Should().ContainSingle("bar");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -48,7 +45,7 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost?foo=bar"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("FoO", true)).ContainsExactly("bar");
|
||||
request.GetParameter("FoO", true).Should().ContainSingle("bar");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -58,8 +55,8 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost?key=1&key=2"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("key")).Contains("1");
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
request.GetParameter("key").Should().Contain("1");
|
||||
request.GetParameter("key").Should().Contain("2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -69,9 +66,9 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost?key=1,2,3"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("key")).Contains("1");
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
Check.That(request.GetParameter("key")).Contains("3");
|
||||
request.GetParameter("key").Should().Contain("1");
|
||||
request.GetParameter("key").Should().Contain("2");
|
||||
request.GetParameter("key").Should().Contain("3");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,28 +78,8 @@ public class RequestMessageTests
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost?key=1,2&foo=bar&key=3"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("key")).Contains("1");
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
Check.That(request.GetParameter("key")).Contains("3");
|
||||
request.GetParameter("key").Should().Contain("1");
|
||||
request.GetParameter("key").Should().Contain("2");
|
||||
request.GetParameter("key").Should().Contain("3");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Constructor1_PathSegments()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/a/b/c"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Constructor2_PathSegments()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
|
||||
|
||||
// Assert
|
||||
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.ResponseBuilders;
|
||||
|
||||
@@ -25,9 +24,9 @@ public class ResponseCreateTests
|
||||
var responseBuilder = Response.Create(() => responseMessage);
|
||||
|
||||
// Act
|
||||
var response = await responseBuilder.ProvideResponseAsync(mapping, request, _settings).ConfigureAwait(false);
|
||||
var response = await responseBuilder.ProvideResponseAsync(mapping, Mock.Of<HttpContext>(), request, _settings);
|
||||
|
||||
// Assert
|
||||
Check.That(response.Message).Equals(responseMessage);
|
||||
response.Message.Should().Be(responseMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user