Пример #1
0
        public async Task ApixuClientTests_GetTemp_GivenAZipCode_NotFound_ThrowsException()
        {
            // how do we handle error states outside our control?
            // Arrange
            var(apiuxClient, mockHttp) = Factory();
            const int    zipCode  = 57105;
            const double fakeTemp = 70.5;
            var          response = new ApiuxWeatherCurrentResponse
            {
                Current = new ApiuxWeatherCurrent
                {
                    TempF = fakeTemp
                }
            };
            var requestUri = $"https://api.apixu.com/v1/current.json?key={ApixuClient.apiKey}&q={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 ApixuClientTests_GetTemp_GivenAZipCode_UsesThatZipCode()
        {
            // Arrange
            var(apiuxClient, mockHttp) = Factory();
            const int    zipCode  = 57105;
            const double fakeTemp = 70.5;
            var          response = new ApiuxWeatherCurrentResponse
            {
                Current = new ApiuxWeatherCurrent
                {
                    TempF = fakeTemp
                }
            };
            var requestUri = $"https://api.apixu.com/v1/current.json?key={ApixuClient.apiKey}&q={zipCode}";
            var request    = mockHttp.When(requestUri)
                             .Respond("application/json", Serialize.ToJson(response));


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

            // Assert
            Assert.AreEqual(1, mockHttp.GetMatchCount(request));
        }