示例#1
0
        public async Task GetTemp_GivenAZipCode_NotFound_ThrowsException()
        {
            // how do we handle error states outside our control?
            // Arrange
            var(apiuxClient, mockHttp) = Factory();
            const int  zipCode  = 57105;
            const long fakeTemp = (long)70.5;
            var        response = new WeatherMainResponse
            {
                Current = new WeatherCurrentResponse
                {
                    Temperature = fakeTemp
                }
            };
            var requestUri = $"http://api.weatherstack.com/current?access_key={WeatherStackClient.apiKey}&type=zipcode&units=f&query={zipCode}";

            var request = mockHttp.When(requestUri)
                          .Respond(HttpStatusCode.NotFound);

            // Act and Assert
            await Assert.ThrowsExceptionAsync <NotFoundException>(async() =>
            {
                await apiuxClient.GetCurrentTempAsync(zipCode);
            });
        }
示例#2
0
        public async Task GetTemp_GivenAZipCode_ReturnsTemp()
        {
            // Arrange
            var(apiuxClient, mockHttp) = Factory();
            const int  zipCode  = 57105;
            const long fakeTemp = (long)70.5;
            var        response = new WeatherMainResponse
            {
                Current = new WeatherCurrentResponse
                {
                    Temperature = fakeTemp
                }
            };

            var requestUri = $"http://api.weatherstack.com/current?access_key={WeatherStackClient.apiKey}&type=zipcode&units=f&query={zipCode}";

            mockHttp.When(requestUri)
            .Respond("application/json", Serialize.ToJson(response));

            // Act
            var result = await apiuxClient.GetCurrentTempAsync(zipCode);

            // Assert
            Assert.AreEqual(fakeTemp, result);
        }