Skip to content

Commit

Permalink
Consolidate custom Assert classes into ancillary assembly (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpassing authored Mar 10, 2024
1 parent 4b2326f commit e022e03
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ namespace NUnit.Framework
/// <summary>
/// Alias for NUnit 3-style assertion.
/// </summary>
internal class AssertThat : ClassicAssert
public class AssertThat : ClassicAssert
{
}

/// <summary>
/// Alias for NUnit 3-style assertion.
/// </summary>
internal class CollectionAssertThat : CollectionAssert
public class CollectionAssertThat : CollectionAssert
{ }

/// <summary>
/// Alias for NUnit 3-style assertion.
/// </summary>
internal class StringAssertThat : StringAssert
public class StringAssertThat : StringAssert
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,10 @@
using System;
using System.Reflection;

namespace Jpki.Test
namespace NUnit.Framework
{
internal static class AssertThrows
public static class AssertThrows
{
public static TActual? AggregateException<TActual>(TestDelegate code) where TActual : Exception
{
return AssertThat.Throws<TActual>(() =>
{
try
{
code();
}
catch (AggregateException e)
{
throw e.Unwrap();
}
});
}

private static Exception Unwrap(this Exception e)
{
if (e is AggregateException aggregate &&
Expand All @@ -59,5 +44,20 @@ private static Exception Unwrap(this Exception e)
return e;
}
}

public static TActual? AggregateException<TActual>(TestDelegate code) where TActual : Exception
{
return AssertThat.Throws<TActual>(() =>
{
try
{
code();
}
catch (AggregateException e)
{
throw e.Unwrap();
}
});
}
}
}
7 changes: 7 additions & 0 deletions sources/Jpki.NUnit/Jpki.NUnit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Jpki.props" />

<ItemGroup>
<PackageReference Include="NUnit" Version="4.0.1" />
</ItemGroup>
</Project>
46 changes: 0 additions & 46 deletions sources/Jpki.Powershell.Test/AssertThrows.cs

This file was deleted.

1 change: 1 addition & 0 deletions sources/Jpki.Powershell.Test/Jpki.Powershell.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

<ItemGroup>
<ProjectReference Include="..\Jpki.Powershell\Jpki.Powershell.csproj" />
<ProjectReference Include="..\Jpki.Nunit\Jpki.NUnit.csproj" />
</ItemGroup>
</Project>
44 changes: 0 additions & 44 deletions sources/Jpki.Security.Cryptography.Test/AssertThat.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jpki.Security.Cryptography\Jpki.Security.Cryptography.csproj" />
<ProjectReference Include="..\Jpki.Nunit\Jpki.NUnit.csproj" />
</ItemGroup>
</Project>
44 changes: 0 additions & 44 deletions sources/Jpki.Security.WebAuthn.Test/AssertThat.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\Jpki.Security.WebAuthn\Jpki.Security.WebAuthn.csproj" />
<ProjectReference Include="..\Jpki.Nunit\Jpki.NUnit.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions sources/Jpki.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jpki.Security.WebAuthn.Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jpki.Build", "Jpki\Jpki.Build.csproj", "{83F04876-1B36-4153-9C7E-16AD531744C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jpki.Powershell", "Jpki.Powershell\Jpki.Powershell.csproj", "{04D7531B-574D-452A-9FA8-A10C20562C99}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jpki.Powershell", "Jpki.Powershell\Jpki.Powershell.csproj", "{04D7531B-574D-452A-9FA8-A10C20562C99}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jpki.Powershell.Test", "Jpki.Powershell.Test\Jpki.Powershell.Test.csproj", "{EF89FDD9-E35B-4B76-A726-9BBB4D3C1B1E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jpki.Powershell.Test", "Jpki.Powershell.Test\Jpki.Powershell.Test.csproj", "{EF89FDD9-E35B-4B76-A726-9BBB4D3C1B1E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jpki.NUnit", "Jpki.Nunit\Jpki.NUnit.csproj", "{80B66880-C413-43BF-8668-10BA6D342B4A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -59,6 +61,10 @@ Global
{EF89FDD9-E35B-4B76-A726-9BBB4D3C1B1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF89FDD9-E35B-4B76-A726-9BBB4D3C1B1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF89FDD9-E35B-4B76-A726-9BBB4D3C1B1E}.Release|Any CPU.Build.0 = Release|Any CPU
{80B66880-C413-43BF-8668-10BA6D342B4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80B66880-C413-43BF-8668-10BA6D342B4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80B66880-C413-43BF-8668-10BA6D342B4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80B66880-C413-43BF-8668-10BA6D342B4A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit e022e03

Please sign in to comment.