v3.0.0
NOTE: This release caused too many problems with the class
constraint on ShouldBe
- use v3.0.3 instead.
New Features
- Added nullable annotations everywhere.
ValueTask
assertions -ShouldComplete
andShouldFail
.- Unfortunately there's no way to specify the exception type directly, but you can chain a type assertion, e.g.
task.ShouldFail().And.ShouldBeA<ArgumentException>()
- Unfortunately there's no way to specify the exception type directly, but you can chain a type assertion, e.g.
IAsyncEnumerable
assertions -ShouldComplete
andShouldFail
.ShouldComplete
returns anIReadOnlyList
so you can assert on the items afterwards.
- A
ShouldMatch
collection assertion that takes in an assertion callback instead of an equality function. This makes it easier to re-use assertion code, and will often provide more useful error messages. SeparateRolled back in subsequent release because it caused too many problems.ShouldBe
andShouldNotBe
assertions for classes and value types, for better value type IntelliSense.- Improvements for custom assertions
- Added
RegisterNotNullAssertion
for custom assertions that assert that the actual value isn't null. Tells the compiler that the actual value isn't null after the assertion has been called. - Replaced
RegisterUserAssertion
with simplerCall
method onIAssertionContext
, which just takes in a single expression that calls the assertion. Register(NotNull)Assertion
andCall
methods optionally take in suffixes to add to the actual and expected expressions, for better expressions when asserting on contents of objects.
- Added
Bug Fixes
ItemsSatisfy
andAllItemsSatisfy
no longer allow passing in a predicate accidentally.ShouldBeNull
can no longer be called on non-nullable types.- Assertions are tracked within the async context, rather than the thread context, which should fix a lot of problems with incorrect source code in errors.
Breaking Changes
RegisterUserAssertion
has been removed. UseCall
instead.
// Before
public static Actual<T> MyCustomAssertion(this T actual, Action<T> assertion)
{
return actual.RegisterAssertion(c => {
actual.RegisterUserAssertion(assertion, () => assertion(actual));
});
}
// After
public static Actual<T> MyCustomAssertion(this T actual, Action<T> assertion)
{
return actual.RegisterAssertion(c => {
c.Call(() => assertion(actual));
});
}
RegisterIndexedAssertion
has been removed. Pass a suffix intoRegisterAssertion
orCall
instead.
// Before
public static Actual<T> MyIndexedAssertion(this List<T> actual, T expected)
{
return actual.RegisterAssertion(c => {
actual.RegisterIndexedAssertion(1, () => actual[1].ShouldBe(expected));
});
}
// After
public static Actual<T> MyIndexedAssertion(this List<T> actual, T expected)
{
return actual.RegisterAssertion(c => {
actual.RegisterAssertion(c2 => actual[1].ShouldBe(expected), "[1]");
});
// or
return actual.RegisterAssertion(c => {
actual[1].ShouldBe(expected);
}, "[1]");
}
ShouldBeValue has been marked as obsolete. UseRolled back in subsequent release because it caused too many problems.ShouldBe
instead.- .NET framework requirement has been bumped up to .NET 4.6.1
- Added dependencies on
IndexRange
,System.Linq.Async
, andSystem.Memory
. TestExpressionProvider
interface has been renamed toITestExpressionProvider
.