Beispiel #1
0
        public async Task Weather_Controller_Should_Return_Weather_By_City_Coord(float lon, float lat)
        {
            ApplicationData applicationData = new ApplicationData
            {
                OWMUrl    = "https://api.openweathermap.org/data/2.5/weather?",
                OWMApiKey = "f1b58a47aa129daa6330e7280a88e7b5"
            };

            var options = Options.Create <ApplicationData>(applicationData);

            var mockFactory = new Mock <IHttpClientFactory>();
            var client      = new HttpClient();

            mockFactory.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(client);
            IHttpClientFactory factory = mockFactory.Object;

            IClientService    clientService  = new ClientService(factory);
            IWeatherService   weatherService = new WeatherService(clientService, options);
            WeatherController controller     = new WeatherController(weatherService);

            var result = await controller.GetCurrentWeatherByCityCoord(new API.Models.WeatherDetails.Coord
            {
                Lat = lat,
                Lon = lon
            });

            Assert.NotNull(result.Value.ResponseBody);
            Assert.IsType <WeatherModel>(result.Value.ResponseBody);
        }
Beispiel #2
0
        public async Task Weather_Controller_Should_Throw_ArgumentNullException()
        {
            ApplicationData applicationData = new ApplicationData
            {
                OWMUrl    = "https://api.openweathermap.org/data/2.5/weather?",
                OWMApiKey = "f1b58a47aa129daa6330e7280a88e7b5"
            };

            var options = Options.Create <ApplicationData>(applicationData);

            var mockFactory = new Mock <IHttpClientFactory>();
            var client      = new HttpClient();

            mockFactory.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(client);
            IHttpClientFactory factory = mockFactory.Object;

            IClientService    clientService  = new ClientService(factory);
            IWeatherService   weatherService = new WeatherService(clientService, options);
            WeatherController controller     = new WeatherController(weatherService);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await controller.GetCurrentWeatherByCityCoord(null);
            });
        }