-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
428 additions
and
24 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
8 changes: 4 additions & 4 deletions
8
samples/current/SampleLibrary.Tests/SampleLibrary.Tests.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
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,172 @@ | ||
using MELT; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
|
||
namespace SampleLibraryX.Tests | ||
{ | ||
public class MoreTest | ||
{ | ||
[Fact] | ||
public void DoMoreLogsMessage() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.DoMore(); | ||
|
||
// Assert | ||
Assert.Collection(loggerFactory.Sink.LogEntries, | ||
l => Assert.Equal("More is less.", l.Message), | ||
l => Assert.Equal("The answer is 42", l.Message)); | ||
} | ||
|
||
[Fact] | ||
public void DoMoreLogsMessage_NotCheckingNested() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(options => options.FilterByTypeName<More>()); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.DoMore(); | ||
|
||
// Assert | ||
var log = Assert.Single(loggerFactory.Sink.LogEntries); | ||
Assert.Equal("More is less.", log.Message); | ||
} | ||
|
||
[Fact] | ||
public void DoMoreLogsFormat_NotCheckingNested() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(options => options.FilterByTypeName<More>()); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.DoMore(); | ||
|
||
// Assert | ||
var log = Assert.Single(loggerFactory.Sink.LogEntries); | ||
Assert.Equal("More is less.", log.OriginalFormat); | ||
} | ||
|
||
[Fact] | ||
public void DoEvenMoreLogsCorrectParameters() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
|
||
// Act | ||
more.DoEvenMore(); | ||
|
||
// Assert | ||
var log = Assert.Single(loggerFactory.Sink.LogEntries); | ||
// Assert specific parameters in the log entry | ||
LoggingAssert.Contains("number", 42, log.Properties); | ||
LoggingAssert.Contains("foo", "bar", log.Properties); | ||
} | ||
|
||
[Fact] | ||
public void UseScopeLogsScope() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.UseScope(); | ||
|
||
// Assert | ||
Assert.Collection(loggerFactory.Sink.Scopes, | ||
scope => Assert.Equal("This scope's answer is 42", scope.Message)); | ||
} | ||
|
||
[Fact] | ||
public void UseScopeLogsCorrectParameters() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.UseScope(); | ||
|
||
// Assert | ||
var scope = Assert.Single(loggerFactory.Sink.Scopes); | ||
// Assert specific parameters in the log entry | ||
LoggingAssert.Contains("number", 42, scope.Properties); | ||
} | ||
|
||
[Fact] | ||
public void UseScopeLogsCorrectOriginalFormat() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.UseScope(); | ||
|
||
// Assert | ||
var scope = Assert.Single(loggerFactory.Sink.Scopes); | ||
// Assert specific parameters in the log entry | ||
Assert.Equal("This scope's answer is {number}", scope.OriginalFormat); | ||
} | ||
|
||
[Fact] | ||
public void UseLocalScopeLogsMessageWithScope() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.UseLocalScope(); | ||
|
||
// Assert | ||
var log = Assert.Single(loggerFactory.Sink.LogEntries); | ||
var scope = Assert.Single(log.Scopes); | ||
Assert.Equal("This scope's answer is 42", scope.Message); | ||
} | ||
|
||
[Fact] | ||
public void TraceLogsMessageWithScope() | ||
{ | ||
// Arrange | ||
var loggerFactory = TestLoggerFactory.Create(); | ||
var sampleLogger = loggerFactory.CreateLogger<Sample>(); | ||
var moreLogger = loggerFactory.CreateLogger<More>(); | ||
var more = new More(new Sample(sampleLogger), moreLogger); | ||
|
||
// Act | ||
more.Trace(); | ||
|
||
// Assert | ||
var log = Assert.Single(loggerFactory.Sink.LogEntries); | ||
Assert.Equal("This log entry is at trace level", log.Message); | ||
LoggingAssert.Contains("level", "trace", log.Properties); | ||
var scope = Assert.Single(log.Scopes); | ||
LoggingAssert.Contains("foo", "bar", scope.Properties); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
samples/xunit-2.4.2/SampleLibraryX.Tests/SampleLibraryX.Tests.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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\MELT.Xunit\MELT.Xunit.csproj" /> | ||
<ProjectReference Include="..\..\..\src\MELT\MELT.csproj" /> | ||
<ProjectReference Include="..\SampleLibraryX\SampleLibraryX.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.