示例#1
0
        public static void ReplaceCaseInsensitive_OldValueNotFound_ReturnsStringWithNoReplacements()
        {
            // Arrange
            const string Original1 = "";
            const string Original2 = "   ";
            const string Original3 = "  \r\n   ";
            const string Original4 = "this is some text";
            const string Original5 = "this is \r\n some text";

            const string OldValue1 = "A";
            const string OldValue2 = "\r\n";
            const string OldValue3 = "text";
            const string OldValue4 = "ABCD";
            const string OldValue5 = @"//";

            // Act
            string actual1 = Original1.ReplaceCaseInsensitive(OldValue1, string.Empty);
            string actual2 = Original2.ReplaceCaseInsensitive(OldValue2, "some replacement");
            string actual3 = Original3.ReplaceCaseInsensitive(OldValue3, "ABCD");
            string actual4 = Original4.ReplaceCaseInsensitive(OldValue4, "...");
            string actual5 = Original5.ReplaceCaseInsensitive(OldValue5, "some other\r\nreplacement");

            // Assert
            Assert.Equal(Original1, actual1);
            Assert.Equal(Original2, actual2);
            Assert.Equal(Original3, actual3);
            Assert.Equal(Original4, actual4);
            Assert.Equal(Original5, actual5);
        }
示例#2
0
        public static void ReplaceCaseInsensitive_OldValueFoundAndNewValueIsNotEmpty_ReplacesAllOccurrencesOfOldValueWithNewValue()
        {
            // Arrange
            const string Original1  = "     ";
            const string OldValue1a = " ";
            const string NewValue1a = ".";
            const string Expected1a = ".....";
            const string OldValue1b = "  ";
            const string NewValue1b = "Ab";
            const string Expected1b = "AbAb ";
            const string OldValue1c = "   ";
            const string NewValue1c = "xyZ";
            const string Expected1c = "xyZ  ";
            const string OldValue1d = "  ";
            const string NewValue1d = "   ";
            const string Expected1d = "       ";

            const string Original2  = "  \r\n   ";
            const string OldValue2a = "\r\n";
            const string NewValue2a = "\r\n\r\n";
            const string Expected2a = "  \r\n\r\n   ";
            const string OldValue2b = " \r";
            const string NewValue2b = " \nO";
            const string Expected2b = "  \nO\n   ";

            const string Original3  = "this is some text";
            const string OldValue3a = "EXT";
            const string NewValue3a = "eXt";
            const string Expected3a = "this is some teXt";
            const string OldValue3b = "Thi";
            const string NewValue3b = "THI";
            const string Expected3b = "THIs is some text";

            const string Original4  = "this is \r\n some text";
            const string OldValue4a = "th";
            const string NewValue4a = "thth";
            const string Expected4a = "ththis is \r\n some text";
            const string OldValue4b = "xT";
            const string NewValue4b = "xtxt";
            const string Expected4b = "this is \r\n some textxt";
            const string OldValue4c = "is";
            const string NewValue4c = "is";
            const string Expected4c = "this is \r\n some text";

            const string Original5  = "ThThisIsSomeisTeXtXT";
            const string OldValue5a = "tH";
            const string NewValue5a = "ah";
            const string Expected5a = "ahahisIsSomeisTeXtXT";
            const string OldValue5b = "XT";
            const string NewValue5b = "%^";
            const string Expected5b = "ThThisIsSomeisTe%^%^";
            const string OldValue5c = "IS";
            const string NewValue5c = "YisO";
            const string Expected5c = "ThThYisOYisOSomeYisOTeXtXT";

            const string Original6 = "appUkslsaAPPskskdsdksapP";
            const string OldValue6 = "ApP";
            const string NewValue6 = "  ,*";
            const string Expected6 = "  ,*Ukslsa  ,*skskdsdks  ,*";

            // Act
            string actual1a = Original1.ReplaceCaseInsensitive(OldValue1a, NewValue1a);
            string actual1b = Original1.ReplaceCaseInsensitive(OldValue1b, NewValue1b);
            string actual1c = Original1.ReplaceCaseInsensitive(OldValue1c, NewValue1c);
            string actual1d = Original1.ReplaceCaseInsensitive(OldValue1d, NewValue1d);
            string actual2a = Original2.ReplaceCaseInsensitive(OldValue2a, NewValue2a);
            string actual2b = Original2.ReplaceCaseInsensitive(OldValue2b, NewValue2b);
            string actual3a = Original3.ReplaceCaseInsensitive(OldValue3a, NewValue3a);
            string actual3b = Original3.ReplaceCaseInsensitive(OldValue3b, NewValue3b);
            string actual4a = Original4.ReplaceCaseInsensitive(OldValue4a, NewValue4a);
            string actual4b = Original4.ReplaceCaseInsensitive(OldValue4b, NewValue4b);
            string actual4c = Original4.ReplaceCaseInsensitive(OldValue4c, NewValue4c);
            string actual5a = Original5.ReplaceCaseInsensitive(OldValue5a, NewValue5a);
            string actual5b = Original5.ReplaceCaseInsensitive(OldValue5b, NewValue5b);
            string actual5c = Original5.ReplaceCaseInsensitive(OldValue5c, NewValue5c);
            string actual6  = Original6.ReplaceCaseInsensitive(OldValue6, NewValue6);

            // Assert
            Assert.Equal(Expected1a, actual1a);
            Assert.Equal(Expected1b, actual1b);
            Assert.Equal(Expected1c, actual1c);
            Assert.Equal(Expected1d, actual1d);
            Assert.Equal(Expected2a, actual2a);
            Assert.Equal(Expected2b, actual2b);
            Assert.Equal(Expected3a, actual3a);
            Assert.Equal(Expected3b, actual3b);
            Assert.Equal(Expected4a, actual4a);
            Assert.Equal(Expected4b, actual4b);
            Assert.Equal(Expected4c, actual4c);
            Assert.Equal(Expected5a, actual5a);
            Assert.Equal(Expected5b, actual5b);
            Assert.Equal(Expected5c, actual5c);
            Assert.Equal(Expected6, actual6);
        }
示例#3
0
        public static void ReplaceCaseInsensitive_OldValueFoundAndNewValueIsEmpty_RemovesAllOccurrencesOfOldValue()
        {
            // Arrange
            const string Original1 = "   ";
            const string Original2 = "  \r\n   ";
            const string Original3 = "this is some text";
            const string Original4 = "this is \r\n some text";
            const string Original5 = "ThThisIsSomeisTeXtXT";
            const string Original6 = "appUkslsaAPPskskdsdksapP";

            const string OldValue1  = " ";
            const string OldValue2a = "\r\n";
            const string OldValue2b = " ";
            const string OldValue3a = "EXT";
            const string OldValue3b = "Thi";
            const string OldValue4a = "th";
            const string OldValue4b = "xT";
            const string OldValue4c = " \r\n ";
            const string OldValue5a = "th";
            const string OldValue5b = "XT";
            const string OldValue5c = "IS";
            const string OldValue6  = "ApP";

            const string Expected1  = "";
            const string Expected2a = "     ";
            const string Expected2b = "\r\n";
            const string Expected3a = "this is some t";
            const string Expected3b = "s is some text";
            const string Expected4a = "is is \r\n some text";
            const string Expected4b = "this is \r\n some te";
            const string Expected4c = "this issome text";
            const string Expected5a = "isIsSomeisTeXtXT";
            const string Expected5b = "ThThisIsSomeisTe";
            const string Expected5c = "ThThSomeTeXtXT";
            const string Expected6  = "Ukslsaskskdsdks";

            // Act
            string actual1  = Original1.ReplaceCaseInsensitive(OldValue1, string.Empty);
            string actual2a = Original2.ReplaceCaseInsensitive(OldValue2a, string.Empty);
            string actual2b = Original2.ReplaceCaseInsensitive(OldValue2b, string.Empty);
            string actual3a = Original3.ReplaceCaseInsensitive(OldValue3a, string.Empty);
            string actual3b = Original3.ReplaceCaseInsensitive(OldValue3b, string.Empty);
            string actual4a = Original4.ReplaceCaseInsensitive(OldValue4a, string.Empty);
            string actual4b = Original4.ReplaceCaseInsensitive(OldValue4b, string.Empty);
            string actual4c = Original4.ReplaceCaseInsensitive(OldValue4c, string.Empty);
            string actual5a = Original5.ReplaceCaseInsensitive(OldValue5a, string.Empty);
            string actual5b = Original5.ReplaceCaseInsensitive(OldValue5b, string.Empty);
            string actual5c = Original5.ReplaceCaseInsensitive(OldValue5c, string.Empty);
            string actual6  = Original6.ReplaceCaseInsensitive(OldValue6, string.Empty);

            // Assert
            Assert.Equal(Expected1, actual1);
            Assert.Equal(Expected2a, actual2a);
            Assert.Equal(Expected2b, actual2b);
            Assert.Equal(Expected3a, actual3a);
            Assert.Equal(Expected3b, actual3b);
            Assert.Equal(Expected4a, actual4a);
            Assert.Equal(Expected4b, actual4b);
            Assert.Equal(Expected4c, actual4c);
            Assert.Equal(Expected5a, actual5a);
            Assert.Equal(Expected5b, actual5b);
            Assert.Equal(Expected5c, actual5c);
            Assert.Equal(Expected6, actual6);
        }