public async Task GetWeatherForecast_ReturnsNotFount_WhenNoWeatherFound()
        {
            var controller = new WeatherForecastController(new Mock <IGetWeatherByLocationIdUseCase>().Object);
            var result     = await controller.GetWeatherForecast(1, ThermometricScales.Celsius);

            result.Should().BeOfType <NotFoundResult>();
        }
        public async Task GetWeatherForecast_ReturnsWeatherWithStatusOk_WhenFound()
        {
            var expectedResult = new Weather(ThermometricScales.Celsius,
                                             new Location(1, "location", "1,2", "City"),
                                             new List <Forecast>
            {
                new Forecast(ThermometricScales.Celsius, DateTime.Today, 1, 2)
            });

            var useCase = new Mock <IGetWeatherByLocationIdUseCase>();

            useCase.Setup(x => x.Execute(1, ThermometricScales.Celsius))
            .ReturnsAsync(expectedResult);

            var controller = new WeatherForecastController(useCase.Object);
            var result     = await controller.GetWeatherForecast(1, ThermometricScales.Celsius);

            var objectResultAssertion = result.Should().BeOfType <OkObjectResult>();

            objectResultAssertion.Which.StatusCode.Should()
            .Be(StatusCodes.Status200OK);

            objectResultAssertion.Which.Value.Should()
            .BeEquivalentTo(expectedResult);
        }
        public async Task GetWeatherForecast_ReturnsNoContent_WhenForecastsIsEmpty()
        {
            var useCase = new Mock <IGetWeatherByLocationIdUseCase>();

            useCase.Setup(x => x.Execute(1, ThermometricScales.Celsius))
            .ReturnsAsync(new Weather(ThermometricScales.Celsius,
                                      new Location(1, "location", "1,2", "City"),
                                      new List <Forecast>()));

            var controller = new WeatherForecastController(useCase.Object);
            var result     = await controller.GetWeatherForecast(1, ThermometricScales.Celsius);

            result.Should().BeOfType <NoContentResult>();
        }
Beispiel #4
0
        public void WeatherForecastHandlesExceptions()
        {
            // Arrange
            const string exception_message          = "let's focus on the future";
            var          mockWeatherForecastService = new Mock <IWeatherForecastService>();

            mockWeatherForecastService
            .Setup(s => s.Forecast(It.Is <int>(d => d < 1)))
            .Throws(new ArgumentOutOfRangeException(exception_message));
            var controller = new WeatherForecastController(mockLogger.Object, mockWeatherForecastService.Object);

            // Act
            var response = controller.GetWeatherForecast(-1);

            // Assert
            var result = Assert.IsAssignableFrom <ProblemDetails>(response.Result);

            Assert.Equal(exception_message, result.Detail);
        }
        public void TestMethodGet()
        {
            var result = WeatherForecastController.GetWeatherForecast();

            Assert.AreEqual(5, result.Count());
        }
        public void Test1()
        {
            var result = _controller.GetWeatherForecast().ToList();

            Assert.Equal(5, result.Count);
        }