Beispiel #1
0
        public async void GetCurrentWeather_Valid()
        {
            var owmProvider    = Substitute.For <IOWMProvider>();
            var currentWeather = new CurrentWeatherData()
            {
                Timestamp            = new DateTime(2020, 07, 22, 18, 47, 01, DateTimeKind.Utc),
                Sunrise              = new DateTime(2020, 07, 22, 18, 47, 01, DateTimeKind.Utc),
                Sunset               = new DateTime(2020, 07, 22, 18, 47, 01, DateTimeKind.Utc),
                Temperature          = 20.3f,
                TemperatureFeelsLike = 19.72f,
                Pressure             = 971,
                Humidity             = 80,
                UVIndex              = 4.7f,
                Clouds               = 29,
                Visibility           = 8000,
                WindSpeed            = 100,
                WindDirection        = 300,
                Weather              = new WeatherCondition
                {
                    Description = "Many clouds!",
                    IconId      = "10d"
                }
            };

            owmProvider.GetCurrentWeatherAsync().Returns(Task.FromResult(currentWeather));
            var controller = new WeatherController(owmProvider);

            var result = await controller.GetCurrentWeather();

            var okResult      = Assert.IsType <OkObjectResult>(result.Result);
            var resultWeather = Assert.IsType <CurrentWeatherData>(okResult.Value);

            Assert.Equal(currentWeather, resultWeather);
        }
Beispiel #2
0
        public void GetCurrentWeatherOK()
        {
            WeatherController cont = new WeatherController();
            var result             = cont.GetCurrentWeather("dnipro");

            Assert.IsNotNull(result);
        }
Beispiel #3
0
        public async void GetCurrentWeather_DataNull()
        {
            var owmProvider = Substitute.For <IOWMProvider>();
            CurrentWeatherData currentWeather = null;

            owmProvider.GetCurrentWeatherAsync().Returns(Task.FromResult(currentWeather));
            var controller = new WeatherController(owmProvider);

            var result = await controller.GetCurrentWeather();

            Assert.IsType <NotFoundResult>(result.Result);
        }
Beispiel #4
0
 public void GetCurrentWeather404()
 {
     try
     {
         WeatherController cont = new WeatherController();
         var result             = cont.GetCurrentWeather("d");
     }
     catch (Exception ex)
     {
         Assert.IsNotNull(ex);
     }
 }
        public void GivenMockResponse_GetCurrentWeather_ShouldReturnValidData()
        {
            var mediatorMock = new Mock <IMediator>();

            mediatorMock.Setup(m => m.Send(It.IsAny <GetCurrentWeatherQuery>(), It.IsAny <System.Threading.CancellationToken>()))
            .ReturnsAsync((new WeatherOutputModel(5, 23), string.Empty));

            WeatherController controller = new WeatherController(mediatorMock.Object);

            var result        = controller.GetCurrentWeather("Melbourne").Result as OkObjectResult;
            var responseValue = result?.Value as WeatherOutputModel;

            Assert.NotNull(responseValue);
            Assert.Equal(5, responseValue.wind_speed);
            Assert.Equal(23, responseValue.temperature_degrees);
        }