Exemplo n.º 1
0
        public void TestGetTimePeriods()
        {
            var service = new TimePeriodService();

            var apiResponse = new SchedulingApiResponse()
            {
                StartOfTimePeriod = "2017-03-01",
                EndOfTimePeriod   = "2017-04-04",
                DaysInPeriod      = 7
            };

            var timePeriods = service.GetTimePeriods(apiResponse);

            Assert.Equal(5, timePeriods.Count);

            var validPeriods = new List <TimePeriod>()
            {
                new TimePeriod {
                    Start = new DateTime(2017, 3, 1),
                    End   = new DateTime(2017, 3, 8),
                },
                new TimePeriod {
                    Start = new DateTime(2017, 3, 8),
                    End   = new DateTime(2017, 3, 15),
                },
                new TimePeriod {
                    Start = new DateTime(2017, 3, 15),
                    End   = new DateTime(2017, 3, 22),
                },
                new TimePeriod {
                    Start = new DateTime(2017, 3, 22),
                    End   = new DateTime(2017, 3, 29),
                },
                new TimePeriod {
                    Start = new DateTime(2017, 3, 29),
                    End   = new DateTime(2017, 4, 4),
                },
            };

            for (int i = 0; i < timePeriods.Count; i++)
            {
                var validPeriod   = validPeriods[i];
                var currentPeriod = timePeriods[i];

                Assert.Equal(validPeriod.Start, currentPeriod.Start);
                Assert.Equal(validPeriod.End, currentPeriod.End);
            }
        }
Exemplo n.º 2
0
        public async Task GetTimePeriods_Observations_CorrectlyOrderWeeklyTimeIdentifiers()
        {
            var obs1 = new Observation {
                Year = 2001, TimeIdentifier = Week1
            };
            var obs2 = new Observation {
                Year = 2000, TimeIdentifier = Week20
            };
            var obs3 = new Observation {
                Year = 2000, TimeIdentifier = Week2
            };
            var obs4 = new Observation {
                Year = 2000, TimeIdentifier = Week1
            };
            var obs5 = new Observation {
                Year = 2000, TimeIdentifier = Week10
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddRangeAsync(obs1, obs2, obs3, obs4, obs5);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = new TimePeriodService(statisticsDbContext);
                var queryableObservations = statisticsDbContext.Observation.AsQueryable();
                var result = service.GetTimePeriods(queryableObservations).ToList();

                Assert.Equal(5, result.Count);
                Assert.Equal((2000, Week1), result[0]);
                Assert.Equal((2000, Week2), result[1]);
                Assert.Equal((2000, Week10), result[2]);
                Assert.Equal((2000, Week20), result[3]);
                Assert.Equal((2001, Week1), result[4]);
            }
        }
Exemplo n.º 3
0
        public async Task GetTimePeriods_Subject_CorrectlyOrderMonthlyTimeIdentifiers()
        {
            var subject = new Subject
            {
                Observations = new List <Observation>
                {
                    new() { Year = 2001, TimeIdentifier = January },
                    new() { Year = 2000, TimeIdentifier = February },
                    new() { Year = 2000, TimeIdentifier = December },
                    new() { Year = 2000, TimeIdentifier = October },
                    new() { Year = 2000, TimeIdentifier = March },
                }
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(subject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = new TimePeriodService(statisticsDbContext);
                var result  = service.GetTimePeriods(subject.Id).ToList();

                Assert.Equal(5, result.Count);
                Assert.Equal((2000, February), result[0]);
                Assert.Equal((2000, March), result[1]);
                Assert.Equal((2000, October), result[2]);
                Assert.Equal((2000, December), result[3]);
                Assert.Equal((2001, January), result[4]);
            }
        }
Exemplo n.º 4
0
        public async Task GetTimePeriods_Subject_CorrectlyOrderWeeklyTimeIdentifiers()
        {
            var subject = new Subject
            {
                Observations = new List <Observation>
                {
                    new() { Year = 2001, TimeIdentifier = Week1 },
                    new() { Year = 2000, TimeIdentifier = Week20 },
                    new() { Year = 2000, TimeIdentifier = Week2 },
                    new() { Year = 2000, TimeIdentifier = Week1 },
                    new() { Year = 2000, TimeIdentifier = Week10 },
                }
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(subject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = new TimePeriodService(statisticsDbContext);
                var result  = service.GetTimePeriods(subject.Id).ToList();

                Assert.Equal(5, result.Count);
                Assert.Equal((2000, Week1), result[0]);
                Assert.Equal((2000, Week2), result[1]);
                Assert.Equal((2000, Week10), result[2]);
                Assert.Equal((2000, Week20), result[3]);
                Assert.Equal((2001, Week1), result[4]);
            }
        }