Exemplo n.º 1
0
        public async Task ShouldGetWeatherDataForElementByWmoFromEndpoint()
        {
            const string returnData = @"[
						
							{""Time"": ""12.30pm"", ""air_temp"": 10.3},
							{""Time"": ""12.30pm"", ""air_temp"": 3},
							{""Time"": ""12.30pm"", ""air_temp"": -3},
							{""Time"": ""12.30pm"", ""air_temp"": 23.6},
							{""Time"": ""12.30pm"", ""air_temp"": 13.9}
						]"                        ;

            var fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(_json, Encoding.UTF8, "application/json")
            });

            var fakeHttpClient = new HttpClient(fakeHttpMessageHandler)
            {
                BaseAddress = new Uri(_url)
            };

            _httpClientFactoryMock.CreateClient().Returns(fakeHttpClient);

            var sut = new BomService(fakeHttpClient);

            var actual = await sut.GetWeatherDataElementAsync(123, "air_temp");

            var expected = JsonConvert.DeserializeObject <IEnumerable <JToken> >(returnData);

            actual.Should().BeEquivalentTo(expected);
        }