Beispiel #1
0
        public void GetForecastOK()
        {
            WeatherController cont = new WeatherController();
            var result             = cont.GetForecast("dnipro");

            Assert.IsNotNull(result);
        }
Beispiel #2
0
 public void GetForecast404()
 {
     try
     {
         WeatherController cont = new WeatherController();
         var result             = cont.GetForecast("d");
     }
     catch (Exception ex)
     {
         Assert.IsNotNull(ex);
     }
 }
        public async Task GetForecast_ByDefault_ReturnsOkObjectResult()
        {
            var weatherServiceStub = new Mock <IWeatherService>();
            var mapperServiceStub  = new Mock <IMapper>();

            weatherServiceStub.Setup(e => e.GetForecast(It.IsAny <string>()))
            .Returns(Task.FromResult(new WeatherDto()));

            var weatherController = new WeatherController
                                        (weatherServiceStub.Object, mapperServiceStub.Object);
            var actual = await weatherController.GetForecast(It.IsAny <string>());

            Assert.IsAssignableFrom <OkObjectResult>(actual);
        }
        public async Task GetForecast_WhenInvalidCity_ThrowsException()
        {
            var weatherServiceStub = new Mock <IWeatherService>();
            var mapperServiceStub  = new Mock <IMapper>();

            weatherServiceStub.Setup(e => e.GetForecast(It.IsAny <string>()))
            .Returns(Task.FromResult(new WeatherDto()));
            weatherServiceStub.Setup(e => e.GetForecast(It.Is <string>(m => m != "Warsaw")))
            .Throws <ForecastException>();

            var weatherController = new WeatherController
                                        (weatherServiceStub.Object, mapperServiceStub.Object);
            var actual = weatherController.GetForecast(It.Is <string>(m => m != "Warsaw"));

            await Assert.ThrowsAsync <ForecastException>(() => actual);
        }