mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-12-06 15:06:45 +01:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4541c3a46 | ||
|
|
ef93f7417d | ||
|
|
acbc33f04e | ||
|
|
3f3e576750 | ||
|
|
48dd8f4927 | ||
|
|
3436818ab5 | ||
|
|
b0af60b27a | ||
|
|
b2eb7c4a18 | ||
|
|
66204c8297 |
No files matched your search
@@ -1,3 +1,13 @@
|
|||||||
|
# 2.35.0 (27 November 2026)
|
||||||
|
- [#1552](https://github.com/wiremock/WireMock.Net/pull/1552) - Upgrade NJsonSchema.Extensions & NSwag.Core [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|
||||||
|
# 2.34.0 (25 November 2026)
|
||||||
|
- [#1551](https://github.com/wiremock/WireMock.Net/pull/1551) - Update Scriban.Signed to 7.6.1 [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|
||||||
|
# 2.33.0 (24 November 2026)
|
||||||
|
- [#1550](https://github.com/wiremock/WireMock.Net/pull/1550) - Configure OpenTelemetry activity source and service names [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1549](https://github.com/wiremock/WireMock.Net/issues/1549) - Support for passing ENV variable for Otel Activity Name [feature]
|
||||||
|
|
||||||
# 2.32.0 (20 November 2026)
|
# 2.32.0 (20 November 2026)
|
||||||
- [#1544](https://github.com/wiremock/WireMock.Net/pull/1544) - Depend on Microsoft.AspNetCore.App for .NET 8 and .NET 10 [dependencies] contributed by [StefH](https://github.com/StefH)
|
- [#1544](https://github.com/wiremock/WireMock.Net/pull/1544) - Depend on Microsoft.AspNetCore.App for .NET 8 and .NET 10 [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#1545](https://github.com/wiremock/WireMock.Net/pull/1545) - Upgrade ProtoBufJsonConverter to latest [dependencies] contributed by [StefH](https://github.com/StefH)
|
- [#1545](https://github.com/wiremock/WireMock.Net/pull/1545) - Upgrade ProtoBufJsonConverter to latest [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>2.32.0</VersionPrefix>
|
<VersionPrefix>2.35.0</VersionPrefix>
|
||||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
# 2.32.0 (20 November 2026)
|
# 2.35.0 (27 November 2026)
|
||||||
- #1544 Depend on Microsoft.AspNetCore.App for .NET 8 and .NET 10 [dependencies]
|
- #1552 Upgrade NJsonSchema.Extensions & NSwag.Core [dependencies]
|
||||||
- #1545 Upgrade ProtoBufJsonConverter to latest [dependencies]
|
|
||||||
- #1547 Test Testcontainers ConsoleApp on Linux [bug]
|
|
||||||
- #1548 Upgrade ProtoBufJsonConverter to latest [dependencies]
|
|
||||||
- #1546 WireMock.Net.Testcontainers isn't compatible with Testcontainers 4.17.0 [bug]
|
|
||||||
|
|
||||||
The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md
|
The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
@@ -21,7 +21,7 @@ A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) w
|
|||||||
* GraphQL support
|
* GraphQL support
|
||||||
* gRPC / ProtoBuf support
|
* gRPC / ProtoBuf support
|
||||||
* OpenAPI support
|
* OpenAPI support
|
||||||
* OpenTelemetry support
|
* [OpenTelemetry support](src/WireMock.Net.OpenTelemetry/README.md), including configurable service names for standalone and Docker instances
|
||||||
* WebSockets support
|
* WebSockets support
|
||||||
|
|
||||||
## :memo: Blogs
|
## :memo: Blogs
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ EndProject
|
|||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Tests", "test\WireMock.Net.Tests\WireMock.Net.Tests.csproj", "{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Tests", "test\WireMock.Net.Tests\WireMock.Net.Tests.csproj", "{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{985E0ADB-D4B4-473A-AA40-567E279B7946}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{985E0ADB-D4B4-473A-AA40-567E279B7946}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
examples\Issue1553.cs = examples\Issue1553.cs
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7EFB2C5B-1BB2-4AAF-BC9F-216ED80C594D}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7EFB2C5B-1BB2-4AAF-BC9F-216ED80C594D}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<MsBuildAllProjects>$(MsBuildAllProjects);$(MsBuildThisFileFullPath)</MsBuildAllProjects>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// #:package WireMock.Net@2.35.0
|
||||||
|
#:project ../src/WireMock.Net/WireMock.Net.csproj
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
|
using WireMock.Server;
|
||||||
|
|
||||||
|
static bool MimePluginLoaded() => AppDomain.CurrentDomain.GetAssemblies()
|
||||||
|
.Any(a => a.GetName().Name == "WireMock.Net.MimePart");
|
||||||
|
|
||||||
|
using var server = WireMockServer.Start();
|
||||||
|
server.Given(Request.Create().WithPath("/ping").UsingGet())
|
||||||
|
.RespondWith(Response.Create().WithStatusCode(200));
|
||||||
|
|
||||||
|
using var client = server.CreateClient();
|
||||||
|
Console.WriteLine($"Before GET: {MimePluginLoaded()}");
|
||||||
|
using var response = await client.GetAsync("/ping");
|
||||||
|
Console.WriteLine($"After GET ({(int)response.StatusCode}): {MimePluginLoaded()}");
|
||||||
@@ -21,6 +21,8 @@ public static class MainApp
|
|||||||
{
|
{
|
||||||
using var server = WireMockServer.Start(new WireMockServerSettings
|
using var server = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
|
PreloadMimeKitUtils = true,
|
||||||
|
|
||||||
Port = 9091,
|
Port = 9091,
|
||||||
StartAdminInterface = true,
|
StartAdminInterface = true,
|
||||||
|
|
||||||
|
|||||||
@@ -286,6 +286,9 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
var server = WireMockServer.Start(new WireMockServerSettings
|
var server = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
|
PreloadMimeKitUtils = true,
|
||||||
|
PreloadProtoBufUtils = true,
|
||||||
|
|
||||||
StartAdminInterface = true,
|
StartAdminInterface = true,
|
||||||
Logger = new WireMockConsoleLogger(),
|
Logger = new WireMockConsoleLogger(),
|
||||||
Port = 9091
|
Port = 9091
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="WireMock.Net" Version="2.30.0" />
|
<PackageReference Include="WireMock.Net" Version="2.34.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- CVE -->
|
<!-- CVE -->
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
<Version>2.3.14</Version>
|
<Version>2.3.14</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="WireMock.Net">
|
<PackageReference Include="WireMock.Net">
|
||||||
<Version>2.30.0</Version>
|
<Version>2.34.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
@@ -167,4 +168,11 @@ public interface IRequestMessage
|
|||||||
/// Gets the connection's client certificate
|
/// Gets the connection's client certificate
|
||||||
/// </summary>
|
/// </summary>
|
||||||
X509Certificate2? ClientCertificate { get; }
|
X509Certificate2? ClientCertificate { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the multipart MIME header, if present.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contentTypeHeader">When this method returns, contains the multipart MIME header values if found; otherwise, null.</param>
|
||||||
|
/// <returns>true if a multipart MIME header is found; otherwise, false.</returns>
|
||||||
|
bool TryGetMultipartMimeHeader([NotNullWhen(true)] out WireMockList<string>? contentTypeHeader);
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
@@ -27,45 +24,36 @@ internal class MimeKitUtils : IMimeKitUtils
|
|||||||
{
|
{
|
||||||
Guard.NotNull(requestMessage);
|
Guard.NotNull(requestMessage);
|
||||||
|
|
||||||
if (requestMessage.BodyData != null &&
|
if (!requestMessage.TryGetMultipartMimeHeader(out var contentTypeHeader))
|
||||||
requestMessage.Headers?.TryGetValue(HttpKnownHeaderNames.ContentType, out var contentTypeHeader) == true &&
|
|
||||||
StartsWithMultiPart(contentTypeHeader)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
byte[] bytes;
|
mimeMessageData = null;
|
||||||
|
return false;
|
||||||
switch (requestMessage.BodyData?.DetectedBodyType)
|
|
||||||
{
|
|
||||||
// If the body is bytes, use the BodyAsBytes to match on.
|
|
||||||
case BodyType.Bytes:
|
|
||||||
bytes = requestMessage.BodyData.BodyAsBytes!;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// If the body is a String or MultiPart, use the BodyAsString to match on.
|
|
||||||
case BodyType.String or BodyType.MultiPart:
|
|
||||||
bytes = Encoding.UTF8.GetBytes(requestMessage.BodyData.BodyAsString!);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Else return false.
|
|
||||||
default:
|
|
||||||
mimeMessageData = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fixedBytes = PrependContentTypeHeader(bytes, contentTypeHeader[0]);
|
|
||||||
|
|
||||||
mimeMessageData = LoadFromStream(new MemoryStream(fixedBytes));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mimeMessageData = null;
|
byte[] bytes;
|
||||||
return false;
|
switch (requestMessage.BodyData?.DetectedBodyType)
|
||||||
}
|
{
|
||||||
|
// If the body is bytes, use the BodyAsBytes to match on.
|
||||||
|
case BodyType.Bytes:
|
||||||
|
bytes = requestMessage.BodyData.BodyAsBytes!;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// If the body is a String or MultiPart, use the BodyAsString to match on.
|
||||||
|
case BodyType.String or BodyType.MultiPart:
|
||||||
|
bytes = Encoding.UTF8.GetBytes(requestMessage.BodyData.BodyAsString!);
|
||||||
|
break;
|
||||||
|
|
||||||
private static bool StartsWithMultiPart(WireMockList<string> contentTypeHeader)
|
// Else return false.
|
||||||
{
|
default:
|
||||||
return contentTypeHeader.Any(ct => ct.TrimStart().StartsWith("multipart/", StringComparison.OrdinalIgnoreCase));
|
mimeMessageData = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fixedBytes = PrependContentTypeHeader(bytes, contentTypeHeader[0]);
|
||||||
|
|
||||||
|
using var stream = new MemoryStream(fixedBytes);
|
||||||
|
mimeMessageData = LoadFromStream(stream);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
// 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.
|
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
||||||
using System.Linq;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
|
using WireMock.Http;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
|
using WireMock.Models.Mime;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
@@ -171,7 +173,8 @@ public class RequestMessage : IRequestMessage
|
|||||||
QueryIgnoreCase = new Dictionary<string, WireMockList<string>>(Query, StringComparer.OrdinalIgnoreCase);
|
QueryIgnoreCase = new Dictionary<string, WireMockList<string>>(Query, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
ClientCertificate = clientCertificate;
|
ClientCertificate = clientCertificate;
|
||||||
if (TypeLoader.TryLoadStaticInstance<IMimeKitUtils>(out var mimeKitUtils) && mimeKitUtils.TryGetMimeMessage(this, out var mimeMessage))
|
|
||||||
|
if (TryLoadBodyAsMimeMessage(out var mimeMessage))
|
||||||
{
|
{
|
||||||
BodyAsMimeMessage = mimeMessage;
|
BodyAsMimeMessage = mimeMessage;
|
||||||
}
|
}
|
||||||
@@ -188,4 +191,31 @@ public class RequestMessage : IRequestMessage
|
|||||||
var query = !ignoreCase ? Query : new Dictionary<string, WireMockList<string>>(Query, StringComparer.OrdinalIgnoreCase);
|
var query = !ignoreCase ? Query : new Dictionary<string, WireMockList<string>>(Query, StringComparer.OrdinalIgnoreCase);
|
||||||
return query.TryGetValue(key, out var value) ? value : null;
|
return query.TryGetValue(key, out var value) ? value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool TryGetMultipartMimeHeader([NotNullWhen(true)] out WireMockList<string>? contentTypeHeader)
|
||||||
|
{
|
||||||
|
if (BodyData != null &&
|
||||||
|
Headers?.TryGetValue(HttpKnownHeaderNames.ContentType, out contentTypeHeader) == true &&
|
||||||
|
contentTypeHeader.Any(ct => ct.TrimStart().StartsWith("multipart/", StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
contentTypeHeader = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryLoadBodyAsMimeMessage([NotNullWhen(true)] out IMimeMessageData? mimeMessage)
|
||||||
|
{
|
||||||
|
if (TryGetMultipartMimeHeader(out _) &&
|
||||||
|
TypeLoader.TryLoadStaticInstance<IMimeKitUtils>(out var mimeKitUtils) &&
|
||||||
|
mimeKitUtils.TryGetMimeMessage(this, out mimeMessage))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mimeMessage = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -366,6 +366,18 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
_settings.Logger.Info("By Stef Heyenrath (https://github.com/wiremock/WireMock.Net)");
|
_settings.Logger.Info("By Stef Heyenrath (https://github.com/wiremock/WireMock.Net)");
|
||||||
_settings.Logger.Debug("Server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
_settings.Logger.Debug("Server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||||
|
|
||||||
|
if (settings.PreloadMimeKitUtils == true)
|
||||||
|
{
|
||||||
|
_settings.Logger.Info("Preloading MimeKitUtils");
|
||||||
|
TypeLoader.TryLoadStaticInstance<IMimeKitUtils>(out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.PreloadProtoBufUtils == true)
|
||||||
|
{
|
||||||
|
_settings.Logger.Info("Preloading ProtoBufUtils");
|
||||||
|
TypeLoader.TryLoadStaticInstance<IProtoBufUtils>(out _);
|
||||||
|
}
|
||||||
|
|
||||||
HostUrlOptions urlOptions;
|
HostUrlOptions urlOptions;
|
||||||
if (settings.Urls != null)
|
if (settings.Urls != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ public static class WireMockServerSettingsParser
|
|||||||
HandleRequestsSynchronously = parser.GetBoolValue(nameof(WireMockServerSettings.HandleRequestsSynchronously)),
|
HandleRequestsSynchronously = parser.GetBoolValue(nameof(WireMockServerSettings.HandleRequestsSynchronously)),
|
||||||
HostingScheme = parser.GetEnumValue<HostingScheme>(nameof(WireMockServerSettings.HostingScheme)),
|
HostingScheme = parser.GetEnumValue<HostingScheme>(nameof(WireMockServerSettings.HostingScheme)),
|
||||||
MaxRequestLogCount = parser.GetIntValue(nameof(WireMockServerSettings.MaxRequestLogCount)),
|
MaxRequestLogCount = parser.GetIntValue(nameof(WireMockServerSettings.MaxRequestLogCount)),
|
||||||
|
PreloadMimeKitUtils = parser.GetBoolValue(nameof(WireMockServerSettings.PreloadMimeKitUtils)),
|
||||||
|
PreloadProtoBufUtils = parser.GetBoolValue(nameof(WireMockServerSettings.PreloadProtoBufUtils)),
|
||||||
QueryParameterMultipleValueSupport = parser.GetEnumValue<QueryParameterMultipleValueSupport>(nameof(WireMockServerSettings.QueryParameterMultipleValueSupport)),
|
QueryParameterMultipleValueSupport = parser.GetEnumValue<QueryParameterMultipleValueSupport>(nameof(WireMockServerSettings.QueryParameterMultipleValueSupport)),
|
||||||
ReadStaticMappings = parser.GetBoolValue(nameof(WireMockServerSettings.ReadStaticMappings)),
|
ReadStaticMappings = parser.GetBoolValue(nameof(WireMockServerSettings.ReadStaticMappings)),
|
||||||
RequestLogExpirationDuration = parser.GetIntValue(nameof(WireMockServerSettings.RequestLogExpirationDuration)),
|
RequestLogExpirationDuration = parser.GetIntValue(nameof(WireMockServerSettings.RequestLogExpirationDuration)),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>Minimal version from the lightweight Http Mocking Server for .NET</Description>
|
<Description>Minimal version from the lightweight Http Mocking Server for .NET</Description>
|
||||||
<AssemblyTitle>WireMock.Net.Minimal</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.Minimal</AssemblyTitle>
|
||||||
@@ -38,12 +38,12 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="JmesPath.Net" Version="1.1.0" />
|
<PackageReference Include="JmesPath.Net" Version="1.1.0" />
|
||||||
<PackageReference Include="NJsonSchema.Extensions" Version="0.2.0" />
|
<PackageReference Include="NJsonSchema.Extensions" Version="0.3.0" />
|
||||||
<PackageReference Include="NSwag.Core" Version="13.16.1" />
|
<PackageReference Include="NSwag.Core" Version="14.8.0" />
|
||||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||||
<PackageReference Include="TinyMapper.Signed" Version="4.0.0" />
|
<PackageReference Include="TinyMapper.Signed" Version="4.0.0" />
|
||||||
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.34.0" />
|
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.23.0" />
|
||||||
<PackageReference Include="Scriban.Signed" Version="7.5.3" />
|
<PackageReference Include="Scriban.Signed" Version="7.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -57,8 +57,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.3.9" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.3.14" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.3.9" />
|
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.3.14" />
|
||||||
|
<PackageReference Include="Required" Version="1.0.0" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ namespace WireMock.OpenTelemetry;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpenTelemetryOptions
|
public class OpenTelemetryOptions
|
||||||
{
|
{
|
||||||
|
internal const string DefaultActivitySourceName = "WireMock.Net";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the activity source name to subscribe to and the exported service name.
|
||||||
|
/// Default is <c>WireMock.Net</c>.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public string ActivitySourceName { get; set; } = DefaultActivitySourceName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether to exclude admin interface requests from ASP.NET Core instrumentation.
|
/// Gets or sets a value indicating whether to exclude admin interface requests from ASP.NET Core instrumentation.
|
||||||
/// Default is <c>true</c>.
|
/// Default is <c>true</c>.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ public static class OpenTelemetryOptionsParser
|
|||||||
/// <param name="environment">The environment settings (optional)</param>
|
/// <param name="environment">The environment settings (optional)</param>
|
||||||
/// <param name="options">The parsed options, or null if OpenTelemetry is not enabled</param>
|
/// <param name="options">The parsed options, or null if OpenTelemetry is not enabled</param>
|
||||||
/// <returns>Always returns true.</returns>
|
/// <returns>Always returns true.</returns>
|
||||||
public static bool TryParseArguments(string[] args, IDictionary? environment, out OpenTelemetryOptions? options)
|
public static bool TryParseArguments(string[] args, IDictionary? environment, [NotNullWhen(true)] out OpenTelemetryOptions? options)
|
||||||
{
|
{
|
||||||
Guard.HasNoNulls(args);
|
Guard.HasNoNulls(args);
|
||||||
|
|
||||||
@@ -30,11 +31,13 @@ public static class OpenTelemetryOptionsParser
|
|||||||
if (!parser.GetBoolValue($"{Prefix}Enabled"))
|
if (!parser.GetBoolValue($"{Prefix}Enabled"))
|
||||||
{
|
{
|
||||||
options = null;
|
options = null;
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var activitySourceName = parser.GetStringValue($"{Prefix}ActivitySourceName");
|
||||||
options = new OpenTelemetryOptions
|
options = new OpenTelemetryOptions
|
||||||
{
|
{
|
||||||
|
ActivitySourceName = string.IsNullOrWhiteSpace(activitySourceName) ? OpenTelemetryOptions.DefaultActivitySourceName : activitySourceName!,
|
||||||
ExcludeAdminRequests = parser.GetBoolValue($"{Prefix}ExcludeAdminRequests", defaultValue: true),
|
ExcludeAdminRequests = parser.GetBoolValue($"{Prefix}ExcludeAdminRequests", defaultValue: true),
|
||||||
OtlpExporterEndpoint = parser.GetStringValue($"{Prefix}OtlpExporterEndpoint")
|
OtlpExporterEndpoint = parser.GetStringValue($"{Prefix}OtlpExporterEndpoint")
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using WireMock.Settings;
|
|||||||
|
|
||||||
var openTelemetryOptions = new OpenTelemetryOptions
|
var openTelemetryOptions = new OpenTelemetryOptions
|
||||||
{
|
{
|
||||||
|
ActivitySourceName = "MyService",
|
||||||
ExcludeAdminRequests = true,
|
ExcludeAdminRequests = true,
|
||||||
OtlpExporterEndpoint = "http://localhost:4317" // Your OTEL collector
|
OtlpExporterEndpoint = "http://localhost:4317" // Your OTEL collector
|
||||||
};
|
};
|
||||||
@@ -64,7 +65,7 @@ var openTelemetryOptions = new OpenTelemetryOptions();
|
|||||||
|
|
||||||
// Configure your own TracerProvider
|
// Configure your own TracerProvider
|
||||||
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||||
.AddWireMockInstrumentation(openTelemetryOptions) // Adds WireMock.Net source
|
.AddWireMockInstrumentation(openTelemetryOptions) // Adds WireMock.Net and the configured source
|
||||||
.AddOtlpExporter(options =>
|
.AddOtlpExporter(options =>
|
||||||
{
|
{
|
||||||
options.Endpoint = new Uri("http://localhost:4317");
|
options.Endpoint = new Uri("http://localhost:4317");
|
||||||
@@ -83,7 +84,8 @@ services.AddWireMockOpenTelemetry(openTelemetryOptions);
|
|||||||
```
|
```
|
||||||
|
|
||||||
This configures:
|
This configures:
|
||||||
- The WireMock.Net ActivitySource
|
- The WireMock.Net ActivitySource and the configured ActivitySource
|
||||||
|
- A resource with the configured service name
|
||||||
- ASP.NET Core instrumentation
|
- ASP.NET Core instrumentation
|
||||||
- OTLP exporter (using the endpoint from `OpenTelemetryOptions.OtlpExporterEndpoint` or the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable)
|
- OTLP exporter (using the endpoint from `OpenTelemetryOptions.OtlpExporterEndpoint` or the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable)
|
||||||
|
|
||||||
@@ -101,9 +103,12 @@ tracerProvider.AddWireMockInstrumentation(openTelemetryOptions);
|
|||||||
|
|
||||||
| Property | Description | Default |
|
| Property | Description | Default |
|
||||||
|----------|-------------|---------|
|
|----------|-------------|---------|
|
||||||
|
| `ActivitySourceName` | Additional ActivitySource to subscribe to and service name for `AddWireMockOpenTelemetry` | `WireMock.Net` |
|
||||||
| `ExcludeAdminRequests` | Exclude `/__admin/*` from ASP.NET Core instrumentation | `true` |
|
| `ExcludeAdminRequests` | Exclude `/__admin/*` from ASP.NET Core instrumentation | `true` |
|
||||||
| `OtlpExporterEndpoint` | OTLP collector endpoint URL | Uses `OTEL_EXPORTER_OTLP_ENDPOINT` env var |
|
| `OtlpExporterEndpoint` | OTLP collector endpoint URL | Uses `OTEL_EXPORTER_OTLP_ENDPOINT` env var |
|
||||||
|
|
||||||
|
WireMock's own activities always use the `WireMock.Net` source, which remains subscribed even when a different source is configured. `AddWireMockInstrumentation` only configures instrumentation; configure its resource separately if you need a custom service name.
|
||||||
|
|
||||||
### ActivityTracingOptions (Trace content configuration)
|
### ActivityTracingOptions (Trace content configuration)
|
||||||
|
|
||||||
Configured in `WireMockServerSettings.ActivityTracingOptions`:
|
Configured in `WireMockServerSettings.ActivityTracingOptions`:
|
||||||
@@ -150,11 +155,14 @@ When using WireMock.Net.StandAlone or Docker images, activity tracing and OpenTe
|
|||||||
**OpenTelemetry Export (where traces are sent):**
|
**OpenTelemetry Export (where traces are sent):**
|
||||||
```bash
|
```bash
|
||||||
--OpenTelemetryEnabled true
|
--OpenTelemetryEnabled true
|
||||||
|
--OpenTelemetryActivitySourceName MyService
|
||||||
--OpenTelemetryOtlpExporterEndpoint http://localhost:4317
|
--OpenTelemetryOtlpExporterEndpoint http://localhost:4317
|
||||||
--OpenTelemetryExcludeAdminRequests true
|
--OpenTelemetryExcludeAdminRequests true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For Docker or standalone environment configuration, set `WireMockServerSettings__OpenTelemetryEnabled=true` and `WireMockServerSettings__OpenTelemetryActivitySourceName=MyService`. The activity source name defaults to `WireMock.Net` when omitted or empty.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- .NET 6.0 or later
|
- .NET 8.0 or later
|
||||||
- WireMock.Net 1.6.0 or later
|
- WireMock.Net 1.6.0 or later
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>OpenTelemetry exporter support for WireMock.Net</Description>
|
<Description>OpenTelemetry exporter support for WireMock.Net</Description>
|
||||||
<AssemblyTitle>WireMock.Net.OpenTelemetry</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.OpenTelemetry</AssemblyTitle>
|
||||||
<Authors>Petr Houška</Authors>
|
<Authors>Petr Houška, Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>netstandard2.0;net8.0;net10.0</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;net8.0;net10.0</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<RootNamespace>WireMock.OpenTelemetry</RootNamespace>
|
<RootNamespace>WireMock.OpenTelemetry</RootNamespace>
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ namespace WireMock.OpenTelemetry;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WireMockOpenTelemetryExtensions
|
public static class WireMockOpenTelemetryExtensions
|
||||||
{
|
{
|
||||||
private const string ServiceName = "WireMock.Net";
|
|
||||||
private const string WireMockActivitySourceName = "WireMock.Net";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds OpenTelemetry tracing to the WireMock server with instrumentation and OTLP exporter.
|
/// Adds OpenTelemetry tracing to the WireMock server with instrumentation and OTLP exporter.
|
||||||
/// This configures:
|
/// This configures:
|
||||||
@@ -38,14 +35,14 @@ public static class WireMockOpenTelemetryExtensions
|
|||||||
.ConfigureResource(resource =>
|
.ConfigureResource(resource =>
|
||||||
{
|
{
|
||||||
resource.AddService(
|
resource.AddService(
|
||||||
serviceName: ServiceName,
|
serviceName: options.ActivitySourceName,
|
||||||
serviceVersion: typeof(WireMockOpenTelemetryExtensions).Assembly.GetName().Version?.ToString() ?? "unknown"
|
serviceVersion: typeof(WireMockOpenTelemetryExtensions).Assembly.GetName().Version?.ToString() ?? "unknown"
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.WithTracing(tracing =>
|
.WithTracing(tracing =>
|
||||||
{
|
{
|
||||||
// Add WireMock-specific traces
|
// Add WireMock-specific traces
|
||||||
tracing.AddSource(WireMockActivitySourceName);
|
tracing.AddSource(OpenTelemetryOptions.DefaultActivitySourceName, options.ActivitySourceName);
|
||||||
|
|
||||||
// Add ASP.NET Core instrumentation for standard HTTP server traces
|
// Add ASP.NET Core instrumentation for standard HTTP server traces
|
||||||
tracing.AddAspNetCoreInstrumentation(aspNetOptions =>
|
tracing.AddAspNetCoreInstrumentation(aspNetOptions =>
|
||||||
@@ -93,7 +90,7 @@ public static class WireMockOpenTelemetryExtensions
|
|||||||
OpenTelemetryOptions? options = null)
|
OpenTelemetryOptions? options = null)
|
||||||
{
|
{
|
||||||
// Add WireMock-specific traces
|
// Add WireMock-specific traces
|
||||||
tracing.AddSource(WireMockActivitySourceName);
|
tracing.AddSource(OpenTelemetryOptions.DefaultActivitySourceName, options?.ActivitySourceName ?? OpenTelemetryOptions.DefaultActivitySourceName);
|
||||||
|
|
||||||
// Add ASP.NET Core instrumentation for standard HTTP server traces
|
// Add ASP.NET Core instrumentation for standard HTTP server traces
|
||||||
tracing.AddAspNetCoreInstrumentation(aspNetOptions =>
|
tracing.AddAspNetCoreInstrumentation(aspNetOptions =>
|
||||||
|
|||||||
@@ -63,6 +63,20 @@ public class WireMockServerSettings
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool? ReadStaticMappings { get; set; }
|
public bool? ReadStaticMappings { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Preload MimeKit utilities during server startup.
|
||||||
|
/// Default is <c>false</c>. Set to <c>true</c> to improve performance for the first request with a multipart MIME body.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public bool? PreloadMimeKitUtils { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Preload ProtoBuf utilities during server startup.
|
||||||
|
/// Default is <c>false</c>. Set to <c>true</c> to improve performance for the first ProtoBuf request.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public bool? PreloadProtoBufUtils { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Watch the static mapping files + folder for changes when running.
|
/// Watch the static mapping files + folder for changes when running.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
|
||||||
<PackageReference Include="WireMock.Net" Version="2.31.0" />
|
<PackageReference Include="WireMock.Net" Version="2.34.0" />
|
||||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace WireMock.Net.Tests.Matchers;
|
|||||||
|
|
||||||
public class MimePartMatcherTests
|
public class MimePartMatcherTests
|
||||||
{
|
{
|
||||||
private static readonly IMimeKitUtils MimeKitUtils = new MimeKitUtils();
|
private static readonly MimeKitUtils MimeKitUtils = new();
|
||||||
|
|
||||||
private const string TestMultiPart =
|
private const string TestMultiPart =
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
using WireMock.OpenTelemetry;
|
using WireMock.OpenTelemetry;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.OpenTelemetry;
|
namespace WireMock.Net.Tests.OpenTelemetry;
|
||||||
@@ -13,6 +14,7 @@ public class OpenTelemetryOptionsParserTests
|
|||||||
var result = OpenTelemetryOptionsParser.TryParseArguments(
|
var result = OpenTelemetryOptionsParser.TryParseArguments(
|
||||||
[
|
[
|
||||||
"--OpenTelemetryEnabled", "true",
|
"--OpenTelemetryEnabled", "true",
|
||||||
|
"--OpenTelemetryActivitySourceName", "MyService",
|
||||||
"--OpenTelemetryExcludeAdminRequests", "false",
|
"--OpenTelemetryExcludeAdminRequests", "false",
|
||||||
"--OpenTelemetryOtlpExporterEndpoint", "http://localhost:4317"
|
"--OpenTelemetryOtlpExporterEndpoint", "http://localhost:4317"
|
||||||
], null, out var options);
|
], null, out var options);
|
||||||
@@ -20,10 +22,40 @@ public class OpenTelemetryOptionsParserTests
|
|||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
options.Should().NotBeNull();
|
options.Should().NotBeNull();
|
||||||
options!.ExcludeAdminRequests.Should().BeFalse();
|
options.ActivitySourceName.Should().Be("MyService");
|
||||||
|
options.ExcludeAdminRequests.Should().BeFalse();
|
||||||
options.OtlpExporterEndpoint.Should().Be("http://localhost:4317");
|
options.OtlpExporterEndpoint.Should().Be("http://localhost:4317");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null)]
|
||||||
|
[InlineData("")]
|
||||||
|
[InlineData(" ")]
|
||||||
|
[InlineData("MyService")]
|
||||||
|
public void TryParseArguments_Environment_UsesConfiguredOrDefaultActivitySourceName(string? name)
|
||||||
|
{
|
||||||
|
var environment = new Hashtable
|
||||||
|
{
|
||||||
|
["WireMockServerSettings__OpenTelemetryEnabled"] = "true"
|
||||||
|
};
|
||||||
|
if (name is not null)
|
||||||
|
{
|
||||||
|
environment["WireMockServerSettings__OpenTelemetryActivitySourceName"] = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = OpenTelemetryOptionsParser.TryParseArguments([], environment, out var options);
|
||||||
|
|
||||||
|
result.Should().BeTrue();
|
||||||
|
options.Should().NotBeNull();
|
||||||
|
options.ActivitySourceName.Should().Be(string.IsNullOrWhiteSpace(name) ? "WireMock.Net" : name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OpenTelemetryOptions_DefaultActivitySourceName_IsWireMockNet()
|
||||||
|
{
|
||||||
|
new OpenTelemetryOptions().ActivitySourceName.Should().Be("WireMock.Net");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TryParseArguments_NotEnabled_ShouldReturnNull()
|
public void TryParseArguments_NotEnabled_ShouldReturnNull()
|
||||||
{
|
{
|
||||||
@@ -31,7 +63,7 @@ public class OpenTelemetryOptionsParserTests
|
|||||||
var result = OpenTelemetryOptionsParser.TryParseArguments(Array.Empty<string>(), null, out var options);
|
var result = OpenTelemetryOptionsParser.TryParseArguments(Array.Empty<string>(), null, out var options);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeFalse();
|
||||||
options.Should().BeNull();
|
options.Should().BeNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
using AwesomeAssertions;
|
using AwesomeAssertions;
|
||||||
|
using System.Diagnostics;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using OpenTelemetry;
|
||||||
|
using OpenTelemetry.Trace;
|
||||||
using WireMock.OpenTelemetry;
|
using WireMock.OpenTelemetry;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.OpenTelemetry;
|
namespace WireMock.Net.Tests.OpenTelemetry;
|
||||||
@@ -38,5 +41,52 @@ public class WireMockOpenTelemetryExtensionsTests
|
|||||||
result.Should().BeSameAs(services);
|
result.Should().BeSameAs(services);
|
||||||
services.Count.Should().BeGreaterThan(initialCount);
|
services.Count.Should().BeGreaterThan(initialCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("WireMock.Net")]
|
||||||
|
[InlineData("MyService")]
|
||||||
|
public void AddWireMockOpenTelemetry_UsesConfiguredServiceAndListensToSources(string name)
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var processor = new RecordingProcessor();
|
||||||
|
services.AddWireMockOpenTelemetry(new OpenTelemetryOptions { ActivitySourceName = name });
|
||||||
|
services.AddOpenTelemetry().WithTracing(builder => builder.AddProcessor(processor));
|
||||||
|
using var provider = services.BuildServiceProvider();
|
||||||
|
var tracerProvider = provider.GetRequiredService<TracerProvider>();
|
||||||
|
using var wireMockSource = new ActivitySource("WireMock.Net");
|
||||||
|
using var configuredSource = new ActivitySource(name);
|
||||||
|
|
||||||
|
wireMockSource.StartActivity("wiremock-test")?.Dispose();
|
||||||
|
configuredSource.StartActivity("configured-test")?.Dispose();
|
||||||
|
|
||||||
|
processor.Names.Should().Contain(["wiremock-test", "configured-test"]);
|
||||||
|
tracerProvider.GetResource().Attributes.Should().Contain(attribute => attribute.Key == "service.name" && (string)attribute.Value == name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null, "WireMock.Net")]
|
||||||
|
[InlineData("MyInstrumentation", "MyInstrumentation")]
|
||||||
|
public void AddWireMockInstrumentation_ListensToConfiguredAndWireMockSources(string? name, string expectedName)
|
||||||
|
{
|
||||||
|
var processor = new RecordingProcessor();
|
||||||
|
using var provider = Sdk.CreateTracerProviderBuilder()
|
||||||
|
.AddWireMockInstrumentation(name is null ? null : new OpenTelemetryOptions { ActivitySourceName = name })
|
||||||
|
.AddProcessor(processor)
|
||||||
|
.Build();
|
||||||
|
using var wireMockSource = new ActivitySource("WireMock.Net");
|
||||||
|
using var configuredSource = new ActivitySource(expectedName);
|
||||||
|
|
||||||
|
wireMockSource.StartActivity("wiremock-test")?.Dispose();
|
||||||
|
configuredSource.StartActivity("configured-test")?.Dispose();
|
||||||
|
|
||||||
|
processor.Names.Should().Contain(["wiremock-test", "configured-test"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class RecordingProcessor : BaseProcessor<Activity>
|
||||||
|
{
|
||||||
|
public List<string> Names { get; } = [];
|
||||||
|
|
||||||
|
public override void OnEnd(Activity data) => Names.Add(data.DisplayName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests;
|
namespace WireMock.Net.Tests;
|
||||||
|
|
||||||
@@ -82,4 +83,37 @@ public class RequestMessageTests
|
|||||||
request.GetParameter("key").Should().Contain("2");
|
request.GetParameter("key").Should().Contain("2");
|
||||||
request.GetParameter("key").Should().Contain("3");
|
request.GetParameter("key").Should().Contain("3");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessage_TryGetMultipartMimeHeader_WithMultipartContentType()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var contentType = " MULTIPART/form-data; boundary=boundary";
|
||||||
|
var body = new BodyData();
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", [contentType] } };
|
||||||
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, headers);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = request.TryGetMultipartMimeHeader(out var contentTypeHeader);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
contentTypeHeader.Should().ContainSingle(contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessage_TryGetMultipartMimeHeader_WithNonMultipartContentType()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var body = new BodyData();
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/json"] } };
|
||||||
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, headers);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = request.TryGetMultipartMimeHeader(out var contentTypeHeader);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeFalse();
|
||||||
|
contentTypeHeader.Should().BeNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,36 @@ public class WireMockServerSettingsParserTests
|
|||||||
settings!.AdminPath.Should().Be("/__admin");
|
settings!.AdminPath.Should().Be("/__admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TryParseArguments_With_PreloadMimeKitUtils()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var result = WireMockServerSettingsParser.TryParseArguments(new[]
|
||||||
|
{
|
||||||
|
"--PreloadMimeKitUtils", "true"
|
||||||
|
}, null, out var settings);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
settings.Should().NotBeNull();
|
||||||
|
settings!.PreloadMimeKitUtils.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TryParseArguments_With_PreloadProtoBufUtils()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var result = WireMockServerSettingsParser.TryParseArguments(new[]
|
||||||
|
{
|
||||||
|
"--PreloadProtoBufUtils", "true"
|
||||||
|
}, null, out var settings);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().BeTrue();
|
||||||
|
settings.Should().NotBeNull();
|
||||||
|
settings!.PreloadProtoBufUtils.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TryParseArguments_With_ActivityTracingEnabled_ShouldParseOptions()
|
public void TryParseArguments_With_ActivityTracingEnabled_ShouldParseOptions()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user