| | | 1 | | using System.Collections; |
| | | 2 | | using ArturRios.Extensions; |
| | | 3 | | using Xunit; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Util.Test.Assertion; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Extra xUnit-style assertions for the null/empty checks that come up most often in tests. |
| | | 9 | | /// Each method throws a <c>Xunit.Sdk.XunitException</c> when the condition is not met, exactly like <see cref="Assert"/ |
| | | 10 | | /// </summary> |
| | | 11 | | public static class CustomAssert |
| | | 12 | | { |
| | | 13 | | /// <summary>Asserts that <paramref name="collection"/> is <c>null</c> or contains no elements.</summary> |
| | | 14 | | /// <param name="collection">The collection to check.</param> |
| | 3 | 15 | | public static void NullOrEmpty(IEnumerable? collection) => Assert.True(collection is null || collection.IsEmpty()); |
| | | 16 | | |
| | | 17 | | /// <summary>Asserts that <paramref name="collection"/> is not <c>null</c> and contains at least one element.</summa |
| | | 18 | | /// <param name="collection">The collection to check.</param> |
| | 3 | 19 | | public static void NotNullOrEmpty(IEnumerable? collection) => Assert.True(collection is not null && collection.IsNot |
| | | 20 | | |
| | | 21 | | /// <summary>Asserts that <paramref name="string"/> is <c>null</c> or the empty string.</summary> |
| | | 22 | | /// <param name="string">The string to check.</param> |
| | 3 | 23 | | public static void NullOrEmpty(string? @string) => Assert.True(string.IsNullOrEmpty(@string)); |
| | | 24 | | |
| | | 25 | | /// <summary>Asserts that <paramref name="string"/> is not <c>null</c> and not the empty string.</summary> |
| | | 26 | | /// <param name="string">The string to check.</param> |
| | 3 | 27 | | public static void NotNullOrEmpty(string? @string) => Assert.False(string.IsNullOrEmpty(@string)); |
| | | 28 | | |
| | | 29 | | /// <summary>Asserts that <paramref name="string"/> is <c>null</c>, empty, or consists only of white-space character |
| | | 30 | | /// <param name="string">The string to check.</param> |
| | 4 | 31 | | public static void NullOrWhiteSpace(string? @string) => Assert.True(string.IsNullOrWhiteSpace(@string)); |
| | | 32 | | |
| | | 33 | | /// <summary>Asserts that <paramref name="string"/> contains at least one non-white-space character.</summary> |
| | | 34 | | /// <param name="string">The string to check.</param> |
| | 4 | 35 | | public static void NotNullOrWhiteSpace(string? @string) => Assert.False(string.IsNullOrWhiteSpace(@string)); |
| | | 36 | | } |