コード例 #1
0
        public async Task Add_should_save_session()
        {
            // Arrange
            var fixture = new Fixture();
            var session = fixture.Create <TestFileResult>();

            MongoTestFileResultRepository repository = GetTestFileResultRepository();

            // Act
            await repository.Add(session);

            // Assert
            TestFileResultSummaryCollection summaries = await repository.GetSummaries(It.IsAny <DateTime>());

            Assert.That(summaries.TotalFileResults, Is.EqualTo(1));
        }
コード例 #2
0
        public async Task Delete_should_remove_the_session()
        {
            // Arrange
            var fixture = new Fixture();
            var session = fixture.Create <TestFileResult>();

            MongoTestFileResultRepository repository = GetTestFileResultRepository();
            await repository.Add(session);

            // Act
            await repository.Delete(session.Id);

            // Assert
            TestFileResultSummaryCollection summaries = await repository.GetSummaries(It.IsAny <DateTime>());

            Assert.That(summaries.PagedResults.Count(), Is.EqualTo(0));
        }
コード例 #3
0
        public async Task GetSummaries_should_return_sessioninfo_objects_for_today_only()
        {
            // Arrange
            var fixture       = new Fixture();
            var todaySession1 = fixture.Create <TestFileResult>();
            var todaySession2 = fixture.Create <TestFileResult>();
            var otherSession1 = fixture.Create <TestFileResult>();
            var otherSession2 = fixture.Create <TestFileResult>();

            todaySession1.StartTime = DateTime.Today;
            todaySession1.EndTime   = todaySession1.StartTime.AddMinutes(5);

            todaySession2.StartTime = DateTime.Today.AddHours(1);
            todaySession2.EndTime   = todaySession2.StartTime.AddMinutes(5);

            otherSession1.StartTime = DateTime.Today.AddDays(-2);
            otherSession1.EndTime   = otherSession1.StartTime.AddMinutes(10);

            otherSession2.StartTime = DateTime.Today.AddDays(-2);
            otherSession2.EndTime   = otherSession2.StartTime.AddMinutes(10);

            MongoTestFileResultRepository repository = GetTestFileResultRepository();
            await repository.Add(todaySession1);

            await repository.Add(todaySession2);

            await repository.Add(otherSession1);

            await repository.Add(otherSession2);

            // Act
            TestFileResultSummaryCollection summaries = await repository.GetSummaries(DateTime.Today);

            // Assert
            Assert.That(summaries.TotalFileResults, Is.EqualTo(2));

            IEnumerable <Guid> ids = summaries.PagedResults.Select(x => x.Id);

            Assert.That(ids, Contains.Item(todaySession1.Id));
            Assert.That(ids, Contains.Item(todaySession2.Id));
        }
コード例 #4
0
        public async Task GetSummaries_should_return_sessioninfos()
        {
            // Arrange
            var fixture  = new Fixture();
            var session1 = fixture.Create <TestFileResult>();
            var session2 = fixture.Create <TestFileResult>();

            MongoTestFileResultRepository repository = GetTestFileResultRepository();
            await repository.Add(session1);

            await repository.Add(session2);

            // Act
            TestFileResultSummaryCollection summaries = await repository.GetSummaries(It.IsAny <DateTime>());

            // Assert
            Assert.That(summaries.TotalFileResults, Is.EqualTo(2));

            IEnumerable <Guid> ids = summaries.PagedResults.Select(x => x.Id);

            Assert.That(ids, Contains.Item(session1.Id));
            Assert.That(ids, Contains.Item(session2.Id));
        }
コード例 #5
0
        public async Task DeleteBeforeDate_should_only_remove_entries_before_a_certain_date()
        {
            // Arrange
            MongoTestFileResultRepository repository = GetTestFileResultRepository();
            var fixture = new Fixture();

            var oldResult1 = fixture.Create <TestFileResult>();

            oldResult1.StartTime = DateTime.Now.AddDays(-10);
            await repository.Add(oldResult1);

            var oldResult2 = fixture.Create <TestFileResult>();

            oldResult2.StartTime = DateTime.Now.AddDays(-6);
            await repository.Add(oldResult2);

            var newResult1 = fixture.Create <TestFileResult>();

            newResult1.StartTime = DateTime.Now.AddDays(-4);
            await repository.Add(newResult1);

            var newResult2 = fixture.Create <TestFileResult>();

            newResult2.StartTime = DateTime.Now.AddDays(0);
            await repository.Add(newResult2);

            // Act
            await repository.DeleteBeforeDate(DateTime.Now.AddDays(-5));

            // Assert
            TestFileResultSummaryCollection summaries = await repository.GetSummaries(DateTime.MinValue);

            Assert.That(summaries.PagedResults.Count(), Is.EqualTo(2));
            Assert.That(summaries.PagedResults.Count(x => x.Id == newResult1.Id), Is.EqualTo(1));
            Assert.That(summaries.PagedResults.Count(x => x.Id == newResult2.Id), Is.EqualTo(1));
        }