using Microsoft.VisualStudio.TestTools.UnitTesting; namespace X10D.Tests.Core { /// /// Tests for . /// [TestClass] public class StringTests { /// /// Tests for . /// [TestMethod] public void AsNullIfEmpty() { Assert.AreEqual(null, string.Empty.AsNullIfEmpty()); Assert.AreEqual(null, ((string)null).AsNullIfEmpty()); Assert.AreEqual(" ", " ".AsNullIfEmpty()); Assert.AreEqual("foo", "foo".AsNullIfEmpty()); } /// /// Tests for . /// [TestMethod] public void AsNullIfWhiteSpace() { Assert.AreEqual(null, string.Empty.AsNullIfWhiteSpace()); Assert.AreEqual(null, ((string)null).AsNullIfWhiteSpace()); Assert.AreEqual(null, " ".AsNullIfWhiteSpace()); Assert.AreEqual("foo", "foo".AsNullIfWhiteSpace()); } /// /// Tests for . /// [TestMethod] public void Repeat() { Assert.AreEqual("foofoofoofoofoo", "foo".Repeat(5)); } /// /// Tests for . /// [TestMethod] public void Reverse() { Assert.AreEqual("dlroW olleH", StringExtensions.Reverse("Hello World")); Assert.AreEqual("Foobar", StringExtensions.Reverse("rabooF")); } /// /// Tests for . /// [TestMethod] public void Split() { const string str = "Hello World"; // ReSharper disable once SuggestVarOrType_Elsewhere var arr = str.Split(2).ToArray(); CollectionAssert.AreEqual(new[] { "He", "ll", "o ", "Wo", "rl", "d" }, arr); } /// /// Tests and /// . /// [TestMethod] public void WithAlternative() { const string inputA = "Hello World"; const string inputB = " "; const string inputC = ""; const string? inputD = null; 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(() => ((string?)null).WithEmptyAlternative(null!)); Assert.AreEqual(resultA, inputA); Assert.AreEqual(resultB, inputB); Assert.AreEqual(resultBWithWhitespace, alternative); Assert.AreEqual(resultC, alternative); Assert.AreEqual(resultD, alternative); } } }