public void AggregatesAllLogsForTheLastThreedays() { using (ShimsContext.Create()) { // Arrange var sut = new LogAggregator(); ShimDirectory.GetFilesStringString = (path, seachPattern) => new[] { @"C:\someLogDir\Log_20180801.log", @"C:\someLogDir\Log_20180827.log", @"C:\someLogDir\Log_20180829.log" }; ShimFile.ReadAllLinesString = path => { switch (path) { case @"C:\someLogDir\Log_20180801.log": return(new[] { "OctFirstLine1", "OctFirstLine2" }); case @"C:\someLogDir\Log_20180827.log": return(new[] { "2DaysAgoPickedUpLine", "SOmethingElse" }); case @"C:\someLogDir\Log_20180829.log": return(new[] { "OctFifthLine1", "TodayLastLine" }); default: return(new string[] { }); } }; ShimDateTime.TodayGet = () => new DateTime(2018, 08, 29); // Act var logResults = sut.AggregateLogs(@"C:\SomeDir", 3); // Assert Assert.AreEqual(4, logResults.Length); Assert.Contains("2DaysAgoPickedUpLine", logResults); Assert.Contains("TodayLastLine", logResults); } }
public void AggregateLogs_PastThreeDays_ReturnsAllLinesFromPastThreeDays() { using (ShimsContext.Create()) { // Arrange var sut = new LogAggregator(); ShimDirectory.GetFilesStringString = (dir, pattern) => new[] { @"C:\someLogDir\Log_20121001.log", @"C:\someLogDir\Log_20121002.log", @"C:\someLogDir\Log_20121005.log" }; ShimFile.ReadAllLinesString = path => { switch (path) { case @"C:\someLogDir\Log_20121001.log": return(new[] { "OctFirstLine1", "OctFirstLine2" }); case @"C:\someLogDir\Log_20121002.log": return(new[] { "ThreeDaysAgoFirstLine", "OctSecondLine2" }); case @"C:\someLogDir\Log_20121005.log": return(new[] { "OctFifthLine1", "TodayLastLine" }); } return(new string[] { }); }; ShimDateTime.TodayGet = () => new DateTime(2012, 10, 05); // Act var result = sut.AggregateLogs(@"C:\SomeLogDir", daysInPast: 3); // Assert Assert.AreEqual(4, result.Length, "Number of aggregated lines incorrect."); CollectionAssert.Contains(result, "ThreeDaysAgoFirstLine", "Expected line missing from aggregated log."); CollectionAssert.Contains(result, "TodayLastLine", "Expected line missing from aggregated log."); } }