public async Task ForGetWeatherById_ReturnsNotFoundObjectResultForNonexistent() { // Arrange var mockRepo = new Mock <IWeatherRepository>(); var controller = new WeatherForecastController(mockRepo.Object); var nonExistentSessionId = 999; //// Act var result = await controller.GetById(nonExistentSessionId); //// Assert var actionResult = Assert.IsType <ActionResult <WeatherObservationDto> >(result); Assert.IsType <NotFoundObjectResult>(actionResult.Result); }
public async Task ForGetWeatherById_ReturnsWeatherObject() { // Arrange int weatherId = 2; var mockRepo = new Mock <IWeatherRepository>(); mockRepo.Setup(repo => repo.GetById(weatherId)) .ReturnsAsync(GetTestWeather()); var controller = new WeatherForecastController(mockRepo.Object); // Act var result = await controller.GetById(weatherId); // Assert var actionResult = Assert.IsType <ActionResult <WeatherObservationDto> >(result); var returnValue = Assert.IsType <WeatherObservationDto>(actionResult.Value); Assert.Equal("Warm", returnValue.Summary); Assert.Equal(21, returnValue.TemperatureC); }
public void GetDateByAddingIndex() { var item = controller.GetById(1); Assert.Equal(DateTime.Now.AddDays(1).Date, item.Date.Date); }