コード例 #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 UnitTest1()
        {
            var connection = new SqliteConnection("Data Source=:memory:");

            connection.Open();
            var options = new DbContextOptionsBuilder <MyDbContext>().UseSqlite(connection).Options;

            dbcontext = new MyDbContext(options);

            uut = new WeatherObservationsController(dbcontext, null);
        }
コード例 #3
0
        public async Task GetWeatherObservationPeriodFromADateInterval()
        {
            using (var context = new ApplicationContext(_options))
            {
                context.Database.EnsureCreated();
                WeatherObservationsController uut = new WeatherObservationsController(context, _hubContext);
                var result = await uut.GetWeatherObservationPeriod(DateTime.Today.AddDays(-11), DateTime.Today.AddDays(-10));

                Assert.Equal("Denmark", result.Value.FirstOrDefault().LocationName);
            }
        }
コード例 #4
0
        public async Task GetWeatherObservationsGet3()
        {
            using (var context = new ApplicationContext(_options))
            {
                context.Database.EnsureCreated();

                WeatherObservationsController uut = new WeatherObservationsController(context, _hubContext);

                var result = await uut.GetWeatherObservations();

                Assert.Equal(3, result.Value.Count());
            }
        }
コード例 #5
0
        public async Task PostWeatherObservationAddsToDb()
        {
            using (var context = new ApplicationContext(_options))
            {
                context.Database.EnsureCreated();
                int initial = context.WeatherObservations.ToList().Count;
                WeatherObservationsController uut   = new WeatherObservationsController(context, _hubContext);
                WeatherObservation            entry = new WeatherObservation()
                {
                    LocationName = "Poland",
                    Temperature  = 120
                };
                await uut.PostWeatherObservation(entry);

                Assert.Equal(initial + 1, context.WeatherObservations.ToList().Count);
            }
        }
コード例 #6
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));
                }));
            }
        }
コード例 #7
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));
                }));
            }
        }