예제 #1
0
        public async Task Test_GetWeatherForecastsAsync_Returns_Weather()
        {
            Db.Recreate();

            var now = DateTime.UtcNow;

            using (WeatherDbContext ctx = Db.GetAdminContext())
            {
                ctx.Set <WeatherForecastEntity>()
                .AddRange(new WeatherForecastEntity
                {
                    Id           = Guid.NewGuid(),
                    Date         = now,
                    Summary      = "sum-1",
                    TemperatureC = 1
                }, new WeatherForecastEntity
                {
                    Id           = Guid.NewGuid(),
                    Date         = now.AddDays(-1),
                    Summary      = "sum-2",
                    TemperatureC = 1
                });
                await ctx.SaveChangesAsync();
            }

            IWeatherForecastClient client = Integration.CreateClient();

            WeatherForecastGetModel[] models = await client.GetWeatherForecasts(CancellationToken.None);

            Assert.AreEqual(2, models.Length);
            Assert.AreEqual("sum-1", models[0].Summary);
            Assert.AreEqual("sum-2", models[1].Summary);
        }
예제 #2
0
        public async Task LogOverTemperatureDates()
        {
            var result = await _weatherForecastClient.GetWeatherForecasts();

            var forecastsOverThan30Degree = result.Where(x => x.TemperatureC > 30);

            foreach (var weatherForecast in forecastsOverThan30Degree)
            {
                _logger.LogWarning($"日期: {weatherForecast.Date} 氣溫過高,禁止室外操課!");
            }
        }