-
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.
InitialDesign for MAssert and modified Transition Test as an example …
…for the usage. Feel free to break the tests and switch between Assert.That and MAssert.That to see the effects. Fix wrongly translated example
- Loading branch information
1 parent
584cb93
commit 567633c
Showing
5 changed files
with
114 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