Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion TUnit.Assertions/Conditions/DateTimeEqualsAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public DateTimeEqualsAssertion(
}

/// <summary>
/// ⚡ CUSTOM METHOD - No wrapper needed!
/// Specifies the acceptable tolerance for the comparison.
/// </summary>
public DateTimeEqualsAssertion Within(TimeSpan tolerance)
Expand Down
9 changes: 2 additions & 7 deletions TUnit.Assertions/Conditions/StringEqualsAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ namespace TUnit.Assertions.Conditions;
/// </summary>
public class StringEqualsAssertion : Assertion<string>
{
private readonly string _expected;
private readonly string? _expected;
private StringComparison _comparison = StringComparison.Ordinal;
private bool _trimming = false;
private bool _nullAndEmptyEquality = false;
private bool _ignoringWhitespace = false;

public StringEqualsAssertion(
AssertionContext<string> context,
string expected)
string? expected)
: base(context)
{
_expected = expected;
}

/// <summary>
/// ⚡ CUSTOM METHOD - No wrapper needed!
/// Makes the comparison case-insensitive.
/// </summary>
public StringEqualsAssertion IgnoringCase()
Expand All @@ -35,7 +34,6 @@ public StringEqualsAssertion IgnoringCase()
}

/// <summary>
/// ⚡ CUSTOM METHOD - No wrapper needed!
/// Specifies a custom string comparison type.
/// </summary>
public StringEqualsAssertion WithComparison(StringComparison comparison)
Expand All @@ -46,7 +44,6 @@ public StringEqualsAssertion WithComparison(StringComparison comparison)
}

/// <summary>
/// ⚡ CUSTOM METHOD - No wrapper needed!
/// Trims both strings before comparing.
/// </summary>
public StringEqualsAssertion WithTrimming()
Expand All @@ -57,7 +54,6 @@ public StringEqualsAssertion WithTrimming()
}

/// <summary>
/// ⚡ CUSTOM METHOD - No wrapper needed!
/// Treats null and empty string as equal.
/// </summary>
public StringEqualsAssertion WithNullAndEmptyEquality()
Expand All @@ -68,7 +64,6 @@ public StringEqualsAssertion WithNullAndEmptyEquality()
}

/// <summary>
/// ⚡ CUSTOM METHOD - No wrapper needed!
/// Removes all whitespace from both strings before comparing.
/// </summary>
public StringEqualsAssertion IgnoringWhitespace()
Expand Down
6 changes: 3 additions & 3 deletions TUnit.Assertions/Extensions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static ValueAssertion<TValue> That<TValue>(
/// Example: await Assert.That(() => GetValue()).IsGreaterThan(10);
/// </summary>
public static FuncAssertion<TValue> That<TValue>(
Func<TValue> func,
Func<TValue?> func,
[CallerArgumentExpression(nameof(func))] string? expression = null)
{
return new FuncAssertion<TValue>(func, expression);
Expand All @@ -138,7 +138,7 @@ public static FuncAssertion<TValue> That<TValue>(
/// Example: await Assert.That(async () => await GetValueAsync()).IsEqualTo(expected);
/// </summary>
public static AsyncFuncAssertion<TValue> That<TValue>(
Func<Task<TValue>> func,
Func<Task<TValue?>> func,
[CallerArgumentExpression(nameof(func))] string? expression = null)
{
return new AsyncFuncAssertion<TValue>(func, expression);
Expand All @@ -151,7 +151,7 @@ public static AsyncFuncAssertion<TValue> That<TValue>(
/// Example: await Assert.That(GetValueAsync()).IsCompleted();
/// </summary>
public static TaskAssertion<TValue> That<TValue>(
Task<TValue> task,
Task<TValue?> task,
[CallerArgumentExpression(nameof(task))] string? expression = null)
{
return new TaskAssertion<TValue>(task, expression);
Expand Down
4 changes: 2 additions & 2 deletions TUnit.Assertions/Extensions/AssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static DateTimeEqualsAssertion IsEqualTo(
[OverloadResolutionPriority(2)]
public static StringEqualsAssertion IsEqualTo(
this IAssertionSource<string> source,
string expected,
string? expected,
[CallerArgumentExpression(nameof(expected))] string? expression = null)
{
source.Context.ExpressionBuilder.Append($".IsEqualTo({expression})");
Expand All @@ -88,7 +88,7 @@ public static StringEqualsAssertion IsEqualTo(
/// </summary>
public static StringEqualsAssertion IsEqualTo(
this IAssertionSource<string> source,
string expected,
string? expected,
StringComparison comparison,
[CallerArgumentExpression(nameof(expected))] string? expression = null)
{
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Assertions/Sources/AsyncFuncAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AsyncFuncAssertion<TValue> : IAssertionSource<TValue>, IDelegateAss
{
public AssertionContext<TValue> Context { get; }

public AsyncFuncAssertion(Func<Task<TValue>> func, string? expression)
public AsyncFuncAssertion(Func<Task<TValue?>> func, string? expression)
{
var expressionBuilder = new StringBuilder();
expressionBuilder.Append($"Assert.That({expression ?? "?"})");
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Assertions/Sources/FuncAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FuncAssertion<TValue> : IAssertionSource<TValue>, IDelegateAssertio
{
public AssertionContext<TValue> Context { get; }

public FuncAssertion(Func<TValue> func, string? expression)
public FuncAssertion(Func<TValue?> func, string? expression)
{
var expressionBuilder = new StringBuilder();
expressionBuilder.Append($"Assert.That({expression ?? "?"})");
Expand Down
15 changes: 8 additions & 7 deletions TUnit.Assertions/Sources/TaskAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace TUnit.Assertions.Sources;
/// Implements IDelegateAssertionSource to enable Throws() extension methods.
/// Does not inherit from Assertion to prevent premature awaiting.
/// </summary>
public class TaskAssertion<TValue> : IAssertionSource<TValue>, IDelegateAssertionSource<TValue>, IAssertionSource<Task<TValue>>
public class TaskAssertion<TValue> : IAssertionSource<TValue>, IDelegateAssertionSource<TValue>, IAssertionSource<Task<TValue?>>
{
public AssertionContext<TValue> Context { get; }
AssertionContext<Task<TValue>> IAssertionSource<Task<TValue>>.Context => TaskContext;
AssertionContext<Task<TValue?>> IAssertionSource<Task<TValue?>>.Context => TaskContext;

private AssertionContext<Task<TValue>> TaskContext { get; }
private AssertionContext<Task<TValue?>> TaskContext { get; }

public TaskAssertion(Task<TValue> task, string? expression)
public TaskAssertion(Task<TValue?> task, string? expression)
{
var expressionBuilder = new StringBuilder();
expressionBuilder.Append($"Assert.That({expression ?? "?"})");
Expand All @@ -43,13 +43,14 @@ public TaskAssertion(Task<TValue> task, string? expression)
// DO NOT await the task here - we want to check its state synchronously
var taskExpressionBuilder = new StringBuilder();
taskExpressionBuilder.Append(expressionBuilder.ToString());
var taskEvaluationContext = new EvaluationContext<Task<TValue>>(() =>
var taskEvaluationContext = new EvaluationContext<Task<TValue?>>(() =>
{
// Return the task object itself without awaiting it
// This allows IsCompleted, IsCanceled, IsFaulted, etc. to check task properties synchronously
return Task.FromResult<(Task<TValue>?, Exception?)>((task, null));
return Task.FromResult<(Task<TValue?>?, Exception?)>((task, null));
});
TaskContext = new AssertionContext<Task<TValue>>(taskEvaluationContext, taskExpressionBuilder);

TaskContext = new AssertionContext<Task<TValue?>>(taskEvaluationContext, taskExpressionBuilder);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace
public static . That(. task, [.("task")] string? expression = null) { }
public static .<TItem> That<TItem>(.<TItem>? value, [.("value")] string? expression = null) { }
public static .<TItem> That<TItem>(.<TItem>? value, [.("value")] string? expression = null) { }
public static .<TValue> That<TValue>(<.<TValue>> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(<TValue> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(.<TValue> task, [.("task")] string? expression = null) { }
public static .<TValue> That<TValue>(<.<TValue?>> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(<TValue?> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(.<TValue?> task, [.("task")] string? expression = null) { }
public static .<TItem> That<TItem>(TItem[]? value, [.("value")] string? expression = null) { }
public static .<TValue> That<TValue>(TValue? value, [.("value")] string? expression = null) { }
public static .<TKey, TValue> That<TKey, TValue>(.<TKey, TValue> value, [.("value")] string? expression = null)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ namespace .Conditions
}
public class StringEqualsAssertion : .<string>
{
public StringEqualsAssertion(.<string> context, string expected) { }
public StringEqualsAssertion(.<string> context, string? expected) { }
protected override .<.> CheckAsync(.<string> metadata) { }
protected override string GetExpectation() { }
public . IgnoringCase() { }
Expand Down Expand Up @@ -1681,8 +1681,8 @@ namespace .Extensions
[.(2)]
public static . IsEqualTo(this .<long> source, long expected, [.("expected")] string? expression = null) { }
[.(2)]
public static . IsEqualTo(this .<string> source, string expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string expected, comparison, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string? expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string? expected, comparison, [.("expected")] string? expression = null) { }
[.(0)]
public static .<TValue> IsEqualTo<TValue>(this .<TValue> source, TValue expected, [.("expected")] string? expression = null) { }
[.(-1)]
Expand Down Expand Up @@ -3534,7 +3534,7 @@ namespace .Sources
}
public class AsyncFuncAssertion<TValue> : .<TValue>, .<TValue>
{
public AsyncFuncAssertion(<.<TValue>> func, string? expression) { }
public AsyncFuncAssertion(<.<TValue?>> func, string? expression) { }
public .<TValue> Context { get; }
public .<TException> Throws<TException>()
where TException : { }
Expand All @@ -3558,16 +3558,16 @@ namespace .Sources
}
public class FuncAssertion<TValue> : .<TValue>, .<TValue>
{
public FuncAssertion(<TValue> func, string? expression) { }
public FuncAssertion(<TValue?> func, string? expression) { }
public .<TValue> Context { get; }
public .<TException> Throws<TException>()
where TException : { }
public .<TException> ThrowsExactly<TException>()
where TException : { }
}
public class TaskAssertion<TValue> : .<.<TValue>>, .<TValue>, .<TValue>
public class TaskAssertion<TValue> : .<.<TValue?>>, .<TValue>, .<TValue>
{
public TaskAssertion(.<TValue> task, string? expression) { }
public TaskAssertion(.<TValue?> task, string? expression) { }
public .<TValue> Context { get; }
public .<.<TValue>> IsCanceled() { }
public .<.<TValue>> IsCompleted() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace
public static . That(. task, [.("task")] string? expression = null) { }
public static .<TItem> That<TItem>(.<TItem>? value, [.("value")] string? expression = null) { }
public static .<TItem> That<TItem>(.<TItem>? value, [.("value")] string? expression = null) { }
public static .<TValue> That<TValue>(<.<TValue>> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(<TValue> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(.<TValue> task, [.("task")] string? expression = null) { }
public static .<TValue> That<TValue>(<.<TValue?>> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(<TValue?> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(.<TValue?> task, [.("task")] string? expression = null) { }
public static .<TItem> That<TItem>(TItem[]? value, [.("value")] string? expression = null) { }
public static .<TValue> That<TValue>(TValue? value, [.("value")] string? expression = null) { }
public static .<TKey, TValue> That<TKey, TValue>(.<TKey, TValue> value, [.("value")] string? expression = null)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ namespace .Conditions
}
public class StringEqualsAssertion : .<string>
{
public StringEqualsAssertion(.<string> context, string expected) { }
public StringEqualsAssertion(.<string> context, string? expected) { }
protected override .<.> CheckAsync(.<string> metadata) { }
protected override string GetExpectation() { }
public . IgnoringCase() { }
Expand Down Expand Up @@ -1672,8 +1672,8 @@ namespace .Extensions
public static . IsEqualTo(this .<double> source, double expected, [.("expected")] string? expression = null) { }
public static .<int> IsEqualTo(this .<int> source, int expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<long> source, long expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string expected, comparison, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string? expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string? expected, comparison, [.("expected")] string? expression = null) { }
public static .<TValue> IsEqualTo<TValue>(this .<TValue> source, TValue expected, [.("expected")] string? expression = null) { }
public static .<TActual, TExpected> IsEqualTo<TActual, TExpected>(this .<TActual> source, TExpected expected, [.("expected")] string? expression = null)
where TActual : struct, <TExpected> { }
Expand Down Expand Up @@ -3522,7 +3522,7 @@ namespace .Sources
}
public class AsyncFuncAssertion<TValue> : .<TValue>, .<TValue>
{
public AsyncFuncAssertion(<.<TValue>> func, string? expression) { }
public AsyncFuncAssertion(<.<TValue?>> func, string? expression) { }
public .<TValue> Context { get; }
public .<TException> Throws<TException>()
where TException : { }
Expand All @@ -3546,16 +3546,16 @@ namespace .Sources
}
public class FuncAssertion<TValue> : .<TValue>, .<TValue>
{
public FuncAssertion(<TValue> func, string? expression) { }
public FuncAssertion(<TValue?> func, string? expression) { }
public .<TValue> Context { get; }
public .<TException> Throws<TException>()
where TException : { }
public .<TException> ThrowsExactly<TException>()
where TException : { }
}
public class TaskAssertion<TValue> : .<.<TValue>>, .<TValue>, .<TValue>
public class TaskAssertion<TValue> : .<.<TValue?>>, .<TValue>, .<TValue>
{
public TaskAssertion(.<TValue> task, string? expression) { }
public TaskAssertion(.<TValue?> task, string? expression) { }
public .<TValue> Context { get; }
public .<.<TValue>> IsCanceled() { }
public .<.<TValue>> IsCompleted() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace
public static . That(. task, [.("task")] string? expression = null) { }
public static .<TItem> That<TItem>(.<TItem>? value, [.("value")] string? expression = null) { }
public static .<TItem> That<TItem>(.<TItem>? value, [.("value")] string? expression = null) { }
public static .<TValue> That<TValue>(<.<TValue>> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(<TValue> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(.<TValue> task, [.("task")] string? expression = null) { }
public static .<TValue> That<TValue>(<.<TValue?>> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(<TValue?> func, [.("func")] string? expression = null) { }
public static .<TValue> That<TValue>(.<TValue?> task, [.("task")] string? expression = null) { }
public static .<TItem> That<TItem>(TItem[]? value, [.("value")] string? expression = null) { }
public static .<TValue> That<TValue>(TValue? value, [.("value")] string? expression = null) { }
public static .<TKey, TValue> That<TKey, TValue>(.<TKey, TValue> value, [.("value")] string? expression = null)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ namespace .Conditions
}
public class StringEqualsAssertion : .<string>
{
public StringEqualsAssertion(.<string> context, string expected) { }
public StringEqualsAssertion(.<string> context, string? expected) { }
protected override .<.> CheckAsync(.<string> metadata) { }
protected override string GetExpectation() { }
public . IgnoringCase() { }
Expand Down Expand Up @@ -1681,8 +1681,8 @@ namespace .Extensions
[.(2)]
public static . IsEqualTo(this .<long> source, long expected, [.("expected")] string? expression = null) { }
[.(2)]
public static . IsEqualTo(this .<string> source, string expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string expected, comparison, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string? expected, [.("expected")] string? expression = null) { }
public static . IsEqualTo(this .<string> source, string? expected, comparison, [.("expected")] string? expression = null) { }
[.(0)]
public static .<TValue> IsEqualTo<TValue>(this .<TValue> source, TValue expected, [.("expected")] string? expression = null) { }
[.(-1)]
Expand Down Expand Up @@ -3534,7 +3534,7 @@ namespace .Sources
}
public class AsyncFuncAssertion<TValue> : .<TValue>, .<TValue>
{
public AsyncFuncAssertion(<.<TValue>> func, string? expression) { }
public AsyncFuncAssertion(<.<TValue?>> func, string? expression) { }
public .<TValue> Context { get; }
public .<TException> Throws<TException>()
where TException : { }
Expand All @@ -3558,16 +3558,16 @@ namespace .Sources
}
public class FuncAssertion<TValue> : .<TValue>, .<TValue>
{
public FuncAssertion(<TValue> func, string? expression) { }
public FuncAssertion(<TValue?> func, string? expression) { }
public .<TValue> Context { get; }
public .<TException> Throws<TException>()
where TException : { }
public .<TException> ThrowsExactly<TException>()
where TException : { }
}
public class TaskAssertion<TValue> : .<.<TValue>>, .<TValue>, .<TValue>
public class TaskAssertion<TValue> : .<.<TValue?>>, .<TValue>, .<TValue>
{
public TaskAssertion(.<TValue> task, string? expression) { }
public TaskAssertion(.<TValue?> task, string? expression) { }
public .<TValue> Context { get; }
public .<.<TValue>> IsCanceled() { }
public .<.<TValue>> IsCompleted() { }
Expand Down
Loading
Loading