public void TestDeleteWrittenBuffer()
        {
            #region Arrange

            StringBuilder inputString = new StringBuilder("11aabzza");

            var sut = new ReplaceStreamContentCore(null, null, 5, null);

            #endregion

            #region Act
            var bufferRest = sut.InvokeProtectedOrPrivateMethod<StringBuilder>("deleteWrittenBuffer", new Tuple<int, StringBuilder>(5, inputString));
            #endregion

            #region Assert

            bufferRest.ToString().Should().Be("zza");

            #endregion
        }
        public void TestGetBytesToRead()
        {
            #region Arrange

            StringBuilder inputString = new StringBuilder("zza");

            var sut = new ReplaceStreamContentCore(null, null, 8, null);

            #endregion

            #region Act
            var readCount = sut.InvokeProtectedOrPrivateMethod<Tuple<int, StringBuilder>>("getBytesToRead", inputString);
            #endregion

            #region Assert

            readCount.Item1.Should().Be(5);

            #endregion
        }
        public void TestGetBytesToWrite()
        {
            #region Arrange

            StringBuilder inputString = new StringBuilder("11aaz");

            List<Replacement> replacements = new List<Replacement> { new Replacement { OldValue = "12", NewValue = "11" }, new Replacement { OldValue = "ab", NewValue = "aa" } };
            var sut = new ReplaceStreamContentCore(null, null, 5, replacements);

            #endregion

            #region Act
            var outputTuple = sut.InvokeProtectedOrPrivateMethod<Tuple<int, StringBuilder>>("getBytesToWrite", new Tuple<int, StringBuilder>(3, inputString));
            #endregion

            #region Assert

            outputTuple.Item1.Should().Be(4);
            outputTuple.Item2.ToString().Should().Be("11aaz");

            #endregion
        }
        public void TestWriteBytes()
        {
            #region Arrange

            string inputString = "11aabzza";
            Stream input = GenerateStreamFromString(inputString);
            MemoryStream outputStream = new MemoryStream();

            List<Replacement> replacements = new List<Replacement> { new Replacement { OldValue = "22", NewValue = "11" }, new Replacement { OldValue = "aaa", NewValue = "aab" } };
            var streamWriter = new StreamWriter(outputStream);
            var sut = new ReplaceStreamContentCore(new StreamReader(input), streamWriter, 5, replacements);

            #endregion

            #region Act
            var outputTuple = sut.InvokeProtectedOrPrivateMethod<Tuple<int, StringBuilder>>("writeBytes", new Tuple<int, StringBuilder>(5, new StringBuilder(inputString)));
            streamWriter.Flush();
            #endregion

            #region Assert

            outputTuple.Item1.Should().Be(5);
            outputTuple.Item2.ToString().Should().Be("11aabzza");

            outputStream.Position = 0;

            string writtenString = Encoding.ASCII.GetString(outputStream.ToArray());
            writtenString.Should().Be("11aab");

            #endregion
        }
        public void TestReplaceReal05()
        {
            #region Arrange

            string writtenString;
            string path = @"C:\Users\kreich\Desktop\new  3.txt";
            List<Replacement> replacements;
            using (Stream input = File.OpenRead(path))
            {

                MemoryStream outputStream = new MemoryStream();

                replacements = new List<Replacement>
                                   {
                                       new Replacement {OldValue = "aaa", NewValue = "b"},
                                       new Replacement {OldValue = "kda", NewValue = "zz"}
                                   };
                //replacements = new List<Replacement> {new Replacement {OldValue = "aaa", NewValue = "aab"}};
                var streamWriter = new StreamWriter(outputStream);
                var sut = new ReplaceStreamContentCore(new StreamReader(input), streamWriter, 1000, replacements);

                #endregion

                #region Act

                Stopwatch sw = new Stopwatch();
                sw.Start();
                sut.Replace();
                sw.Stop();

                Console.WriteLine(sw.ElapsedMilliseconds);

                streamWriter.Flush();

                #endregion

                outputStream.Position = 0;

                writtenString = Encoding.ASCII.GetString(outputStream.ToArray());
            }

            #region Assert

            var inputString = File.ReadAllText(path);
            foreach (var replacement in replacements)
            {
                inputString = inputString.Replace(replacement.OldValue, replacement.NewValue);
            }

            writtenString.Should().Be(inputString);

            #endregion
        }
        public void TestReplaceReal04()
        {
            #region Arrange

            string inputString = "11aabzzaaasdlkjfdghjkdasadlkjasdhjkgfdsalakjsdasdhjksdfsaldfkasdhjaaasdsdfjk";
            Stream input = GenerateStreamFromString(inputString);
            MemoryStream outputStream = new MemoryStream();

            List<Replacement> replacements = new List<Replacement> { new Replacement { OldValue = "aaa", NewValue = "aab" } };
            var streamWriter = new StreamWriter(outputStream);
            var sut = new ReplaceStreamContentCore(new StreamReader(input), streamWriter, 8, replacements);

            #endregion

            #region Act
            sut.Replace();
            streamWriter.Flush();
            #endregion

            #region Assert

            outputStream.Position = 0;

            string writtenString = Encoding.ASCII.GetString(outputStream.ToArray());
            writtenString.Should().Be(inputString.Replace("aaa", "aab"));

            #endregion
        }
        public void TestReplaceReal02a(string stringToReplace)
        {
            #region Arrange

            string inputString = @"kda0123456789kda0123456789";
            Stream input = GenerateStreamFromString(inputString);
            MemoryStream outputStream = new MemoryStream();

            List<Replacement> replacements = new List<Replacement>
                                   {
                                       new Replacement {OldValue = stringToReplace, NewValue = "b"},
                                       new Replacement {OldValue = "kda", NewValue = "zz"}
                                   };
            var streamWriter = new StreamWriter(outputStream);
            var sut = new ReplaceStreamContentCore(new StreamReader(input), streamWriter, 5, replacements);

            #endregion

            #region Act
            sut.Replace();
            streamWriter.Flush();
            #endregion

            #region Assert

            outputStream.Position = 0;

            foreach (var replacement in replacements)
            {
                inputString = inputString.Replace(replacement.OldValue, replacement.NewValue);
            }

            string writtenString = Encoding.ASCII.GetString(outputStream.ToArray());
            writtenString.Should().Be(inputString);

            #endregion
        }
        public void TestReplaceReal01()
        {
            #region Arrange

            string inputString = "11aabzza";
            Stream input = GenerateStreamFromString(inputString);
            MemoryStream outputStream = new MemoryStream();

            List<Replacement> replacements = new List<Replacement> { new Replacement { OldValue = "22", NewValue = "11" }, new Replacement { OldValue = "aaa", NewValue = "aab" } };
            var streamWriter = new StreamWriter(outputStream);
            var sut = new ReplaceStreamContentCore(new StreamReader(input), streamWriter, 8, replacements);

            #endregion

            #region Act
            sut.Replace();
            streamWriter.Flush();
            #endregion

            #region Assert

            outputStream.Position = 0;

            string writtenString = Encoding.ASCII.GetString(outputStream.ToArray());
            writtenString.Should().Be("11aabzza");

            #endregion
        }
        public void TestReadBytes()
        {
            #region Arrange
            Stream input = GenerateStreamFromString("abcdefg");

            ReplaceStreamContentCore sut = new ReplaceStreamContentCore(new StreamReader(input), null, 5, null);

            #endregion

            #region Act
            var erg = sut.InvokeProtectedOrPrivateMethod<StringBuilder>("readBytes", new Tuple<int, StringBuilder>(3, new StringBuilder()));
            #endregion

            #region Assert

            erg.ToString().Should().Be("abc");

            #endregion
        }
        public void TestGetLastEndPosition()
        {
            #region Arrange

            StringBuilder inputString = new StringBuilder("12abz");

            List<Replacement> replacements = new List<Replacement> { new Replacement { OldValue = "12", NewValue = "11" }, new Replacement { OldValue = "ab", NewValue = "aa" } };
            var sut = new ReplaceStreamContentCore(null, null, 5, replacements);

            #endregion

            #region Act
            var erg = sut.InvokeProtectedOrPrivateMethod<Tuple<int, StringBuilder>>("getLastEndPosition", inputString);
            #endregion

            #region Assert

            erg.Item1.Should().Be(3);

            #endregion
        }