public void GetTest() { var controller = new WeatherForecastController(); var result = controller.Get(); Assert.IsNotNull(result); }
public void GetForecastsWhenApiKeyIsProvided() { var controller = new WeatherForecastController(_settings); var forecasts = controller.Get(); Check.That(forecasts).As("Should return 5 forecasts").CountIs(5); }
private WeatherForecastController InstantiateWeatherForecastController() { Microsoft.Extensions.Logging.ILogger <WeatherForecastController> nullLogger = new NullLogger <WeatherForecastController>(); var weatherForecastController = new WeatherForecastController(nullLogger, configuration); return(weatherForecastController); }
public WeatherForecastControllerTests() { //_fixture = new Fixture(); _mockLogger = new Mock <ILogger <WeatherForecastController> >(); //_mockCatalogueService = new Mock<ICatalogueService>(); _controller = new WeatherForecastController(_mockLogger.Object); }
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 Test_WeatherForecastController_Get() { var controller = new WeatherForecastController( configuration: _configuration, logger: _logger, sqlConnectionBegonia: _sqlConnectionBegonia, aNNOUNCEMENT_GROUPRepository: _aNNOUNCEMENT_GROUPRepository, aNNOUNCEMENTRepository: _aNNOUNCEMENTRepository); var data = controller.Get(); var count = data.Count(); Check.That(count).IsNotZero(); /* * var announcementProvider = new Mock<IAnnouncementProvider>(); * announcementProvider * .Setup(x => x.GetList()) * .ReturnsAsync(Enumerable.Repeat(new Announcement(),1)); * * * */ }
public void GIVEN_WeatherForecastController_WHEN_get_THEN_return_correct_List() { var expected = new WeatherForecast { Date = new DateTime(2020, 01, 01), Temperature = 1, Summary = "Warm" }; var weatherForecastServiceMock = new Mock <IWeatherForecastService>(); weatherForecastServiceMock .Setup(service => service.Get()) .Returns(new List <WeatherForecast> { expected }); var weatherForecastController = new WeatherForecastController(weatherForecastServiceMock.Object); var actualResult = weatherForecastController.Get(); Assert.AreEqual(1, actualResult.Count()); var actual = actualResult.First(); Assert.AreEqual(expected.Date, actual.Date); Assert.AreEqual(expected.Summary, actual.Summary); Assert.AreEqual(expected.Temperature, actual.Temperature); }
public void Setup() { var mocklogger = new Mock <ILogger <WeatherForecastController> >(); logger = mocklogger.Object; weatherForecastController = new WeatherForecastController(logger); }
public WeatherForecastControllerTest() { var mock = new Mock <ILogger <WeatherForecastController> >(); _logger = mock.Object; _controller = new WeatherForecastController(_logger); }
public void WeatherForecastGet_ReturnsCorrectly() { var logger = new Mock <ILogger <WeatherForecastController> >(); WeatherForecastController weatherForecastController = new WeatherForecastController(logger.Object); Assert.IsNotNull(weatherForecastController.Get()); }
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 HomeController(ILogger <HomeController> logger, PostLogRepository postLogRepository, WeatherForecastController weatherForecastController, IHttpContextAccessor httpContext) { _logger = logger; _postlogrepository = postLogRepository; _weatherForecastController = weatherForecastController; _httpContext = httpContext; }
public void Get() { WeatherForecastController controller = new WeatherForecastController(null); IEnumerable <WeatherForecast> result = controller.Get(); Assert.AreEqual(result.ToList().Count, 10);//注意这里不能对比JSON格式的数据 }
public WeatherForecastControllerTest() { // prepare db and test data fixture = new WeatherForecastDbFixture(); // mock repo service var forecastService = new Mock <IWeatherForecastService>(); forecastService.Setup(s => s.GetList()).ReturnsAsync(fixture.forecastList); forecastService.Setup(s => s.GetOne(It.IsAny <int>())) .ReturnsAsync((int id) => fixture.forecastList.Where(forecast => forecast.Id == id).FirstOrDefault()); forecastService.Setup(s => s.Create(It.IsAny <CreateWeatherForecastDto>())).ReturnsAsync((CreateWeatherForecastDto createRequest) => { var newWeatherForecast = new WeatherForecast() { Id = fixture.DbContext.WeatherForecast.Count() + 1, Date = createRequest.Date, TemperatureC = createRequest.TemperatureC, Summary = createRequest.Summary }; fixture.DbContext.Add(newWeatherForecast); fixture.DbContext.SaveChanges(); fixture.forecastList.Add(newWeatherForecast); return(newWeatherForecast); }); // create controller to test controller = new WeatherForecastController(forecastService.Object); }
public void Test_Get() { WeatherForecastController wtc = new WeatherForecastController(); var teststring = wtc.Get(); Assert.IsTrue(teststring != null); }
public WeatherForecastControllerSteps( WeatherForecastController weatherForecastController, ScenarioContext scenarioContext) { _weatherForecastController = weatherForecastController; _scenarioContext = scenarioContext; }
public void TestGet() { _weatherForecastController = new WeatherForecastController(); var result = _weatherForecastController.Get(); Assert.IsType <OkObjectResult>(result.Result); }
public void Test1() { WeatherForecastController obj = new WeatherForecastController(); var result = obj.checkWeather("Chilly"); Assert.True(result); }
public void Login_Success() { ILogin login = new CustomLogin(); var controller = new WeatherForecastController(login);// new Logger<TestMethod>); Assert.IsTrue(controller.Get().Count() > 0); }
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 WeatherForecastControllerShould(ITestOutputHelper _output) { var logger = new Mock <ILogger <WeatherForecastController> >(); _con = new WeatherForecastController(logger.Object); this._output = _output; }
public void Test() { var sut = new WeatherForecastController(null); var weathers = sut.Get(); Assert.NotNull(weathers); }
public WeatherForecastControllerTest() { _loggerMock = new Mock <ILogger <WeatherForecastController> >(); _weatherMock = new Mock <IWeather>(); _summariesMock = new Mock <ISummaries>(); _forecast = new Forecast(_summariesMock.Object, _weatherMock.Object); _weatherForecastController = new WeatherForecastController(_loggerMock.Object, _forecast); }
public void WeatherForecast_ReturnsMoreThanOne() { var controller = new WeatherForecastController(); IEnumerable <WeatherForecast> result = controller.Get(); Assert.True(result.ToList().Count() > 1); }
public void Test1() { var controller = new WeatherForecastController(null); var result = controller.GetFoo(); Assert.IsType <OkResult>(result); }
public void TestController() { var logger = new Mock <ILogger <WeatherForecastController> >(); var controller = new WeatherForecastController(logger.Object); IEnumerable <WeatherForecast> wvalues = controller.Get(); Assert.AreEqual(wvalues.Count(), 5); }
public void TestGet() { WeatherForecastController lController = new WeatherForecastController(null); var lResult = lController.Get(); Assert.AreEqual(6, lResult.ToList().Count); }
public void GetWeatherList() { WeatherForecastController wfc = new WeatherForecastController(null); var retValue = wfc.Get(); Assert.Equal("Test", "Test"); }
public void Controller_Return_5_Elements() { var controller = new WeatherForecastController(null); var items = controller.Get().ToList(); Assert.Equal(5, items.Count); }
public void Test1() { var logger = Mock.Of <ILogger <WeatherForecastController> >(); var controller = new WeatherForecastController(logger); var response = controller.Get(); Assert.NotNull(response); }