public void Process_WhenOneOrMoreInputEntryHasNoType_ShouldNotThrowException() { var outputMock = new Mock <IDBLogWriter>(); var inputMock = new Mock <ILogRepository>(); Dictionary <string, JsonLogEntry> fileLogDataStart = CreateInputWithOneStartedEventWithoutType(); Dictionary <string, JsonLogEntry> fileLogDataStop = CreateInputWithOneStoppedEventWithoutType(); inputMock.Setup(i => i.GetStartedEntries()).Returns(fileLogDataStart); inputMock.Setup(i => i.GetStoppedEntries()).Returns(fileLogDataStop); var sut = new LogParsingService(inputMock.Object, outputMock.Object); sut.Process(); Assert.IsTrue(true); }
public void TestLog2DB() { // Arrange var testDbPath = @"MyData.db"; File.Delete(testDbPath); var input = FileLogService.LoadFromFile(@"..\..\..\..\..\logfile.txt"); var output = new LogWriterService(testDbPath, "LogEntries"); var service = new LogParsingService(input, output, 4); // Act service.Process(); // Assert var result = output.GetLogEntries(); Assert.IsTrue(result.Count == 3); }
public void Process_WhenStartedEventExistsButNoAccordingStoppedEvent_ShouldNotThrowException() { // Arrange var outputMock = new Mock <IDBLogWriter>(); var inputMock = new Mock <ILogRepository>(); var fileLogDataStart = CreateInputWithOneStartedEventWithoutType(); var fileLogDataStop = new Dictionary <string, JsonLogEntry>(); inputMock.Setup(i => i.GetStartedEntries()).Returns(fileLogDataStart); inputMock.Setup(i => i.GetStoppedEntries()).Returns(fileLogDataStop); var sut = new LogParsingService(inputMock.Object, outputMock.Object); // Act sut.Process(); // Assert Assert.IsTrue(true); }
public void Process_WhenStartedEntryHasNoHostButStoppedHas_ShouldWriteHostFromStoppedEntry() { // Arrange var outputMock = new Mock <IDBLogWriter>(); var inputMock = new Mock <ILogRepository>(); Dictionary <string, JsonLogEntry> fileLogDataStart = CreateInputWithOneStartedEventWithoutHost(); Dictionary <string, JsonLogEntry> fileLogDataStop = CreateInputWithOneStoppedWithHost(); inputMock.Setup(i => i.GetStartedEntries()).Returns(fileLogDataStart); inputMock.Setup(i => i.GetStoppedEntries()).Returns(fileLogDataStop); var sut = new LogParsingService(inputMock.Object, outputMock.Object); // Act sut.Process(); // Assert outputMock.Verify(o => o.InsertLogEntry(It.Is <DBLogEntry>(l => l.Id == "id" && l.Host == "host"))); }
public void Process_WhenInputHasOneEntryDurationOverThreshold_EntryInDbShouldBeAlerted() { // Arrange var outputMock = new Mock <IDBLogWriter>(); var inputMock = new Mock <ILogRepository>(); Dictionary <string, JsonLogEntry> fileLogDataStart = CreateInputWithOneStartedEventWithZeroTimeStamp(); Dictionary <string, JsonLogEntry> fileLogDataStop = CreateInputWithOneStoppedEventWithTenTimeStamp(); inputMock.Setup(i => i.GetStartedEntries()).Returns(fileLogDataStart); inputMock.Setup(i => i.GetStoppedEntries()).Returns(fileLogDataStop); var sut = new LogParsingService(inputMock.Object, outputMock.Object, 4); // Act sut.Process(); // Assert outputMock.Verify(o => o.InsertLogEntry(It.Is <DBLogEntry>(l => l.Id == "id" && l.Alert == true))); }