示例#1
0
        public async Task GetObservations_DbSeeded_ReturnsDtoWeatherObservationsWithCorrectDates()
        {
            // Arrange
            await using (var context = new ApplicationDbContext(_options))
            {
                _uut = new WeatherObservationsController(context, _mockHub);

                // Act
                var result = await _uut.GetObservations();

                var returnedList = result.Value.ToList();

                // Assert
                var expectedDtoWeatherObservations =
                    GetDtoWeatherObservationsForTest().OrderByDescending(o => o.Date).Take(3).ToList();

                Assert.Multiple((() =>
                {
                    Assert.That(returnedList.Count, Is.EqualTo(3));

                    Assert.That(returnedList[0].Date, Is.EqualTo(expectedDtoWeatherObservations[0].Date));
                    Assert.That(returnedList[1].Date, Is.EqualTo(expectedDtoWeatherObservations[1].Date));
                    Assert.That(returnedList[2].Date, Is.EqualTo(expectedDtoWeatherObservations[2].Date));
                }));
            }
        }
示例#2
0
        public async Task GetObservations_WithDateInitialTimePlus1Day_DbSeeded_ReturnsOneDtoWeatherObservationWithCorrectDate()
        {
            // Arrange

            DateTime date = _initialTime.AddDays(1).Date; // Test data should only contain one observation with this date

            await using (var context = new ApplicationDbContext(_options))
            {
                _uut = new WeatherObservationsController(context, _mockHub);

                // Act
                var result = await _uut.GetObservations(date);

                var returnedList = result.Value.ToList();

                // Assert
                Assert.Multiple((() =>
                {
                    Assert.That(returnedList.Count, Is.EqualTo(1));
                    Assert.That(returnedList[0].Date.Date, Is.EqualTo(date));
                }));
            }
        }
示例#3
0
        public async Task GetObservations_WithTimeSpanThreeHours_DbSeeded_ReturnsCorrectDtoWeatherObservations()
        {
            // Arrange
            DateTime startTime = _initialTime;
            DateTime endTime   = _initialTime.AddHours(3); //Should only contain 2 weatherObservations in this time-range

            await using (var context = new ApplicationDbContext(_options))
            {
                _uut = new WeatherObservationsController(context, _mockHub);

                // Act
                var result = await _uut.GetObservations(startTime, endTime);

                var returnedList = result.Value.ToList();

                // Assert
                Assert.Multiple((() =>
                {
                    Assert.That(returnedList.Count, Is.EqualTo(2));
                    Assert.That(returnedList[0].Date, Is.GreaterThanOrEqualTo(startTime).And.LessThanOrEqualTo(endTime));
                    Assert.That(returnedList[1].Date, Is.GreaterThanOrEqualTo(startTime).And.LessThanOrEqualTo(endTime));
                }));
            }
        }