예제 #1
0
        public async Task AddWeather_ReturnsSuccessfulResponse()
        {
            // Arrange & Act
            var testWeather = GetTestWeather();
            var mockRepo    = new Mock <IWeatherRepository>();

            mockRepo.Setup(repo => repo.Add(It.IsAny <WeatherObservation>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var controller = new WeatherForecastController(mockRepo.Object);

            var newWeather = new WeatherObservationDto
            {
                Date         = testWeather.Date,
                Summary      = testWeather.Summary,
                TemperatureC = testWeather.TemperatureC
            };

            // Act
            var result = await controller.Post(newWeather);

            // Assert
            Assert.IsType <OkResult>(result);
            mockRepo.Verify();
        }
        public void GivenThereIsAWeatherforecastWithTheFollowingData(Table table)
        {
            var forecasts = table.CreateSet <WeatherForecastExt>();

            foreach (var forecast in forecasts)
            {
                _weatherForecastController.Post(forecast);
            }
        }
예제 #3
0
        public async Task PostCorrectForecastObj()
        {
            // Arrange
            WeatherForecastController controller = new WeatherForecastController();

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            // Act
            var response = await controller.Post(708546);

            var content = response.Content.ReadAsStringAsync().Result;

            var norm   = normalizeJson.NormalizeObj(content);
            var result = JsonConvert.DeserializeObject <RootObject>(norm);

            // Asserts
            Assert.IsInstanceOf <City>(result.City);
            Assert.IsInstanceOf <string>(result.City.Name);
            Assert.AreEqual("Holubynka", result.City.Name);
            Assert.IsInstanceOf <int>(result.City.Id);
            Assert.AreEqual(708546, result.City.Id);
            Assert.IsInstanceOf <string>(result.City.Country);
            Assert.AreEqual("UA", result.City.Country);
            Assert.IsInstanceOf <Coord>(result.City.Coord);
            Assert.IsInstanceOf <double>(result.City.Coord.Lat);
            Assert.IsInstanceOf <double>(result.City.Coord.Lon);
            Assert.IsInstanceOf <string>(result.Cod);
            Assert.IsInstanceOf <double>(result.Message);
            Assert.IsInstanceOf <Clouds>(result.List.FirstOrDefault().Clouds);
            Assert.IsInstanceOf <int>(result.List.FirstOrDefault().Clouds.All);
            Assert.IsInstanceOf <int>(result.List.FirstOrDefault().Dt);
            Assert.IsInstanceOf <string>(result.List.FirstOrDefault().DtTxt);
            Assert.IsInstanceOf <Main>(result.List.FirstOrDefault().Main);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.TempKf);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.GrndLevel);
            Assert.IsInstanceOf <int>(result.List.FirstOrDefault().Main.Humidity);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.Pressure);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.SeaLevel);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.SeaLevel);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.Temp);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.TempMax);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Main.TempMin);
            Assert.IsInstanceOf <SysMulti>(result.List.FirstOrDefault().Sys);
            Assert.IsInstanceOf <string>(result.List.FirstOrDefault().Sys.Pod);
            Assert.IsInstanceOf <Weather>(result.List.FirstOrDefault().Weather.FirstOrDefault());
            Assert.IsInstanceOf <string>(result.List.FirstOrDefault().Weather.FirstOrDefault().Description);
            Assert.IsInstanceOf <string>(result.List.FirstOrDefault().Weather.FirstOrDefault().Icon);
            Assert.IsInstanceOf <int>(result.List.FirstOrDefault().Weather.FirstOrDefault().Id);
            Assert.IsInstanceOf <string>(result.List.FirstOrDefault().Weather.FirstOrDefault().Main);
            Assert.IsInstanceOf <Wind>(result.List.FirstOrDefault().Wind);
            Assert.IsInstanceOf <string>(result.List.FirstOrDefault().Wind.Deg);
            Assert.IsInstanceOf <double>(result.List.FirstOrDefault().Wind.Speed);
        }
예제 #4
0
        public async Task AddWeather_ReturnsBadRequest_GivenInvalidModel()
        {
            // Arrange & Act
            var mockRepo   = new Mock <IWeatherRepository>();
            var controller = new WeatherForecastController(mockRepo.Object);

            controller.ModelState.AddModelError("error", "some error");

            // Act
            var result = await controller.Post(null);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }