public async Task PostWeatherLog_SeededLogs()
        {
            //Arrange
            _context = new ApplicationDbContext(
                new DbContextOptionsBuilder <ApplicationDbContext>().UseSqlite(CreateInMemoryDatabase()).Options);
            _mockHub           = Substitute.For <IHubContext <WeatherHub> >();
            _weatherController = new WeatherLogsController(_context, _mockHub);
            Seed();

            WeatherLogDto tempweatherlog = new WeatherLogDto()
            {
                LogTime     = new DateTime(2021, 10, 9, 8, 00, 00),
                LogPlaceId  = 1,
                Temperature = 24,
                Humidity    = 90,
                AirPressure = 85
            };

            //Act
            var res = await _weatherController.PostWeatherLog(tempweatherlog);

            var got = await _weatherController.GetWeatherLog(4);

            //Assert
            Assert.Equal(90, got.Value.Humidity);

            Dispose();
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <WeatherLog> > PostWeatherLog(WeatherLogDto weatherLogDto)
        {
            var place = await _context.Places.FindAsync(weatherLogDto.LogPlaceId);

            if (place == null)
            {
                return(NotFound());
            }
            WeatherLog weatherLog = new WeatherLog()
            {
                LogTime     = weatherLogDto.LogTime,
                LogPlace    = place,
                Temperature = weatherLogDto.Temperature,
                Humidity    = weatherLogDto.Humidity,
                AirPressure = weatherLogDto.AirPressure
            };

            _context.WeatherLogs.Add(weatherLog);

            await _context.SaveChangesAsync();

            //==================  SignalR ===================
            var placeid = weatherLog.LogPlace.PlaceId;
            var jsonmsg = JsonConvert.SerializeObject(weatherLog);
            await _weatherHub.Clients.All.SendAsync("WeatherUpdate", jsonmsg);

            return(CreatedAtAction("GetWeatherLog", new { id = weatherLog.LogId }, weatherLog));
        }
        public async Task PostWeatherLog_SeededLogs()
        {
            WeatherLogDto tempweatherlog = new WeatherLogDto()
            {
                LogTime     = new DateTime(2021, 10, 9, 8, 00, 00),
                LogPlaceId  = 1,
                Temperature = 24,
                Humidity    = 90,
                AirPressure = 85
            };

            var res = await _weatherController.PostWeatherLog(tempweatherlog);

            var got = await _weatherController.GetWeatherLog(4);

            Assert.Equal(90, got.Value.Humidity);
        }