-
-
Notifications
You must be signed in to change notification settings - Fork 97
Description
Hi there,
TUnit is an excellent testing and assertion library. Thank you very much for developing it and providing it to us open-source!
However, with the change from version 0.67.19 to 0.7X.X some the assertions used in a project of mine (.NET 9, C# 13) broke and have not been fixed yet up to version 0.74.2. I hope these are actual errors and not planned changes that I missed.
1. Prior to version 0.70.0 there was an assertion method IsNotNullOrWhitespace for Strings that is missing in the versions up to 0.74.2:
[Test]
public async Task Text_IsNotNullOrWhitespace()
{
var text = "Some text";
await Assert.That(text).IsNotNullOrWhitespace();
}'ValueAssertion' does not contain a definition for 'IsNotNullOrWhitespace' and no accessible extension method 'IsNotNullOrWhitespace' accepting a first argument of type 'ValueAssertion' could be found (are you missing a using directive or an assembly reference?)
Assertion method IsNullOrWhiteSpace still exists, as do IsNullOrEmpty and its counterpart IsNotNullOrEmpty.
2. Prior to version 0.70.0 the assertion methods IsTrue and IsFalse worked for nullable Booleans:
[Test]
public async Task NullableBool_IsTrueOrFalse()
{
bool? nullableBool = true;
await Assert.That(nullableBool).IsTrue();
await Assert.That(nullableBool).IsFalse();
}After version 0.70.0, the methods do not exist anymore:
'ValueAssertion<bool?>' does not contain a definition for 'IsTrue' and the best extension method overload 'BooleanAssertionExtensions.IsTrue(IAssertionSource)' requires a receiver of type 'TUnit.Assertions.Core.IAssertionSource'
'ValueAssertion<bool?>' does not contain a definition for 'IsFalse' and the best extension method overload 'BooleanAssertionExtensions.IsFalse(IAssertionSource)' requires a receiver of type 'TUnit.Assertions.Core.IAssertionSource'
3. Prior to version 0.70.0 the assertion method IsDefault worked for countless nulalble types like object, bool? and so on.
[Test]
public async Task NullableObject_IsDefault()
{
object obj = default;
await Assert.That(obj).IsDefault();
}After version 0.70.0, the method does not accept nullable value types anymore:
The type 'object' must be a non-nullable value type in order to use it as parameter 'TValue' in the generic type or method 'IsDefaultAssertionExtensions.IsDefault(IAssertionSource)'
4. Prior to version 0.70.0 the assertion methods Contains and DoesNotContain for enumerables was working in method chains without a problem. With e.g. version 0.74.2 assertion method DoesNotContain now fails during chaining:
public record Language
{
public CultureInfo Culture { get; init; }
}
[Test]
public async Task Enumerable_Contains()
{
var languages = new List<Language>() {
new() { Culture = CultureInfo.InvariantCulture }
};
// Okay:
await Assert.That(languages).Contains(language => language.Culture == CultureInfo.InvariantCulture);
// Okay:
await Assert.That(languages).IsNotEmpty().And.HasDistinctItems().And.Contains(language => language.Culture == CultureInfo.InvariantCulture);
}
[Test]
public async Task Enumerable_DoesNotContain()
{
var = new List<Language>() {
new() { Culture = CultureInfo.InvariantCulture }
};
// Okay:
await Assert.That(languages).DoesNotContain(language => language.Culture == CultureInfo.InvariantCulture);
// Error:
await Assert.That(languages).IsNotEmpty().And.HasDistinctItems().And.DoesNotContain(language => language.Culture == CultureInfo.InvariantCulture);
}Cannot convert lambda expression to type 'Language' because it is not a delegate type