|
7 | 7 |
|
8 | 8 | namespace Egil.RazorComponents.Testing.Asserting |
9 | 9 | { |
10 | | - /// <summary> |
11 | | - /// Collection test assertions |
12 | | - /// </summary> |
13 | | - public static class GenericAssertExtensions |
14 | | - { |
15 | | - /// <summary> |
16 | | - /// Verifies that <paramref name="actual"/> is not null |
17 | | - /// and returns <paramref name="actual"/> again. |
18 | | - /// </summary> |
19 | | - /// <returns>Returns <paramref name="actual"/> if it is not null.</returns> |
20 | | - public static T ShouldNotBeNull<T>([NotNullIfNotNull("actual")]this T? actual) where T : class |
21 | | - { |
22 | | - if (actual is null) |
23 | | - throw new XunitException($"{nameof(ShouldNotBeNull)}() Failure"); |
24 | | - return actual; |
25 | | - } |
26 | | - |
27 | | - /// <summary> |
28 | | - /// Verifies that <paramref name="actual"/> is not null |
29 | | - /// and returns <paramref name="actual"/> again. |
30 | | - /// </summary> |
31 | | - /// <returns>Returns <paramref name="actual"/> if it is not null.</returns> |
32 | | - public static T ShouldNotBeNull<T>([NotNullIfNotNull("actual")]this T? actual) where T : struct |
33 | | - { |
34 | | - if (actual is null) |
35 | | - throw new XunitException($"{nameof(ShouldNotBeNull)}() Failure"); |
36 | | - return actual.Value; |
37 | | - } |
38 | | - |
39 | | - /// <summary> |
40 | | - /// Verifies that a nullable <paramref name="actual"/> is not null |
41 | | - /// and of type <typeparamref name="T"/>. |
42 | | - /// </summary> |
43 | | - /// <returns>Returns <paramref name="actual"/> as <typeparamref name="T"/>.</returns> |
44 | | - public static T ShouldBeOfType<T>([NotNullIfNotNull("actual")]this object? actual) |
45 | | - { |
46 | | - return Assert.IsType<T>(actual); |
47 | | - } |
48 | | - |
49 | | - /// <summary> |
50 | | - /// Verifies that a non nullable struct is the same as its nullable counter part. |
51 | | - /// </summary> |
52 | | - public static void ShouldBe<T>(this T actual, T? expected) |
53 | | - where T : struct |
54 | | - { |
55 | | - Assert.Equal(expected, actual); |
56 | | - } |
57 | | - } |
58 | | - |
59 | 10 | /// <summary> |
60 | 11 | /// Collection test assertions |
61 | 12 | /// </summary> |
62 | 13 | public static class CollectionAssertExtensions |
63 | 14 | { |
64 | | - |
65 | | - |
66 | 15 | /// <summary> |
67 | 16 | /// Verifies that a collection contains exactly a given number of elements, which |
68 | 17 | /// meet the criteria provided by the element inspectors. |
|
0 commit comments