コード例 #1
0
ファイル: ApiTests.cs プロジェクト: syedkai/syedkai
        public void GetTest()
        {
            var controller = new WeatherForecastController();
            var result     = controller.Get();

            Assert.IsNotNull(result);
        }
コード例 #2
0
        public void GetForecastsWhenApiKeyIsProvided()
        {
            var controller = new WeatherForecastController(_settings);
            var forecasts  = controller.Get();

            Check.That(forecasts).As("Should return 5 forecasts").CountIs(5);
        }
コード例 #3
0
        private WeatherForecastController InstantiateWeatherForecastController()
        {
            Microsoft.Extensions.Logging.ILogger <WeatherForecastController> nullLogger = new NullLogger <WeatherForecastController>();
            var weatherForecastController = new WeatherForecastController(nullLogger, configuration);

            return(weatherForecastController);
        }
コード例 #4
0
 public WeatherForecastControllerTests()
 {
     //_fixture = new Fixture();
     _mockLogger = new Mock <ILogger <WeatherForecastController> >();
     //_mockCatalogueService = new Mock<ICatalogueService>();
     _controller = new WeatherForecastController(_mockLogger.Object);
 }
コード例 #5
0
        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();
        }
コード例 #6
0
        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));
             *
             *
             *
             */
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: debjyoti0007/DevOpsTest
        public void Setup()
        {
            var mocklogger = new Mock <ILogger <WeatherForecastController> >();

            logger = mocklogger.Object;
            weatherForecastController = new WeatherForecastController(logger);
        }
コード例 #9
0
        public WeatherForecastControllerTest()
        {
            var mock = new Mock <ILogger <WeatherForecastController> >();

            _logger     = mock.Object;
            _controller = new WeatherForecastController(_logger);
        }
コード例 #10
0
        public void WeatherForecastGet_ReturnsCorrectly()
        {
            var logger = new Mock <ILogger <WeatherForecastController> >();
            WeatherForecastController weatherForecastController = new WeatherForecastController(logger.Object);

            Assert.IsNotNull(weatherForecastController.Get());
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 public HomeController(ILogger <HomeController> logger, PostLogRepository postLogRepository, WeatherForecastController weatherForecastController, IHttpContextAccessor httpContext)
 {
     _logger                    = logger;
     _postlogrepository         = postLogRepository;
     _weatherForecastController = weatherForecastController;
     _httpContext               = httpContext;
 }
コード例 #13
0
ファイル: webapi.cs プロジェクト: Gongting169/sourcestack1
        public void Get()
        {
            WeatherForecastController     controller = new WeatherForecastController(null);
            IEnumerable <WeatherForecast> result     = controller.Get();

            Assert.AreEqual(result.ToList().Count, 10);//注意这里不能对比JSON格式的数据
        }
コード例 #14
0
        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);
        }
コード例 #16
0
 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);
        }
コード例 #18
0
        public void Test1()
        {
            WeatherForecastController obj = new WeatherForecastController();
            var result = obj.checkWeather("Chilly");

            Assert.True(result);
        }
コード例 #19
0
        public void Login_Success()
        {
            ILogin login      = new CustomLogin();
            var    controller = new WeatherForecastController(login);// new Logger<TestMethod>);

            Assert.IsTrue(controller.Get().Count() > 0);
        }
コード例 #20
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>();
        }
コード例 #21
0
        public WeatherForecastControllerShould(ITestOutputHelper _output)
        {
            var logger = new Mock <ILogger <WeatherForecastController> >();

            _con         = new WeatherForecastController(logger.Object);
            this._output = _output;
        }
コード例 #22
0
        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);
 }
コード例 #24
0
        public void WeatherForecast_ReturnsMoreThanOne()
        {
            var controller = new WeatherForecastController();
            IEnumerable <WeatherForecast> result = controller.Get();


            Assert.True(result.ToList().Count() > 1);
        }
コード例 #25
0
        public void Test1()
        {
            var controller = new WeatherForecastController(null);

            var result = controller.GetFoo();

            Assert.IsType <OkResult>(result);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        public void TestGet()
        {
            WeatherForecastController lController = new WeatherForecastController(null);

            var lResult = lController.Get();

            Assert.AreEqual(6, lResult.ToList().Count);
        }
コード例 #28
0
        public void GetWeatherList()
        {
            WeatherForecastController wfc = new WeatherForecastController(null);

            var retValue = wfc.Get();

            Assert.Equal("Test", "Test");
        }
コード例 #29
0
        public void Controller_Return_5_Elements()
        {
            var controller = new WeatherForecastController(null);

            var items = controller.Get().ToList();

            Assert.Equal(5, items.Count);
        }
コード例 #30
0
        public void Test1()
        {
            var logger     = Mock.Of <ILogger <WeatherForecastController> >();
            var controller = new WeatherForecastController(logger);
            var response   = controller.Get();

            Assert.NotNull(response);
        }