Skip to content

Commit

Permalink
Add support for Xunit 2.5.0 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
alefranz authored Aug 6, 2023
1 parent b4fbc54 commit dda76a4
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 24 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup .NET 5.0
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Install dotnet-format
run: dotnet tool install --global dotnet-format
- name: Format
run: dotnet format --check
run: dotnet format --verify-no-changes MELT.sln
build:
runs-on: ubuntu-latest
steps:
Expand All @@ -37,6 +37,10 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Build
run: dotnet build --configuration Release
- name: Test
Expand All @@ -48,10 +52,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup .NET 5.0
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Determine version
run: echo "VERSION=$(git describe --tags --dirty)" >> $GITHUB_ENV
- name: Pack
Expand All @@ -65,10 +69,10 @@ jobs:
needs: pack
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Setup .NET 5.0
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- uses: actions/download-artifact@v1
with:
name: artifacts
Expand Down
25 changes: 21 additions & 4 deletions MELT.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.89
# Visual Studio Version 17
VisualStudioVersion = 17.7.33927.210
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{49161A77-61F0-442B-8874-A5FF7D2368C2}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -75,9 +75,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApplication3_1", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApplication3_1.IntegrationTests", "samples\3.1\SampleWebApplication3_1.IntegrationTests\SampleWebApplication3_1.IntegrationTests.csproj", "{E37446E1-7760-4AD0-B703-B635454E5B3C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApplication", "samples\current\SampleWebApplication\SampleWebApplication.csproj", "{975360DF-04D6-41AB-84EE-3AE5D7A5B2DA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApplication", "samples\current\SampleWebApplication\SampleWebApplication.csproj", "{975360DF-04D6-41AB-84EE-3AE5D7A5B2DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApplication.IntegrationTests", "samples\current\SampleWebApplication.IntegrationTests\SampleWebApplication.IntegrationTests.csproj", "{008667F2-0263-4A13-B9F2-BA10D948EBDB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApplication.IntegrationTests", "samples\current\SampleWebApplication.IntegrationTests\SampleWebApplication.IntegrationTests.csproj", "{008667F2-0263-4A13-B9F2-BA10D948EBDB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "xunit-2.4.2", "xunit-2.4.2", "{ABCE4D92-5106-4849-BCD2-88472585C07F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleLibraryX", "samples\xunit-2.4.2\SampleLibraryX\SampleLibraryX.csproj", "{97C0C780-AF0B-4103-9315-002899C32BE8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleLibraryX.Tests", "samples\xunit-2.4.2\SampleLibraryX.Tests\SampleLibraryX.Tests.csproj", "{8990E486-C322-4741-97D0-94AA7D9F3323}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -181,6 +187,14 @@ Global
{008667F2-0263-4A13-B9F2-BA10D948EBDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{008667F2-0263-4A13-B9F2-BA10D948EBDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{008667F2-0263-4A13-B9F2-BA10D948EBDB}.Release|Any CPU.Build.0 = Release|Any CPU
{97C0C780-AF0B-4103-9315-002899C32BE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97C0C780-AF0B-4103-9315-002899C32BE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97C0C780-AF0B-4103-9315-002899C32BE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97C0C780-AF0B-4103-9315-002899C32BE8}.Release|Any CPU.Build.0 = Release|Any CPU
{8990E486-C322-4741-97D0-94AA7D9F3323}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8990E486-C322-4741-97D0-94AA7D9F3323}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8990E486-C322-4741-97D0-94AA7D9F3323}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8990E486-C322-4741-97D0-94AA7D9F3323}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -216,6 +230,9 @@ Global
{E37446E1-7760-4AD0-B703-B635454E5B3C} = {E77E65BC-8A95-4113-BB22-BE56D6226157}
{975360DF-04D6-41AB-84EE-3AE5D7A5B2DA} = {F08BF453-6A58-486F-8D06-FF08A82D386B}
{008667F2-0263-4A13-B9F2-BA10D948EBDB} = {F08BF453-6A58-486F-8D06-FF08A82D386B}
{ABCE4D92-5106-4849-BCD2-88472585C07F} = {B33EF166-2895-47CF-BF2C-740C271A250E}
{97C0C780-AF0B-4103-9315-002899C32BE8} = {ABCE4D92-5106-4849-BCD2-88472585C07F}
{8990E486-C322-4741-97D0-94AA7D9F3323} = {ABCE4D92-5106-4849-BCD2-88472585C07F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {954CCC12-511A-4435-AE51-C19A527D4654}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
172 changes: 172 additions & 0 deletions samples/xunit-2.4.2/SampleLibraryX.Tests/MoreTest.cs
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);
}
}
}
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>
Loading

0 comments on commit dda76a4

Please sign in to comment.