Exemplo n.º 1
0
        public void GetCurrentWeatherByZip_ArgumentNullException_NullZipCode(string zip)
        {
            // Arrange
            var client = new OpenWeatherMapClient(_apiKey);

            // Assert
            Assert.ThrowsAsync <ArgumentNullException>(async() => await client.GetCurrentWeatherByZip(zip));
        }
Exemplo n.º 2
0
        public void GetCurentWeatherByZip_Exception_InvalidZip()
        {
            // Arrange
            var json                    = File.ReadAllText(_badCurrentWeatherResponsePath);
            var stringContent           = new StringContent(json);
            var fakeHttpResponseMessage = new HttpResponseMessage(HttpStatusCode.NotFound)
            {
                Content = stringContent
            };
            var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpResponseMessage);
            var httpClient             = new HttpClient(fakeHttpMessageHandler);

            var client = new OpenWeatherMapClient(_apiKey, httpClient);

            // Assert
            Assert.ThrowsAsync <Exception>(async() => await client.GetCurrentWeatherByZip("55555"));
        }
Exemplo n.º 3
0
        public async Task GetCurrentWeatherByZip_CurrentWeatherResponse_ValidZipCode()
        {
            // Arrange
            var json                    = File.ReadAllText(_goodCurrentWeatherResponsePath);
            var stringContent           = new StringContent(json);
            var fakeHttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = stringContent
            };
            var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpResponseMessage);
            var httpClient             = new HttpClient(fakeHttpMessageHandler);

            var client = new OpenWeatherMapClient(_apiKey, httpClient);

            // Act
            var response = await client.GetCurrentWeatherByZip("12345");

            // Assert
            Assert.IsInstanceOf <CurrentWeatherResponse>(response);
        }