-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WireMock.Net.TUnit project (#1179)
* Add WireMock.Net.TUnit project * fix * . * fix * bd * 0.1.812 * dotnet test * 0.1.817 * cat * type * type2 * find * -- --diagnostic * --no-build * fix?
- Loading branch information
Showing
8 changed files
with
198 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright © WireMock.Net | ||
|
||
using System; | ||
using Newtonsoft.Json; | ||
using Stef.Validation; | ||
using TUnit.Core.Logging; | ||
using WireMock.Admin.Requests; | ||
using WireMock.Logging; | ||
|
||
namespace WireMock.Net.TUnit; | ||
|
||
/// <summary> | ||
/// When using TUnit, this class enables to log the output from WireMock.Net to the <see cref="TUnitLogger"/>. | ||
/// </summary> | ||
// ReSharper disable once InconsistentNaming | ||
public sealed class TUnitWireMockLogger : IWireMockLogger | ||
{ | ||
private readonly TUnitLogger _tUnitLogger; | ||
|
||
/// <summary> | ||
/// Create a new instance on the <see cref="TUnitWireMockLogger"/>. | ||
/// </summary> | ||
/// <param name="tUnitLogger">Represents a class which can be used to provide test output.</param> | ||
public TUnitWireMockLogger(TUnitLogger tUnitLogger) | ||
{ | ||
_tUnitLogger = Guard.NotNull(tUnitLogger); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Debug(string formatString, params object[] args) | ||
{ | ||
_tUnitLogger.LogDebug(Format("Debug", formatString, args)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Info(string formatString, params object[] args) | ||
{ | ||
_tUnitLogger.LogInformation(Format("Info", formatString, args)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Warn(string formatString, params object[] args) | ||
{ | ||
_tUnitLogger.LogWarning(Format("Warning", formatString, args)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Error(string formatString, params object[] args) | ||
{ | ||
_tUnitLogger.LogError(Format("Error", formatString, args)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Error(string formatString, Exception exception) | ||
{ | ||
_tUnitLogger.LogError(Format("Error", formatString, exception.Message), exception); | ||
|
||
if (exception is AggregateException ae) | ||
{ | ||
ae.Handle(ex => | ||
{ | ||
_tUnitLogger.LogError(Format("Error", "Exception {0}", ex.Message), exception); | ||
return true; | ||
}); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) | ||
{ | ||
var message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented); | ||
_tUnitLogger.LogDebug(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); | ||
} | ||
|
||
private static string Format(string level, string formatString, params object[] args) | ||
{ | ||
var message = args.Length > 0 ? string.Format(formatString, args) : formatString; | ||
return $"{DateTime.UtcNow} [{level}] : {message}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Description>Some extensions for TUnit (TUnitLogger)</Description> | ||
<AssemblyTitle>WireMock.Net.TUnit</AssemblyTitle> | ||
<Authors>Stef Heyenrath</Authors> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<AssemblyName>WireMock.Net.TUnit</AssemblyName> | ||
<RootNamespace>WireMock.Net.Tunit</RootNamespace> | ||
<PackageId>WireMock.Net.TUnit</PackageId> | ||
<PackageTags>tdd;wiremock;test;unittest;TUnit</PackageTags> | ||
<ProjectGuid>{0DE0954F-8C00-4E8D-B94A-4361FC1CB34A}</ProjectGuid> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile> | ||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="Stef.Validation" Version="0.1.1" /> | ||
<PackageReference Include="TUnit.Core" Version="0.1.817" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright © WireMock.Net | ||
|
||
using WireMock.Net.TUnit; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
using WireMock.Server; | ||
using WireMock.Settings; | ||
|
||
namespace WireMock.Net.TUnitTests; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class TUnitTests | ||
{ | ||
[Test] | ||
public async Task Test_TUnitWireMockLogger() | ||
{ | ||
// Assign | ||
var path = $"/foo_{Guid.NewGuid()}"; | ||
|
||
using var server = WireMockServer.Start(new WireMockServerSettings | ||
{ | ||
Logger = new TUnitWireMockLogger(TestContext.Current!.GetDefaultLogger()) | ||
}); | ||
|
||
server | ||
.Given(Request.Create() | ||
.WithPath(path) | ||
.UsingGet()) | ||
.RespondWith(Response.Create().WithBody("TUnit")); | ||
|
||
// Act | ||
var response = await server.CreateClient().GetStringAsync($"{server.Url}{path}"); | ||
|
||
// Assert | ||
await Assert.That(response).IsEqualTo("TUnit"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/WireMock.Net.TUnitTests/WireMock.Net.TUnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="TUnit" Version="0.1.817" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\WireMock.Net.TUnit\WireMock.Net.TUnit.csproj" /> | ||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |