-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNullabilityAssertionExtensions.cs
43 lines (35 loc) · 1.19 KB
/
NullabilityAssertionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using FluentAssertions;
using JetBrains.Annotations;
using SysNotNull = System.Diagnostics.CodeAnalysis.NotNullAttribute;
// ReSharper disable PossibleMultipleEnumeration
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
namespace TestBuildingBlocks;
public static class NullabilityAssertionExtensions
{
[CustomAssertion]
public static T ShouldNotBeNull<T>([SysNotNull] this T? subject)
{
subject.Should().NotBeNull();
return subject!;
}
[CustomAssertion]
public static void ShouldNotBeEmpty([SysNotNull] this string? subject)
{
subject.Should().NotBeEmpty();
}
[CustomAssertion]
public static void ShouldHaveCount<T>([SysNotNull] this IEnumerable<T>? subject, int expected)
{
subject.Should().HaveCount(expected);
}
[CustomAssertion]
public static TValue? ShouldContainKey<TKey, TValue>([SysNotNull] this IDictionary<TKey, TValue?>? subject, TKey expected)
{
subject.Should().ContainKey(expected);
return subject![expected];
}
public static void With<T>(this T subject, [InstantHandle] Action<T> continuation)
{
continuation(subject);
}
}