1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:05:42 +00:00

Update string.With*Alternative tests

This commit is contained in:
Oliver Booth 2022-03-06 17:36:58 +00:00
parent 4f99763a0a
commit 5509305c5a
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634

View File

@ -65,16 +65,31 @@ namespace X10D.Tests.Core
} }
/// <summary> /// <summary>
/// Tests for <see cref="StringExtensions.WithAlternative" />. /// Tests <see cref="StringExtensions.WithEmptyAlternative" /> and
/// <see cref="StringExtensions.WithWhiteSpaceAlternative"/>.
/// </summary> /// </summary>
[TestMethod] [TestMethod]
public void WithAlternative() public void WithAlternative()
{ {
Assert.AreEqual("Hello", "Hello".WithAlternative("Discarded")); const string inputA = "Hello World";
Assert.AreEqual("Alternative", string.Empty.WithAlternative("Alternative")); const string inputB = " ";
Assert.AreEqual(" ", " ".WithAlternative("Discarded")); const string inputC = "";
Assert.AreEqual("Alternative", " ".WithAlternative("Alternative", true)); const string? inputD = null;
Assert.AreEqual("Alternative", ((string)null).WithAlternative("Alternative")); const string alternative = "ALTERNATIVE";
string resultA = inputA.WithEmptyAlternative(alternative);
string resultB = inputB.WithEmptyAlternative(alternative);
string resultBWithWhitespace = inputB.WithWhiteSpaceAlternative(alternative);
string resultC = inputC.WithEmptyAlternative(alternative);
string resultD = inputD.WithEmptyAlternative(alternative);
Assert.ThrowsException<ArgumentNullException>(() => ((string?)null).WithEmptyAlternative(null!));
Assert.AreEqual(resultA, inputA);
Assert.AreEqual(resultB, inputB);
Assert.AreEqual(resultBWithWhitespace, alternative);
Assert.AreEqual(resultC, alternative);
Assert.AreEqual(resultD, alternative);
} }
} }
} }