Ejemplo n.º 1
0
        public void TextFileProcessor_ParseData_GivenEmptyStream_ShouldThrowException()
        {
            // ARRANGE
            TextFileProcessor processor   = new TextFileProcessor();
            Stream            emptyStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(string.Empty));

            // ACT
            // No act as we're checking an exception

            // ASSERT
            Assert.Throws <DataLoadException>(() => processor.ParseData(emptyStream), "The method should have thrown an exception.");
        } // end test
Ejemplo n.º 2
0
        public void TextFileProcessor_ParseData_GivenValidMultiLineStream_ShouldReturnParsedLines()
        {
            // ARRANGE
            TextFileProcessor      processor = new TextFileProcessor();
            IEnumerable <DataItem> results   = null;
            Stream fakeStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("[2017-12-13 09:42:23.244 INFO - Data Updated] Something fun happened." + Environment.NewLine + "[2017-12-13 11:26:19.583 INFO - Data Updated] Something different happened later."));

            // ACT
            results = processor.ParseData(fakeStream);

            // ASSERT
            Assert.AreEqual(2, results.Count(), "There should have been exactly two results.");
        } // end test
Ejemplo n.º 3
0
        public void TextFileProcessor_ParseData_GivenValidSingleLineStream_ShouldReturnParsedLine()
        {
            // ARRANGE
            TextFileProcessor      processor = new TextFileProcessor();
            IEnumerable <DataItem> results   = null;
            Stream fakeStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("[2017-12-13 09:42:23.244 INFO - Data Updated] Something fun happened."));

            // ACT
            results = processor.ParseData(fakeStream);

            // ASSERT
            Assert.AreEqual(1, results.Count(), "There should only have been one result.");
        } // end test
Ejemplo n.º 4
0
        public void TextFileProcessor_ParseData_GivenSingleLineString_ShouldReturnOneResultOnly()
        {
            // ARRANGE
            TextFileProcessor      processor = new TextFileProcessor();
            IEnumerable <DataItem> results   = null;
            string fakeString = "[2017-12-13 09:42:23.244 INFO - Data Updated] Something fun happened.";

            // ACT
            results = processor.ParseData(fakeString);

            // ASSERT
            Assert.AreEqual(1, results.Count(), "There should only have been one result.");
        } // end test
Ejemplo n.º 5
0
        public void TextFileProcessor_ParseData_GivenMultiLineStringWithTrailingEmptyLine_ShouldTrimExtraLine()
        {
            // ARRANGE
            TextFileProcessor      processor = new TextFileProcessor();
            IEnumerable <DataItem> results   = null;
            string fakeString = "[2017-12-13 09:42:23.244 INFO - Data Updated] Something fun happened." + Environment.NewLine + "[2017-12-13 11:26:19.583 INFO - Data Updated] Something different happened later." + Environment.NewLine;

            // ACT
            results = processor.ParseData(fakeString);

            // ASSERT
            Assert.AreEqual(2, results.Count(), "There should only be two results and the trailing newline ignored.");
        } // end test
Ejemplo n.º 6
0
        public void TextFileProcessor_ParseData_GivenMultiLineString_ShouldBuildMultipleResults()
        {
            // ARRANGE
            TextFileProcessor      processor = new TextFileProcessor();
            IEnumerable <DataItem> results   = null;
            string fakeString = "[2017-12-13 09:42:23.244 INFO - Data Updated] Something fun happened." + Environment.NewLine + "[2017-12-13 11:26:19.583 INFO - Data Updated] Something different happened later.";

            // ACT
            results = processor.ParseData(fakeString);

            // ASSERT
            Assert.AreEqual(2, results.Count(), "There should have been two results built from the input.");
        } // end test