Skip to content

Commit

Permalink
Added new helper test method for XUnit (#233)
Browse files Browse the repository at this point in the history
* Added new helper test method

* moved to it's own file
  • Loading branch information
david-driscoll authored Jul 4, 2020
1 parent ec5aee8 commit 1e5faf3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 441 deletions.
437 changes: 0 additions & 437 deletions .editorconfig.ruleset

This file was deleted.

1 change: 1 addition & 0 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<PackageReference Update="NSubstitute" Version="4.2.2" />
<PackageReference Update="NSubstitute.Analyzers.CSharp" Version="1.0.13" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.abstractions" Version="2.0.3" />
<PackageReference Update="xunit.analyzers" Version="0.10.0" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.2" />
</ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions Testing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rocket.Surgery.Extensions.T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Extensions.Testing.NSubstitute", "src\Testing.NSubstitute\Rocket.Surgery.Extensions.Testing.NSubstitute.csproj", "{AFEE7BD7-6EAE-41F7-B2F6-0B3EB04F5D4D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Extensions.Testing.XUnit", "src\Testing.XUnit\Rocket.Surgery.Extensions.Testing.XUnit.csproj", "{88A55AFE-EDA6-410C-B576-8B960688D113}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -151,6 +153,18 @@ Global
{AFEE7BD7-6EAE-41F7-B2F6-0B3EB04F5D4D}.Release|x64.Build.0 = Release|Any CPU
{AFEE7BD7-6EAE-41F7-B2F6-0B3EB04F5D4D}.Release|x86.ActiveCfg = Release|Any CPU
{AFEE7BD7-6EAE-41F7-B2F6-0B3EB04F5D4D}.Release|x86.Build.0 = Release|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Debug|x64.ActiveCfg = Debug|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Debug|x64.Build.0 = Debug|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Debug|x86.ActiveCfg = Debug|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Debug|x86.Build.0 = Debug|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Release|Any CPU.Build.0 = Release|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Release|x64.ActiveCfg = Release|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Release|x64.Build.0 = Release|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Release|x86.ActiveCfg = Release|Any CPU
{88A55AFE-EDA6-410C-B576-8B960688D113}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -165,6 +179,7 @@ Global
{6016D53B-90FA-4223-BE4A-0CC6AB9CBD0A} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{961EE399-F31D-40A9-9559-F9568BCF5088} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{AFEE7BD7-6EAE-41F7-B2F6-0B3EB04F5D4D} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{88A55AFE-EDA6-410C-B576-8B960688D113} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {439897C2-CCBD-44FE-B2DC-A3E4670ADA59}
Expand Down
10 changes: 10 additions & 0 deletions src/Testing.XUnit/Rocket.Surgery.Extensions.Testing.XUnit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsTestProject>false</IsTestProject>
<RootNamespace>Rocket.Surgery.Extensions.Testing</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit.abstractions" />
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions src/Testing.XUnit/XUnitExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Reflection;
using Xunit.Abstractions;

// ReSharper disable once CheckNamespace
namespace xunit
{
/// <summary>
/// Helpful XUnit Extensions
/// </summary>
public static class XUnitExtensions
{
/// <summary>
/// Gets the test from the ITestOutputHelper
/// </summary>
/// <param name="output"></param>
/// <returns></returns>
public static ITest GetTest(this ITestOutputHelper output)
{
var type = output.GetType();
var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
return (ITest)testMember.GetValue(output);
}
}
}
9 changes: 5 additions & 4 deletions test/Testing.Tests/LoggerTestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Serilog.Events;
using Xunit;
using Xunit.Abstractions;

#pragma warning disable CA1034 // Nested types should not be visible
#pragma warning disable CA2000 // Dispose objects before losing scope
#pragma warning disable CA1062 // Validate arguments of public methods
Expand Down Expand Up @@ -79,10 +80,10 @@ public class LoggerTheoryCollection : TheoryCollection<(IEnumerable<string>, int
{
protected override IEnumerable<(IEnumerable<string>, int)> GetData()
{
yield return (new[] { "1", "2", "3" }, 3);
yield return (new[] { "1", "2" }, 2);
yield return (new[] { "1" }, 1);
yield return ( new[] { "1", "2", "3" }, 3 );
yield return ( new[] { "1", "2" }, 2 );
yield return ( new[] { "1" }, 1 );
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<ProjectReference Include="..\..\src\Testing.NSubstitute\Rocket.Surgery.Extensions.Testing.NSubstitute.csproj" />
<ProjectReference Include="..\..\src\Testing.XUnit\Rocket.Surgery.Extensions.Testing.XUnit.csproj" />
<ProjectReference Include="..\..\src\Testing\Rocket.Surgery.Extensions.Testing.csproj" />
<ProjectReference Include="..\..\src\Testing.Moq\Rocket.Surgery.Extensions.Testing.Moq.csproj" />
<ProjectReference Include="..\..\src\Testing.FakeItEasy\Rocket.Surgery.Extensions.Testing.FakeItEasy.csproj" />
Expand Down
25 changes: 25 additions & 0 deletions test/Testing.Tests/XUnitExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using FluentAssertions;
using xunit;
using Xunit;
using Xunit.Abstractions;

namespace Rocket.Surgery.Extensions.Testing.Tests
{
public class XUnitExtensionsTests : LoggerTest
{
private readonly ITestOutputHelper _outputHelper;

public XUnitExtensionsTests(ITestOutputHelper outputHelper) : base(outputHelper)
{
_outputHelper = outputHelper;
}

[Fact]
public void GetTestTest()
{
var test = _outputHelper.GetTest();
test.Should().NotBeNull();
test.DisplayName.Should().Be("Rocket.Surgery.Extensions.Testing.Tests.XUnitExtensionsTests.GetTestTest");
}
}
}

0 comments on commit 1e5faf3

Please sign in to comment.