-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from andreniggemann/feat/nunitTestTools
Port NUnit Test Tools to release 8
- Loading branch information
Showing
5 changed files
with
115 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Constraints; | ||
using NUnit.Framework.Internal; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Runtime.CompilerServices; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
|
||
namespace Moryx.TestTools.NUnit | ||
{ | ||
public abstract class MAssert | ||
{ | ||
public static void That(bool condition, string? message = null, [CallerArgumentExpression(nameof(condition))] string? predicateExpression = null) | ||
{ | ||
That(condition, Is.True, message, predicateExpression); | ||
} | ||
public static void That(Func<bool> predicate, string? message = null, [CallerArgumentExpression(nameof(predicate))]string? predicateExpression = null) | ||
{ | ||
That(predicate, Is.True, message, predicateExpression); | ||
} | ||
|
||
public static void That<T>(T actual, IResolveConstraint constraint, string? message = null, [CallerArgumentExpression(nameof(actual))] string? predicateExpression = null) | ||
{ | ||
if (message != null) | ||
{ | ||
message = $"{message}\nExpression: {predicateExpression}"; | ||
} | ||
else | ||
{ | ||
message = predicateExpression; | ||
} | ||
Assert.That(actual, constraint, message); | ||
} | ||
|
||
public static void That<T>(Func<T> actualExpression, Constraint constraint, string? message = null, [CallerArgumentExpression(nameof(actualExpression))] string? predicateExpression = null) | ||
{ | ||
if (message != null) | ||
{ | ||
message = $"{message}\nExpression: {predicateExpression}"; | ||
} | ||
else | ||
{ | ||
message = predicateExpression; | ||
} | ||
int fails = TestExecutionContext.CurrentContext.CurrentResult.PendingFailures; | ||
T value = default(T)!; | ||
Assert.That<T>(() => value = actualExpression(), new ThrowsNothingConstraint(), $"{message}\nExpected {constraint.Description} and"); | ||
if (TestExecutionContext.CurrentContext.CurrentResult.PendingFailures > fails) return; // TODO: Check if we there could be multithreading issues and whether or not we care | ||
Assert.That(value, constraint, 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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NUnit" /> | ||
</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