public void TextFileProcessor_ParseLine_WithEmptyString_ShouldThrowException() { // ARRANGE TextFileProcessor processor = new TextFileProcessor(); // ACT // No act as we're checking an exception // ASSERT Assert.Throws <ArgumentNullException>(() => processor.ParseLine(string.Empty), "The method should have thrown an exception."); } // end test
public void TextFileProcessor_ParseLine_GivenStringWithMissingOperation_ShouldThrowException() { // ARRANGE TextFileProcessor processor = new TextFileProcessor(); string fakeString = "[2017-12-13 09:df:23.244 INFO]"; // ACT // No act as we're checking an exception // ASSERT Assert.Throws <FormatException>(() => processor.ParseLine(fakeString), "The method should have thrown an exception."); } // end test
public void TextFileProcessor_ParseLine_GivenStringWithMissingSeverity_ShouldThrowException() { // ARRANGE TextFileProcessor processor = new TextFileProcessor(); string fakeString = "[2017-12-13 09:14:23.244 - Data Updated]"; // ACT // No act as we're checking an exception // ASSERT Assert.Throws <IndexOutOfRangeException>(() => processor.ParseLine(fakeString), "The method should have thrown an exception."); } // end test
public void TextFileProcessor_ParseLine_GivenValidStringWithNoMessage_ShouldBuildObjectWithEmptyMessage() { // ARRANGE TextFileProcessor processor = new TextFileProcessor(); DataItem resultItem = null; string fakeString = "[2017-12-13 09:42:23.244 INFO - Data Updated]"; // ACT resultItem = processor.ParseLine(fakeString); // ASSERT Assert.NotNull(resultItem, "The function should have built a data item."); Assert.IsEmpty(resultItem.Data, "No data should have been populated."); } // end test
public void TextFileProcessor_ParseLine_GivenValidEntry_ShouldBuildNewObjectWithValues(string inputOperation, string inputDateTime, ItemSeverity inputSeverity, string inputMessage) { // ARRANGE DateTime expectedTime = DateTime.Parse(inputDateTime); string timeFormat = "yyyy-MM-dd HH:mm:ss.fff"; TextFileProcessor processor = new TextFileProcessor(); DataItem resultItem = null; string fakeString = string.Concat("[", expectedTime.ToString(timeFormat), " ", inputSeverity.ToString(), " - ", inputOperation, "] ", inputMessage); // ACT resultItem = processor.ParseLine(fakeString); // ASSERT Assert.NotNull(resultItem, "The method should have built a data item."); Assert.AreEqual(inputOperation, resultItem.Operation, "The operation was not built properly."); Assert.AreEqual(expectedTime.ToString(timeFormat), resultItem.TimeStamp.ToString(timeFormat), "The date / time was not built properly."); Assert.AreEqual(inputSeverity, resultItem.Severity, "The severity was not built properly."); Assert.AreEqual(inputMessage, resultItem.Data, "The data was not build properly."); } // end test