public void CleanupStatistics_Should_Delete_All_Invalid_Statistics() { RunTest(() => { var statisticOne = new Statistic { Id = Guid.NewGuid(), Type = StatisticType.Movie, CalculationDateTime = DateTime.Now.AddDays(-1), JsonResult = "", IsValid = false, CollectionIds = new string[0] }; var statisticTwo = new Statistic { Id = Guid.NewGuid(), Type = StatisticType.Movie, CalculationDateTime = DateTime.Now, JsonResult = "", IsValid = true, CollectionIds = new string[0] }; var statisticThree = new Statistic { Id = Guid.NewGuid(), Type = StatisticType.Show, CalculationDateTime = DateTime.Now.AddDays(1), JsonResult = "", IsValid = true, CollectionIds = new string[0] }; var statisticFour = new Statistic { Id = Guid.NewGuid(), Type = StatisticType.Movie, CalculationDateTime = DateTime.Now.AddDays(2), JsonResult = "", IsValid = true, CollectionIds = new[] { "1" } }; using (var database = _context.LiteDatabase) { var collection = database.GetCollection <Statistic>(); collection.InsertBulk(new[] { statisticOne, statisticTwo, statisticThree, statisticFour }); var statistics = collection.FindAll().ToList(); statistics.Count.Should().Be(4); } _statisticsRepository.CleanupStatistics(); using (var database = _context.LiteDatabase) { var collection = database.GetCollection <Statistic>(); var statistics = collection.FindAll().OrderBy(x => x.CalculationDateTime).ToList(); statistics.Count.Should().Be(3); statistics[0].Should().NotBeNull(); statistics[0].Id.Should().Be(statisticTwo.Id); statistics[0].CalculationDateTime.Should().BeCloseTo(statisticTwo.CalculationDateTime, 10); statistics[0].CollectionIds.Should().BeEquivalentTo(statisticTwo.CollectionIds); statistics[0].IsValid.Should().BeTrue(); statistics[0].Type.Should().Be(statisticTwo.Type); statistics[1].Should().NotBeNull(); statistics[1].Id.Should().Be(statisticThree.Id); statistics[1].CalculationDateTime.Should().BeCloseTo(statisticThree.CalculationDateTime, 10); statistics[1].CollectionIds.Should().BeEquivalentTo(statisticThree.CollectionIds); statistics[1].IsValid.Should().BeTrue(); statistics[1].Type.Should().Be(statisticThree.Type); statistics[2].Should().NotBeNull(); statistics[2].Id.Should().Be(statisticFour.Id); statistics[2].CalculationDateTime.Should().BeCloseTo(statisticFour.CalculationDateTime, 10); statistics[2].CollectionIds.Should().BeEquivalentTo(statisticFour.CollectionIds); statistics[2].IsValid.Should().BeTrue(); statistics[2].Type.Should().Be(statisticFour.Type); } }); }