This commit is contained in:
Stef Heyenrath
2026-02-14 11:41:25 +01:00
parent 99f42fb255
commit 6cc18e796c
55 changed files with 164 additions and 398 deletions

View File

@@ -114,8 +114,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.AspNetCore.Middleware", "src\WireMock.Net.AspNetCore.Middleware\WireMock.Net.AspNetCore.Middleware.csproj", "{B6269AAC-170A-4346-8B9A-579DED3D9A13}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.TestWebApplication", "test\WireMock.Net.TestWebApplication\WireMock.Net.TestWebApplication.csproj", "{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Middleware.Tests", "test\WireMock.Net.Middleware.Tests\WireMock.Net.Middleware.Tests.csproj", "{A5FEF4F7-7DA2-4962-89A8-16BA942886E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.AwesomeAssertions", "src\WireMock.Net.AwesomeAssertions\WireMock.Net.AwesomeAssertions.csproj", "{7753670F-7C7F-44BF-8BC7-08325588E60C}"
@@ -156,6 +154,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.WebApplication
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.WebSocketExamples", "examples\WireMock.Net.WebSocketExamples\WireMock.Net.WebSocketExamples.csproj", "{2CE8E3A6-59CC-FE9C-9399-AD54E1FA862B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.TestWebApplication", "examples\WireMock.Net.TestWebApplication\WireMock.Net.TestWebApplication.csproj", "{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.TestWebApplication", "test\WireMock.Net.TestWebApplication\WireMock.Net.TestWebApplication.csproj", "{3B05CC76-C3CB-8667-6B65-3129DFB25681}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -586,18 +588,6 @@ Global
{B6269AAC-170A-4346-8B9A-579DED3D9A13}.Release|x64.Build.0 = Release|Any CPU
{B6269AAC-170A-4346-8B9A-579DED3D9A13}.Release|x86.ActiveCfg = Release|Any CPU
{B6269AAC-170A-4346-8B9A-579DED3D9A13}.Release|x86.Build.0 = Release|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Debug|x64.ActiveCfg = Debug|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Debug|x64.Build.0 = Debug|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Debug|x86.ActiveCfg = Debug|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Debug|x86.Build.0 = Debug|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Release|Any CPU.Build.0 = Release|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Release|x64.ActiveCfg = Release|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Release|x64.Build.0 = Release|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Release|x86.ActiveCfg = Release|Any CPU
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE}.Release|x86.Build.0 = Release|Any CPU
{A5FEF4F7-7DA2-4962-89A8-16BA942886E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5FEF4F7-7DA2-4962-89A8-16BA942886E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5FEF4F7-7DA2-4962-89A8-16BA942886E5}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -838,6 +828,30 @@ Global
{2CE8E3A6-59CC-FE9C-9399-AD54E1FA862B}.Release|x64.Build.0 = Release|Any CPU
{2CE8E3A6-59CC-FE9C-9399-AD54E1FA862B}.Release|x86.ActiveCfg = Release|Any CPU
{2CE8E3A6-59CC-FE9C-9399-AD54E1FA862B}.Release|x86.Build.0 = Release|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Debug|x64.ActiveCfg = Debug|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Debug|x64.Build.0 = Debug|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Debug|x86.ActiveCfg = Debug|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Debug|x86.Build.0 = Debug|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Release|Any CPU.Build.0 = Release|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Release|x64.ActiveCfg = Release|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Release|x64.Build.0 = Release|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Release|x86.ActiveCfg = Release|Any CPU
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652}.Release|x86.Build.0 = Release|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Debug|x64.ActiveCfg = Debug|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Debug|x64.Build.0 = Debug|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Debug|x86.ActiveCfg = Debug|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Debug|x86.Build.0 = Debug|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Release|Any CPU.Build.0 = Release|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Release|x64.ActiveCfg = Release|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Release|x64.Build.0 = Release|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Release|x86.ActiveCfg = Release|Any CPU
{3B05CC76-C3CB-8667-6B65-3129DFB25681}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -880,7 +894,6 @@ Global
{4CD237F7-B616-46B8-872F-E49B4BBB3EAE} = {0BB8B634-407A-4610-A91F-11586990767A}
{E72ADFAB-4B42-439E-B1EE-C06E504B35D2} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
{B6269AAC-170A-4346-8B9A-579DED3D9A13} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
{6B30AA9F-DA04-4EB5-B03C-45A8EF272ECE} = {0BB8B634-407A-4610-A91F-11586990767A}
{A5FEF4F7-7DA2-4962-89A8-16BA942886E5} = {0BB8B634-407A-4610-A91F-11586990767A}
{7753670F-7C7F-44BF-8BC7-08325588E60C} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
{E5B03EEF-822C-4295-952B-4479AD30082B} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
@@ -901,6 +914,8 @@ Global
{2D86546D-8A24-0A55-C962-2071BD299E05} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
{5E6E9FA7-9135-7B82-2CCD-8CA87AC8043C} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
{2CE8E3A6-59CC-FE9C-9399-AD54E1FA862B} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
{2EA75541-E63A-37B7-DA0A-BEA82ECD7652} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
{3B05CC76-C3CB-8667-6B65-3129DFB25681} = {0BB8B634-407A-4610-A91F-11586990767A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}

View File

@@ -1,14 +1,7 @@
// Copyright © WireMock.Net
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
//#if !USE_ASPNETCORE
//using IResponse = Microsoft.Owin.IOwinResponse;
//#else
//using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
//#endif
namespace WireMock.Owin.Mappers;
/// <summary>

View File

@@ -2,14 +2,9 @@
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
//#if USE_ASPNETCORE
//using System.Security.Cryptography.X509Certificates;
//#endif
using System.Text.Json.Serialization;
using Stef.Validation;
using WireMock.Models;
using WireMock.Owin;
@@ -83,11 +78,10 @@ public class RequestMessage : IRequestMessage
/// <inheritdoc />
public byte[]? BodyAsBytes { get; }
//#if MIMEKIT
/// <inheritdoc />
[Newtonsoft.Json.JsonIgnore] // Issue 1001
[JsonIgnore]
public Models.Mime.IMimeMessageData? BodyAsMimeMessage { get; }
//#endif
/// <inheritdoc />
public string? DetectedBodyType { get; }
@@ -110,10 +104,8 @@ public class RequestMessage : IRequestMessage
/// <inheritdoc />
public string Origin { get; }
//#if USE_ASPNETCORE
/// <inheritdoc />
public X509Certificate2? ClientCertificate { get; }
//#endif
/// <summary>
/// Used for Unit Testing
@@ -136,10 +128,8 @@ public class RequestMessage : IRequestMessage
IBodyData? bodyData = null,
IDictionary<string, string[]>? headers = null,
IDictionary<string, string>? cookies = null,
string httpVersion = "1.1"
//#if USE_ASPNETCORE
, X509Certificate2? clientCertificate = null
//#endif
string httpVersion = "1.1",
X509Certificate2? clientCertificate = null
)
{
Guard.NotNull(urlDetails);
@@ -179,16 +169,11 @@ public class RequestMessage : IRequestMessage
Query = QueryStringParser.Parse(RawQuery, options?.QueryParameterMultipleValueSupport);
QueryIgnoreCase = new Dictionary<string, WireMockList<string>>(Query, StringComparer.OrdinalIgnoreCase);
//#if USE_ASPNETCORE
ClientCertificate = clientCertificate;
//#endif
//#if MIMEKIT
if (TypeLoader.TryLoadStaticInstance<IMimeKitUtils>(out var mimeKitUtils) && mimeKitUtils.TryGetMimeMessage(this, out var mimeMessage))
{
BodyAsMimeMessage = mimeMessage;
}
//#endif
}
/// <inheritdoc />

View File

@@ -218,7 +218,6 @@ internal class MatcherMapper
model.ContentTypeMatcher = Map(mimePartMatcher.ContentTypeMatcher);
break;
//#if PROTOBUF
case IProtoBufMatcher protoBufMatcher:
protoBufMatcher.ProtoDefinition().Value(id => model.Pattern = id, texts =>
{
@@ -235,7 +234,6 @@ internal class MatcherMapper
model.ProtoBufMessageType = protoBufMatcher.MessageType;
model.ContentMatcher = Map(protoBufMatcher.Matcher);
break;
//#endif
}
afterMap?.Invoke(model);

View File

@@ -330,12 +330,10 @@ public partial class WireMockServer
InitSettings(_settings);
//#if USE_ASPNETCORE
if (Enum.TryParse<CorsPolicyOptions>(settings.CorsPolicyOptions, true, out var corsPolicyOptions))
{
_settings.CorsPolicyOptions = corsPolicyOptions;
}
//#endif
WireMockMiddlewareOptionsHelper.InitFromSettings(_settings, _options, o =>
{
@@ -344,11 +342,9 @@ public partial class WireMockServer
o.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
}
//#if USE_ASPNETCORE
o.CorsPolicyOptions = corsPolicyOptions;
o.ClientCertificateMode = (Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode) _settings.ClientCertificateMode;
o.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate;
//#endif
});
return ResponseMessageBuilder.Create(200, "Settings updated");

View File

@@ -24,7 +24,6 @@ internal static class WireMockHandlebarsHelpers
GetBaseDirectory(),
};
//#if !NETSTANDARD1_3_OR_GREATER
void Add(string? path, ICollection<string> customHelperPaths)
{
if (!string.IsNullOrEmpty(path))
@@ -36,7 +35,7 @@ internal static class WireMockHandlebarsHelpers
Add(Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location), paths);
Add(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), paths);
Add(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName), paths);
//#endif
o.CustomHelperPaths = paths;
o.Categories = settings.HandlebarsSettings?.AllowedHandlebarsHelpers ?? HandlebarsSettings.DefaultAllowedHandlebarsHelpers;

View File

@@ -18,12 +18,11 @@ internal static class CultureInfoUtils
try
{
//#if !NETSTANDARD1_3
if (int.TryParse(value, out var culture))
{
return new CultureInfo(culture);
}
//#endif
if (string.Equals(value, nameof(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase))
{
return CultureInfo.CurrentCulture;

View File

@@ -1,14 +1,8 @@
// Copyright © WireMock.Net
using System;
using Microsoft.AspNetCore.Http;
using WireMock.Models;
using Stef.Validation;
//#if !USE_ASPNETCORE
//using Microsoft.Owin;
//#else
//using Microsoft.AspNetCore.Http;
//#endif
namespace WireMock.Util;

View File

@@ -1,7 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Stef.Validation;
@@ -10,9 +8,7 @@ namespace WireMock.RegularExpressions;
/// <summary>
/// Extension to the <see cref="Regex"/> object, adding support for GUID tokens for matching on.
/// </summary>
//#if !NETSTANDARD1_3
[Serializable]
//#endif
internal class RegexExtended : Regex
{
/// <inheritdoc cref="Regex"/>

View File

@@ -148,7 +148,6 @@ public class WireMockServerSettings
[JsonIgnore]
public Action<object>? PostWireMockMiddlewareInit { get; set; }
//#if USE_ASPNETCORE
/// <summary>
/// Action which is called with IServiceCollection when ASP.NET Core DI is being configured. [Optional]
/// </summary>
@@ -161,7 +160,6 @@ public class WireMockServerSettings
/// </summary>
[PublicAPI]
public CorsPolicyOptions? CorsPolicyOptions { get; set; }
//#endif
/// <summary>
/// The IWireMockLogger which logs Debug, Info, Warning or Error
@@ -246,7 +244,6 @@ public class WireMockServerSettings
[PublicAPI]
public bool CustomCertificateDefined => CertificateSettings?.IsDefined == true;
//#if USE_ASPNETCORE
/// <summary>
/// Client certificate mode for the server
/// </summary>
@@ -257,8 +254,7 @@ public class WireMockServerSettings
/// Whether to accept any client certificate
/// </summary>
public bool AcceptAnyClientCertificate { get; set; }
//#endif
/// <summary>
/// Defines the global IWebhookSettings to use.
/// </summary>

View File

@@ -22,10 +22,7 @@ internal static class CompressionUtils
using var compressedStream = new MemoryStream();
using var zipStream = Create(contentEncoding, compressedStream, CompressionMode.Compress);
zipStream.Write(data, 0, data.Length);
//#if !NETSTANDARD1_3
zipStream.Close();
//#endif
return compressedStream.ToArray();
}

View File

@@ -1,10 +1,8 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using Stef.Validation;
@@ -142,16 +140,13 @@ internal static class TypeLoader
private static bool TryFindTypeInDlls<TInterface>(string? implementationTypeFullName, [NotNullWhen(true)] out Type? pluginType) where TInterface : class
{
//#if NETSTANDARD1_3
// var directoriesToSearch = new[] { AppContext.BaseDirectory };
//#else
var processDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName);
var processDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName);
var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var directoriesToSearch = new[] { processDirectory, assemblyDirectory }
.Where(d => !string.IsNullOrEmpty(d))
.Distinct()
.ToArray();
//#endif
foreach (var directory in directoriesToSearch)
{
foreach (var file in Directory.GetFiles(directory!, "*.dll"))

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
@@ -26,7 +27,7 @@
<PackageReference Include="AwesomeAssertions" Version="9.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.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>

View File

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

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<Authors>Gennadii Saltyshchak</Authors>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<DebugType>full</DebugType>
@@ -20,7 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.9.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>

View File

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

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
@@ -25,7 +26,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.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>

View File

@@ -17,7 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="WireMock.Net" Version="1.25.0" />
<PackageReference Include="xunit" Version="2.9.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>

View File

@@ -43,7 +43,7 @@ message HelloReply {
var api = RestClient.For<IWireMockAdminApi>(server.Url);
var getMappingsResult = await api.GetMappingsAsync();
await Verifier.Verify(getMappingsResult, VerifySettings);
await Verify(getMappingsResult, VerifySettings);
}
[Fact]
@@ -56,7 +56,7 @@ message HelloReply {
var client = server.CreateClient();
var getMappingsResult = await client.GetStringAsync("/__admin/mappings");
await Verifier.VerifyJson(getMappingsResult, VerifySettings);
await VerifyJson(getMappingsResult, VerifySettings);
}
public WireMockServer Given_WithBodyAsProtoBuf_AddedToServer()

View File

@@ -26,7 +26,6 @@ using WireMock.Util;
namespace WireMock.Net.Tests.AdminApi;
[UsesVerify]
public partial class WireMockAdminApiTests
{
private static readonly VerifySettings VerifySettings = new();

View File

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

View File

@@ -1,27 +1,19 @@
// 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 +22,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 +50,15 @@ public class AdminApiMappingBuilderTests
);
// Act
var status = await mappingBuilder.BuildAndPostAsync();
var status = await mappingBuilder.BuildAndPostAsync(ct);
// Assert
status.Status.Should().Be("Mapping added");
var getMappingResult = await api.GetMappingAsync(guid);
var getMappingResult = await api.GetMappingAsync(guid, ct);
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
await Verify(getMappingResult, VerifySettings).DontScrubGuids();
server.Stop();
}
}
#endif
}

View File

@@ -1,12 +1,7 @@
// 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;
@@ -24,11 +19,11 @@ public class ProtoBufUtilsTests
// Act
var responseBytes = await ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(
[greet, request],
"greet.HelloRequest",
new
"greet.HelloRequest", new
{
name = "hello"
}
},
cancellationToken: TestContext.Current.CancellationToken
);
// Assert
@@ -39,5 +34,4 @@ public class ProtoBufUtilsTests
{
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Grpc", filename));
}
}
//#endif
}

View File

@@ -1,12 +1,7 @@
// 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;
@@ -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
}

View File

@@ -1,18 +1,14 @@
// 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 ExampleIntegrationTest.Lookup;
using FluentAssertions;
using Google.Protobuf.WellKnownTypes;
using Greet;
using Grpc.Net.Client;
using ExampleIntegrationTest.Lookup;
using WireMock.Constants;
using WireMock.Matchers;
using WireMock.RequestBuilders;
@@ -20,7 +16,6 @@ using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
using WireMock.Util;
using Xunit;
// ReSharper disable once CheckNamespace
namespace WireMock.Net.Tests;
@@ -140,7 +135,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);
@@ -178,7 +173,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);
@@ -772,5 +767,4 @@ message Other {
{
return File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Grpc", filename));
}
}
//#endif
}

View File

@@ -1,12 +1,8 @@
// 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 +14,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 +152,7 @@ public class MappingBuilderTests
var mappings = _sut.GetMappings();
// Verify
return Verifier.Verify(mappings, VerifySettings).DontScrubGuids();
return Verify(mappings, VerifySettings).DontScrubGuids();
}
[Fact]
@@ -168,7 +162,7 @@ public class MappingBuilderTests
var json = _sut.ToJson();
// Verify
return Verifier.VerifyJson(json, VerifySettings).DontScrubGuids();
return VerifyJson(json, VerifySettings).DontScrubGuids();
}
[Fact]
@@ -178,7 +172,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 +182,7 @@ public class MappingBuilderTests
var code = _sut.ToCSharpCode(MappingConverterType.Builder);
// Verify
return Verifier.Verify(code, VerifySettings).DontScrubGuids();
return Verify(code, VerifySettings).DontScrubGuids();
}
[Fact]

View File

@@ -1,14 +1,10 @@
// 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 +228,4 @@ public class GraphQLMatcherTests
// Assert
action.Should().Throw<GraphQLSyntaxErrorException>();
}
}
//#endif
}

View File

@@ -1,11 +1,8 @@
// Copyright © WireMock.Net
//#if MIMEKIT
using System;
using FluentAssertions;
using WireMock.Matchers;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Matchers;
@@ -98,5 +95,4 @@ public class MimePartMatcherTests
// Assert
result.Score.Should().Be(MatchScores.Perfect);
}
}
//#endif
}

View File

@@ -1,10 +1,7 @@
// Copyright © WireMock.Net
//#if GRAPHQL
using System;
using FluentAssertions;
using WireMock.GraphQL.Models;
using Xunit;
namespace WireMock.Net.Tests.Matchers.Models;
@@ -94,5 +91,4 @@ public class WireMockCustomScalarGraphTypeTests
// Assert
result.Should().Be("someString");
}
}
//#endif
}

View File

@@ -1,13 +1,9 @@
// 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;
@@ -107,5 +103,4 @@ message HelloReply {
result.Score.Should().Be(MatchScores.Mismatch);
result.Exception.Should().BeOfType<ArgumentException>();
}
}
//#endif
}

View File

@@ -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);
@@ -46,7 +39,7 @@ public class WireMockOpenApiParserTests
var mappings = _sut.FromText(openApiDocument, settings, out _);
// Verify
await Verifier.Verify(mappings);
await Verify(mappings);
}
[Fact]
@@ -64,7 +57,6 @@ public class WireMockOpenApiParserTests
var mappings = _sut.FromText(openApiDocument, settings, out _);
// Verify
await Verifier.Verify(mappings);
await Verify(mappings);
}
}
//#endif
}

View File

@@ -1,23 +1,17 @@
#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 +50,7 @@ public class PactTests
server.SavePact(folder, file);
// Assert
await Verifier.VerifyFile(path);
await VerifyFile(path);
}
[Fact]
@@ -77,7 +71,7 @@ public class PactTests
server.SavePact(folder, file);
// Assert
await Verifier.VerifyFile(path);
await VerifyFile(path);
}
[Fact]
@@ -245,5 +239,4 @@ public class PactTests
// Assert
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
}
}
#endif
}

View File

@@ -1,13 +1,10 @@
// 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 +66,4 @@ public class RequestBuilderWithGraphQLSchemaTests
matchers.Should().HaveCount(1);
((RequestMessageGraphQLMatcher)matchers[0]).Matchers.Should().ContainItemsAssignableTo<GraphQLMatcher>();
}
}
//#endif
}

View File

@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
//#if PROTOBUF
using System.Collections.Generic;
using FluentAssertions;
using WireMock.Matchers;
@@ -63,5 +62,4 @@ message HelloReply {
protoBufMatcher.MessageType.Should().Be(MessageType);
protoBufMatcher.Matcher.Should().BeOfType<JsonMatcher>();
}
}
//#endif
}

View File

@@ -1,7 +1,5 @@
// Copyright © WireMock.Net
//#if GRAPHQL
using System.Linq;
using FluentAssertions;
using Moq;
using WireMock.Matchers;
@@ -9,7 +7,6 @@ using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Types;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers;
@@ -192,5 +189,4 @@ public class RequestMessageGraphQLMatcherTests
stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
stringMatcherMock.Verify(m => m.IsMatch(It.IsAny<string>()), Times.Never);
}
}
//#endif
}

View File

@@ -1,16 +1,11 @@
// 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 +210,4 @@ AAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC
var result = new RequestMatchResult();
return matcher.GetMatchingScore(requestMessage, result);
}
}
//#endif
}

View File

@@ -1,21 +1,15 @@
// Copyright © WireMock.Net
using System.Threading.Tasks;
//using System.Xml;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using NFluent;
using WireMock.Handlers;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
using Xunit;
using Moq;
using WireMock.Handlers;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
//#if !NETSTANDARD1_3
//using Wmhelp.XPath2;
//#endif
namespace WireMock.Net.Tests.ResponseBuilders;

View File

@@ -1,14 +1,9 @@
// Copyright © WireMock.Net
#if NET8_0_OR_GREATER
using System;
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 Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@@ -22,8 +17,6 @@ using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
using Xunit;
using Xunit.Abstractions;
namespace WireMock.Net.Tests.ResponseBuilders;
@@ -95,10 +88,10 @@ public sealed class ResponseWithProxyIntegrationTests(ITestOutputHelper output)
{
var started = new TaskCompletionSource();
var host = app.Services.GetRequiredService<IHostApplicationLifetime>();
host.ApplicationStarted.Register(() => started.SetResult());
host.ApplicationStarted.Register(started.SetResult);
_ = Task.Run(() => app.RunAsync());
await started.Task;
_disposable = new(() => host.StopApplication());
_disposable = new(host.StopApplication);
return this;
}

View File

@@ -1,10 +1,9 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -15,14 +14,6 @@ using WireMock.ResponseBuilders;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
using Xunit;
using System.Globalization;
using CultureAwareTesting.xUnit;
#if NET452
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif
namespace WireMock.Net.Tests.ResponseBuilders;
@@ -442,7 +433,7 @@ public class ResponseWithTransformerTests
Check.That(JsonConvert.SerializeObject(response.Message.BodyData!.BodyAsJson)).Equals("{\"x\":\"test /foo_object\"}");
}
[CulturedTheory("en-US")]
[CulturedTheory(["en-US"])]
[InlineData(TransformerType.Handlebars, "{ \"id\": 42 }", "{\"x\":\"test 42\",\"y\":42}")]
[InlineData(TransformerType.Scriban, "{ \"id\": 42 }", "{\"x\":\"test 42\",\"y\":42}")]
[InlineData(TransformerType.ScribanDotLiquid, "{ \"id\": 42 }", "{\"x\":\"test 42\",\"y\":42}")]
@@ -779,7 +770,6 @@ public class ResponseWithTransformerTests
response.Message.BodyData.Encoding.Should().Be(enc);
}
//#if MIMEKIT
[Theory]
[InlineData(TransformerType.Handlebars)]
// [InlineData(TransformerType.Scriban)]
@@ -830,7 +820,6 @@ AAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC
// Assert
response.Message.BodyData!.BodyAsString.Should().Be("text/plain text/json image.png");
}
//#endif
[Theory]
[InlineData("/wiremock-data/1", "one")]

View File

@@ -1,9 +1,5 @@
// Copyright © WireMock.Net
#if !(NET452 || NET461)
using System.Threading.Tasks;
using VerifyTests;
using VerifyXunit;
using WireMock.Logging;
using WireMock.Models;
using WireMock.Net.Tests.VerifyExtensions;
@@ -12,11 +8,9 @@ using WireMock.ResponseBuilders;
using WireMock.Serialization;
using WireMock.Types;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
[UsesVerify]
public class LogEntryMapperTests
{
private static readonly VerifySettings VerifySettings = new();
@@ -64,7 +58,7 @@ public class LogEntryMapperTests
var result = _sut.Map(logEntry);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
[Fact]
@@ -88,7 +82,7 @@ public class LogEntryMapperTests
var result = _sut.Map(logEntry);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
[Fact]
@@ -114,7 +108,7 @@ public class LogEntryMapperTests
var result = _sut.Map(logEntry);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
[Fact]
@@ -153,7 +147,6 @@ public class LogEntryMapperTests
var result = new LogEntryMapper(options).Map(logEntry);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
}
#endif
}

View File

@@ -1,21 +1,14 @@
// Copyright © WireMock.Net
#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Threading.Tasks;
using FluentAssertions;
using VerifyTests;
using VerifyXunit;
using WireMock.Net.Tests.VerifyExtensions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Serialization;
using WireMock.Types;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
[UsesVerify]
public partial class MappingConverterTests
{
private static readonly VerifySettings VerifySettings = new();
@@ -41,7 +34,7 @@ public partial class MappingConverterTests
code.Should().NotBeEmpty();
// Verify
return Verifier.Verify(code, VerifySettings);
return Verify(code, VerifySettings);
}
[Fact]
@@ -61,7 +54,7 @@ public partial class MappingConverterTests
code.Should().NotBeEmpty();
// Verify
return Verifier.Verify(code, VerifySettings);
return Verify(code, VerifySettings);
}
[Fact]
@@ -81,7 +74,7 @@ public partial class MappingConverterTests
code.Should().NotBeEmpty();
// Verify
return Verifier.Verify(code, VerifySettings);
return Verify(code, VerifySettings);
}
[Fact]
@@ -101,7 +94,7 @@ public partial class MappingConverterTests
code.Should().NotBeEmpty();
// Verify
return Verifier.Verify(code, VerifySettings);
return Verify(code, VerifySettings);
}
private IMapping CreateMapping()
@@ -142,5 +135,4 @@ public partial class MappingConverterTests
data: null
).WithProbability(0.3);
}
}
#endif
}

View File

@@ -1,12 +1,6 @@
// Copyright © WireMock.Net
//#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using VerifyXunit;
using WireMock.Matchers;
using WireMock.Models;
using WireMock.RequestBuilders;
@@ -15,7 +9,6 @@ using WireMock.Serialization;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
@@ -100,7 +93,7 @@ message HelloReply {
model.Webhook.Request.BodyAsJson.Should().BeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -177,7 +170,7 @@ message HelloReply {
model.Webhooks[1].Request.Body.Should().Be("2");
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -199,7 +192,7 @@ message HelloReply {
model.Description.Should().Be(description);
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -219,7 +212,7 @@ message HelloReply {
model.Response.UseTransformer.Should().BeTrue();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -250,7 +243,7 @@ message HelloReply {
model.TimeSettings.TTL.Should().Be(ttl);
// Verify
return Verifier.Verify(model, VerifySettings);
return Verify(model, VerifySettings);
}
[Fact]
@@ -296,7 +289,7 @@ message HelloReply {
model.Response.Delay.Should().Be(delay);
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -318,7 +311,7 @@ message HelloReply {
model.Response.MaximumRandomDelay.Should().Be(60_000);
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -341,7 +334,7 @@ message HelloReply {
model.Response.MaximumRandomDelay.Should().Be(maximumDelay);
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -362,7 +355,7 @@ message HelloReply {
model.Probability.Should().Be(0.4);
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -380,7 +373,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -412,7 +405,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -438,7 +431,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -459,7 +452,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
#if TRAILINGHEADERS
@@ -482,7 +475,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -503,7 +496,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
#endif
@@ -528,10 +521,9 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
//#if GRAPHQL
[Fact]
public Task ToMappingModel_Request_WithBodyAsGraphQLSchema_ReturnsCorrectModel()
{
@@ -560,11 +552,9 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
//#endif
//#if PROTOBUF
[Fact]
public Task ToMappingModel_Request_WithBodyAsProtoBuf_ReturnsCorrectModel()
{
@@ -587,7 +577,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -614,7 +604,7 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
[Fact]
@@ -649,8 +639,6 @@ message HelloReply {
model.Should().NotBeNull();
// Verify
return Verifier.Verify(model);
return Verify(model);
}
//#endif
}
//#endif
}

View File

@@ -1,7 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using AnyOfTypes;
using FluentAssertions;
using FluentAssertions.Execution;
@@ -14,7 +12,6 @@ using WireMock.Matchers;
using WireMock.Models;
using WireMock.Serialization;
using WireMock.Settings;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
@@ -56,13 +53,12 @@ public class MatcherMapperTests
var matcherMock2 = new Mock<IStringMatcher>();
// Act
var models = _sut.Map(new[] { matcherMock1.Object, matcherMock2.Object });
var models = _sut.Map([matcherMock1.Object, matcherMock2.Object]);
// Assert
models.Should().HaveCount(2);
}
//#if MIMEKIT
[Fact]
public void MatcherMapper_Map_Matcher_MimePartMatcher()
{
@@ -94,7 +90,6 @@ public class MatcherMapperTests
model.ContentMatcher!.Name.Should().Be(nameof(ExactObjectMatcher));
model.ContentMatcher.Pattern.Should().Be(bytes);
}
//#endif
[Fact]
public void MatcherMapper_Map_Matcher_IStringMatcher()
@@ -124,7 +119,7 @@ public class MatcherMapperTests
var matcherMock = new Mock<IStringMatcher>();
matcherMock.Setup(m => m.Name).Returns("test");
matcherMock.Setup(m => m.GetPatterns()).Returns(new AnyOf<string, StringPattern>[] { pattern });
matcherMock.Setup(m => m.GetPatterns()).Returns([pattern]);
// Act
var model = _sut.Map(matcherMock.Object)!;
@@ -171,7 +166,6 @@ public class MatcherMapperTests
model.XmlNamespaceMap.Should().BeEquivalentTo(xmlNamespaceMap);
}
//#if GRAPHQL
[Fact]
public void MatcherMapper_Map_Matcher_GraphQLMatcher()
{
@@ -199,9 +193,7 @@ public class MatcherMapperTests
model.Pattern.Should().Be(testSchema);
model.CustomScalars.Should().BeEquivalentTo(customScalars);
}
//#endif
//#if PROTOBUF
[Fact]
public void MatcherMapper_Map_Matcher_ProtoBufMatcher()
{
@@ -280,7 +272,6 @@ message HelloReply {
model.ContentMatcher?.Name.Should().Be("JsonMatcher");
model.ContentMatcher?.Pattern.Should().Be(jsonPattern);
}
//#endif
[Fact]
public void MatcherMapper_Map_MatcherModel_Null()
@@ -598,7 +589,6 @@ message HelloReply {
matcher.MatchBehaviour.Should().Be(MatchBehaviour.RejectOnMatch);
}
//#if MIMEKIT
[Fact]
public void MatcherMapper_Map_MatcherModel_MimePartMatcher()
{
@@ -638,7 +628,6 @@ message HelloReply {
matcher.ContentTransferEncodingMatcher.Should().BeAssignableTo<RegexMatcher>().Which.GetPatterns().Should().ContainSingle("z");
matcher.ContentTypeMatcher.Should().BeAssignableTo<ContentTypeMatcher>().Which.GetPatterns().Should().ContainSingle("text/json");
}
//#endif
[Fact]
public void MatcherMapper_Map_MatcherModel_XPathMatcher_WithXmlNamespaces_As_String()
@@ -649,10 +638,10 @@ message HelloReply {
{
Name = "XPathMatcher",
Pattern = pattern,
XmlNamespaceMap = new[]
{
XmlNamespaceMap =
[
new XmlNamespace { Prefix = "s", Uri = "http://schemas.xmlsoap.org/soap/envelope/" }
}
]
};
// Act
@@ -812,7 +801,7 @@ message HelloReply {
var model = new MatcherModel
{
Name = "ExactObjectMatcher",
Patterns = new object[] { "c3RlZg==" }
Patterns = ["c3RlZg=="]
};
// Act
@@ -829,7 +818,7 @@ message HelloReply {
var model = new MatcherModel
{
Name = "ExactObjectMatcher",
Patterns = new object[] { "_" }
Patterns = ["_"]
};
// Act & Assert
@@ -1050,7 +1039,6 @@ message HelloReply {
}
}
//#if GRAPHQL
[Fact]
public void MatcherMapper_Map_MatcherModel_GraphQLMatcher()
{
@@ -1083,9 +1071,7 @@ message HelloReply {
matcher.Name.Should().Be(nameof(GraphQLMatcher));
matcher.CustomScalars.Should().BeEquivalentTo(customScalars);
}
//#endif
//#if PROTOBUF
[Fact]
public void MatcherMapper_Map_MatcherModel_ProtoBufMatcher()
{
@@ -1132,5 +1118,4 @@ message HelloReply {
matcher.MessageType.Should().Be(messageType);
matcher.Matcher?.Value.Should().Be(jsonMatcherPattern);
}
//#endif
}

View File

@@ -1,23 +1,15 @@
// Copyright © WireMock.Net
#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using VerifyTests;
using VerifyXunit;
using WireMock.Matchers;
using WireMock.Net.Tests.VerifyExtensions;
using WireMock.RequestBuilders;
using WireMock.Serialization;
using WireMock.Settings;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
[UsesVerify]
public class ProxyMappingConverterTests
{
private static readonly VerifySettings VerifySettings = new();
@@ -79,7 +71,6 @@ public class ProxyMappingConverterTests
var model = _mappingConverter.ToMappingModel(proxyMapping);
// Verify
return Verifier.Verify(model, VerifySettings);
return Verify(model, VerifySettings);
}
}
#endif
}

View File

@@ -1,21 +1,14 @@
// Copyright © WireMock.Net
#if !(NET452 || NET461 || NETCOREAPP3_1)
using System.Collections.Generic;
using System.Threading.Tasks;
using VerifyTests;
using VerifyXunit;
using WireMock.Admin.Mappings;
using WireMock.Models;
using WireMock.Net.Tests.VerifyExtensions;
using WireMock.Serialization;
using WireMock.Types;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
[UsesVerify]
public class WebhookMapperTests
{
private static readonly VerifySettings VerifySettings = new();
@@ -46,7 +39,7 @@ public class WebhookMapperTests
var result = WebhookMapper.Map(model);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
[Fact]
@@ -71,7 +64,7 @@ public class WebhookMapperTests
var result = WebhookMapper.Map(model);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
[Fact]
@@ -98,7 +91,7 @@ public class WebhookMapperTests
var result = WebhookMapper.Map(model);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
[Fact]
@@ -130,7 +123,6 @@ public class WebhookMapperTests
var result = WebhookMapper.Map(webhook);
// Verify
return Verifier.Verify(result, VerifySettings);
return Verify(result, VerifySettings);
}
}
#endif
}

View File

@@ -1,19 +1,15 @@
// Copyright © WireMock.Net
#if NET6_0_OR_GREATER
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using FluentAssertions;
using FluentAssertions.Execution;
using Meziantou.Extensions.Logging.Xunit;
using Meziantou.Extensions.Logging.Xunit.v3;
using Microsoft.Extensions.Logging;
using WireMock.Net.Testcontainers;
using WireMock.Net.Testcontainers.Utils;
using WireMock.Net.Tests.Facts;
using Xunit;
using Xunit.Abstractions;
namespace WireMock.Net.Tests.Testcontainers;

View File

@@ -1,23 +1,16 @@
// Copyright © WireMock.Net
#if NET6_0_OR_GREATER
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Execution;
using Greet;
using Grpc.Net.Client;
using Meziantou.Extensions.Logging.Xunit;
using Meziantou.Extensions.Logging.Xunit.v3;
using Microsoft.Extensions.Logging;
using WireMock.Constants;
using WireMock.Net.Testcontainers;
using WireMock.Util;
using Xunit;
using Xunit.Abstractions;
namespace WireMock.Net.Tests.Testcontainers;

View File

@@ -1,10 +1,8 @@
// Copyright © WireMock.Net
using System;
using System.Globalization;
using FluentAssertions;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Util;
@@ -39,7 +37,6 @@ public class CultureInfoUtilsTests
result.Should().Be(expectedCulture);
}
//#if !NETSTANDARD1_3
[Fact]
public void Parse_IntegerInput_ReturnsExpectedCultureInfo()
{
@@ -53,7 +50,6 @@ public class CultureInfoUtilsTests
// Assert
result.Should().Be(expectedCulture);
}
//#endif
[Fact]
public void Parse_CurrentCultureInput_ReturnsCurrentCulture()

View File

@@ -1,11 +1,8 @@
// Copyright © WireMock.Net
using System;
using CultureAwareTesting.xUnit;
using FluentAssertions;
using WireMock.Matchers;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Util;
@@ -86,7 +83,7 @@ public class StringUtilsTests
}
}
[CulturedTheory("en-US")]
[CulturedTheory(["en-US"])]
[InlineData("123.1", 123.1, true)]
[InlineData("-456.1", -456.1, true)]
[InlineData("not a double", 0.0, false)] // Invalid case

View File

@@ -15,7 +15,7 @@ internal static class ClientWebSocketExtensions
internal static async Task<string> ReceiveAsTextAsync(this ClientWebSocket client, int bufferSize = 1024, CancellationToken cancellationToken = default)
{
using var receiveBuffer = ArrayPool<byte>.Shared.Lease(1024);
using var receiveBuffer = ArrayPool<byte>.Shared.Lease(bufferSize);
var result = await client.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), cancellationToken);
if (result.MessageType != WebSocketMessageType.Text)
@@ -33,7 +33,7 @@ internal static class ClientWebSocketExtensions
internal static async Task<byte[]> ReceiveAsBytesAsync(this ClientWebSocket client, int bufferSize = 1024, CancellationToken cancellationToken = default)
{
using var receiveBuffer = ArrayPool<byte>.Shared.Lease(1024);
using var receiveBuffer = ArrayPool<byte>.Shared.Lease(bufferSize);
var result = await client.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), cancellationToken);
if (result.MessageType != WebSocketMessageType.Binary)

View File

@@ -8,7 +8,6 @@ using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
using Xunit.Abstractions;
namespace WireMock.Net.Tests.WebSockets;
@@ -18,6 +17,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output)
public async Task EchoServer_Should_Echo_Text_Messages()
{
// Arrange
var cancelationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start(new WireMockServerSettings
{
Logger = new TestOutputHelperWireMockLogger(output),
@@ -43,10 +43,10 @@ public class WebSocketIntegrationTests(ITestOutputHelper output)
client.State.Should().Be(WebSocketState.Open);
var testMessage = "Hello, WebSocket!";
await client.SendAsync(testMessage);
await client.SendAsync(testMessage, cancellationToken: cancelationToken);
// Assert
var received = await client.ReceiveAsTextAsync();
var received = await client.ReceiveAsTextAsync(cancellationToken: cancelationToken);
received.Should().Be(testMessage);
await client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Test complete", CancellationToken.None);

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<Authors>Stef Heyenrath</Authors>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
@@ -50,7 +51,7 @@
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.Matchers.CSharpCode\WireMock.Net.Matchers.CSharpCode.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.xUnit\WireMock.Net.xUnit.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.xUnit.v3\WireMock.Net.xUnit.v3.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
</ItemGroup>
@@ -60,15 +61,12 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Extensions.Logging.Xunit" Version="1.0.23" />
<PackageReference Include="Verify.Xunit" Version="19.6.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.core" Version="2.9.3" />
<PackageReference Include="Meziantou.Extensions.Logging.Xunit.v3" Version="1.1.23" />
<PackageReference Include="Verify.XunitV3" Version="31.12.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CultureAwareTesting.xUnit" Version="0.0.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
@@ -84,6 +82,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="3.2.2" />
<Protobuf Include="Grpc\greet.proto" GrpcServices="Client" />
<Protobuf Include="Grpc\policy.proto" GrpcServices="Client" />

View File

@@ -178,7 +178,7 @@ public class WireMockServerProxyTests
server.Mappings.Should().HaveCount(2);
// Verify
fileSystemHandlerMock.Verify(f => f.WriteMappingFile($"m{System.IO.Path.DirectorySeparatorChar}Proxy Mapping for _{title}.json", It.IsRegex(stringBody)), Times.Once);
fileSystemHandlerMock.Verify(f => f.WriteMappingFile($"m{Path.DirectorySeparatorChar}Proxy Mapping for _{title}.json", It.IsRegex(stringBody)), Times.Once);
}
[Fact]

View File

@@ -1,18 +1,14 @@
// Copyright © WireMock.Net
//#if MIMEKIT
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests;
@@ -73,5 +69,4 @@ public partial class WireMockServerTests
server.Stop();
}
}
//#endif
}

View File

@@ -1,17 +1,12 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Newtonsoft.Json;
using NFluent;
@@ -27,8 +22,6 @@ using WireMock.Server;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
using Xunit;
using Xunit.Abstractions;
namespace WireMock.Net.Tests;