コード例 #1
0
        public async Task Weather_Controller_Should_Return_Weather_By_City_ID(int id)
        {
            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.GetCurrentWeatherByCityID(id);

            Assert.NotNull(result.Value.ResponseBody);
            Assert.IsType <WeatherModel>(result.Value.ResponseBody);
        }