Skip to content

Commit 37bad61

Browse files
authored
Add WireMock.Net.xUnit.v3 project (#1380)
* Add WireMock.Net.xUnit.v3 project * .
1 parent 8e69f36 commit 37bad61

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

WireMock.Net Solution.sln

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31521.260
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.0.11205.157 d18.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8F890C6F-9ACC-438D-928A-AD61CDA862F2}"
77
EndProject
@@ -144,6 +144,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Extensions.Rou
144144
EndProject
145145
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.ProtoBuf", "src\WireMock.Net.ProtoBuf\WireMock.Net.ProtoBuf.csproj", "{B47413AA-55D3-49A7-896A-17ADBFF72407}"
146146
EndProject
147+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.xUnit.v3", "src\WireMock.Net.xUnit.v3\WireMock.Net.xUnit.v3.csproj", "{4F46BD02-BEBC-4B2D-B857-4169AD1FB067}"
148+
EndProject
147149
Global
148150
GlobalSection(SolutionConfigurationPlatforms) = preSolution
149151
Debug|Any CPU = Debug|Any CPU
@@ -350,6 +352,10 @@ Global
350352
{B47413AA-55D3-49A7-896A-17ADBFF72407}.Debug|Any CPU.Build.0 = Debug|Any CPU
351353
{B47413AA-55D3-49A7-896A-17ADBFF72407}.Release|Any CPU.ActiveCfg = Release|Any CPU
352354
{B47413AA-55D3-49A7-896A-17ADBFF72407}.Release|Any CPU.Build.0 = Release|Any CPU
355+
{4F46BD02-BEBC-4B2D-B857-4169AD1FB067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
356+
{4F46BD02-BEBC-4B2D-B857-4169AD1FB067}.Debug|Any CPU.Build.0 = Debug|Any CPU
357+
{4F46BD02-BEBC-4B2D-B857-4169AD1FB067}.Release|Any CPU.ActiveCfg = Release|Any CPU
358+
{4F46BD02-BEBC-4B2D-B857-4169AD1FB067}.Release|Any CPU.Build.0 = Release|Any CPU
353359
EndGlobalSection
354360
GlobalSection(SolutionProperties) = preSolution
355361
HideSolutionNode = FALSE
@@ -407,6 +413,7 @@ Global
407413
{3FCBCA9C-9DB0-4A96-B47E-30470764CC9C} = {0BB8B634-407A-4610-A91F-11586990767A}
408414
{1E874C8F-08A2-493B-8421-619F9A6E9E77} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
409415
{B47413AA-55D3-49A7-896A-17ADBFF72407} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
416+
{4F46BD02-BEBC-4B2D-B857-4169AD1FB067} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
410417
EndGlobalSection
411418
GlobalSection(ExtensibilityGlobals) = postSolution
412419
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright © WireMock.Net
2+
3+
using System;
4+
using Newtonsoft.Json;
5+
using Stef.Validation;
6+
using WireMock.Admin.Requests;
7+
using WireMock.Logging;
8+
using Xunit;
9+
10+
namespace WireMock.Net.Xunit;
11+
12+
/// <summary>
13+
/// When using xUnit, this class enables to log the output from WireMock.Net to the <see cref="ITestOutputHelper"/>.
14+
/// </summary>
15+
public sealed class TestOutputHelperWireMockLogger : IWireMockLogger
16+
{
17+
private readonly ITestOutputHelper _testOutputHelper;
18+
19+
/// <summary>
20+
/// Create a new instance on the <see cref="TestOutputHelperWireMockLogger"/>.
21+
/// </summary>
22+
/// <param name="testOutputHelper">Represents a class which can be used to provide test output.</param>
23+
public TestOutputHelperWireMockLogger(ITestOutputHelper testOutputHelper)
24+
{
25+
_testOutputHelper = Guard.NotNull(testOutputHelper);
26+
}
27+
28+
/// <inheritdoc />
29+
public void Debug(string formatString, params object[] args)
30+
{
31+
_testOutputHelper.WriteLine(Format("Debug", formatString, args));
32+
}
33+
34+
/// <inheritdoc />
35+
public void Info(string formatString, params object[] args)
36+
{
37+
_testOutputHelper.WriteLine(Format("Info", formatString, args));
38+
}
39+
40+
/// <inheritdoc />
41+
public void Warn(string formatString, params object[] args)
42+
{
43+
_testOutputHelper.WriteLine(Format("Warning", formatString, args));
44+
}
45+
46+
/// <inheritdoc />
47+
public void Error(string formatString, params object[] args)
48+
{
49+
_testOutputHelper.WriteLine(Format("Error", formatString, args));
50+
}
51+
52+
/// <inheritdoc />
53+
public void Error(string message, Exception exception)
54+
{
55+
_testOutputHelper.WriteLine(Format("Error", $"{message} {{0}}", exception));
56+
57+
if (exception is AggregateException ae)
58+
{
59+
ae.Handle(ex =>
60+
{
61+
_testOutputHelper.WriteLine(Format("Error", "Exception {0}", ex));
62+
return true;
63+
});
64+
}
65+
}
66+
67+
/// <inheritdoc />
68+
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
69+
{
70+
var message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
71+
_testOutputHelper.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message));
72+
}
73+
74+
private static string Format(string level, string formatString, params object[] args)
75+
{
76+
var message = args.Length > 0 ? string.Format(formatString, args) : formatString;
77+
return $"{DateTime.UtcNow} [{level}] : {message}";
78+
}
79+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Description>Some extensions for xUnit (ITestOutputHelper)</Description>
4+
<AssemblyTitle>WireMock.Net.xUnit.v3</AssemblyTitle>
5+
<Authors>Stef Heyenrath</Authors>
6+
<TargetFrameworks>net472;net8.0</TargetFrameworks>
7+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8+
<PackageTags>tdd;wiremock;test;unittest;xunit</PackageTags>
9+
<ProjectGuid>{4F46BD02-BEBC-4B2D-B857-4169AD222267}</ProjectGuid>
10+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
11+
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
12+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
15+
<SignAssembly>true</SignAssembly>
16+
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
17+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
18+
</PropertyGroup>
19+
20+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
21+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
26+
<PackageReference Include="Stef.Validation" Version="0.2.0" />
27+
<PackageReference Include="xunit.v3.extensibility.core" Version="3.2.0" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<PackageReference Update="JetBrains.Annotations" Version="2025.2.2" />
36+
</ItemGroup>
37+
</Project>

0 commit comments

Comments
 (0)