|
| 1 | +using System; |
| 2 | +using Xunit; |
| 3 | + |
| 4 | +namespace NetFabric.Assertive.UnitTests |
| 5 | +{ |
| 6 | + public partial class StringAssertionsTests |
| 7 | + { |
| 8 | + [Theory] |
| 9 | + [InlineData(null, null, false)] |
| 10 | + [InlineData("", "", false)] |
| 11 | + [InlineData("", "", true)] |
| 12 | + [InlineData(" ", " ", false)] |
| 13 | + [InlineData(" ", " ", true)] |
| 14 | + [InlineData("a", "a", false)] |
| 15 | + [InlineData("a", "a", true)] |
| 16 | + [InlineData("a", "A", true)] |
| 17 | + public void BeEqualTo_With_Equal_Should_NotThrow(string value, string expected, bool ignoreCase) |
| 18 | + { |
| 19 | + // Arrange |
| 20 | + |
| 21 | + // Act |
| 22 | + _ = value.Must().BeEqualTo(expected, ignoreCase); |
| 23 | + |
| 24 | + // Assert |
| 25 | + } |
| 26 | + |
| 27 | + public static TheoryData<string, string, string> Enumerable_NotEqualNullData => |
| 28 | + new TheoryData<string, string, string> |
| 29 | + { |
| 30 | + { null, "", $"Expected to be equal but it's not.{Environment.NewLine}Expected: <empty>{Environment.NewLine}Actual: <null>" }, |
| 31 | + { "", null, $"Expected to be equal but it's not.{Environment.NewLine}Expected: <null>{Environment.NewLine}Actual: <empty>" }, |
| 32 | + }; |
| 33 | + |
| 34 | + [Theory] |
| 35 | + [MemberData(nameof(Enumerable_NotEqualNullData))] |
| 36 | + public void BeEqualTo_With_NotEqual_Null_Should_Throw(string actual, string expected, string message) |
| 37 | + { |
| 38 | + // Arrange |
| 39 | + |
| 40 | + // Act |
| 41 | + void action() => actual.Must().BeEqualTo(expected); |
| 42 | + |
| 43 | + // Assert |
| 44 | + var exception = Assert.Throws<EqualToAssertionException<string, string>>(action); |
| 45 | + Assert.Equal(actual, exception.Actual); |
| 46 | + Assert.Equal(expected, exception.Expected); |
| 47 | + Assert.Equal(message, exception.Message); |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + public static TheoryData<string, string, int, string> Enumerable_NotEqualData => |
| 52 | + new TheoryData<string, string, int, string> |
| 53 | + { |
| 54 | + { "*", "", 0, $"Expected to be equal but it's not at position 0.{Environment.NewLine}Expected: <empty>{Environment.NewLine} Actual: *{Environment.NewLine} \u25b2" }, |
| 55 | + { "*", "0", 0, $"Expected to be equal but it's not at position 0.{Environment.NewLine}Expected: 0{Environment.NewLine} Actual: *{Environment.NewLine} \u25b2" }, |
| 56 | + { "0", "012345", 1, $"Expected to be equal but it's not at position 1.{Environment.NewLine}Expected: 012345{Environment.NewLine} Actual: 0{Environment.NewLine} \u25b2" }, |
| 57 | + { "012345", "0", 1, $"Expected to be equal but it's not at position 1.{Environment.NewLine}Expected: 0{Environment.NewLine} Actual: 012345{Environment.NewLine} \u25b2" }, |
| 58 | + { "01234*", "012345", 5, $"Expected to be equal but it's not at position 5.{Environment.NewLine}Expected: 012345{Environment.NewLine} Actual: 01234*{Environment.NewLine} \u25b2" }, |
| 59 | + { "01234*6789", "0123456789", 5, $"Expected to be equal but it's not at position 5.{Environment.NewLine}Expected: 0123456789{Environment.NewLine} Actual: 01234*6789{Environment.NewLine} \u25b2" }, |
| 60 | + { "0123456789a*", "0123456789ab", 11, $"Expected to be equal but it's not at position 11.{Environment.NewLine}Expected: \u2026123456789ab{Environment.NewLine} Actual: \u2026123456789a*{Environment.NewLine} \u25b2" }, |
| 61 | + { "0123456789a*cdefghijkl", "0123456789abcdefghijkl", 11, $"Expected to be equal but it's not at position 11.{Environment.NewLine}Expected: \u2026123456789abcdefghijk\u2026{Environment.NewLine} Actual: \u2026123456789a*cdefghijk\u2026{Environment.NewLine} \u25b2" }, |
| 62 | + { " \n\r34*", " \n\r345", 5, $"Expected to be equal but it's not at position 5.{Environment.NewLine}Expected: \u2022\u2193\u2190345{Environment.NewLine} Actual: \u2022\u2193\u219034*{Environment.NewLine} \u25b2" }, |
| 63 | + }; |
| 64 | + |
| 65 | + [Theory] |
| 66 | + [MemberData(nameof(Enumerable_NotEqualData))] |
| 67 | + public void BeEqualTo_With_NotEqual_Should_Throw(string actual, string expected, int index, string message) |
| 68 | + { |
| 69 | + // Arrange |
| 70 | + |
| 71 | + // Act |
| 72 | + void action() => actual.Must().BeEqualTo(expected); |
| 73 | + |
| 74 | + // Assert |
| 75 | + var exception = Assert.Throws<StringEqualToAssertionException>(action); |
| 76 | + Assert.Equal(actual, exception.Actual); |
| 77 | + Assert.Equal(expected, exception.Expected); |
| 78 | + Assert.Equal(index, exception.Index); |
| 79 | + Assert.Equal(message, exception.Message); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments