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)); })); } }
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)); })); } }
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)); })); } }