public async void Hourly_NotMissingMembers()
        {
            var resp = await _service.GetHourly(_latitude, _longitude, ResponseFixture.HourlyFields, new OptionalParamters { UnitSystem = "us" });

            Assert.True(resp.Response.IsSuccessStatus);
            Assert.NotEmpty(resp.DataPoints);
            Assert.Equal("F", resp.DataPoints[0].Temp.Units);
        }
        public async void Hourly_JsonGermanCulture()
        {
            using var cultureJsonService = new ClimaCellService(_apiKey, jsonSerializerService: new JsonGermanCultureFixture());
            var resp = await cultureJsonService.GetHourly(_latitude, _longitude, ResponseFixture.HourlyFields, new OptionalParamters { UnitSystem = "si" });

            Assert.True(resp.Response.IsSuccessStatus);
            Assert.NotEmpty(resp.DataPoints);
            Assert.Equal("C", resp.DataPoints[0].Temp.Units);
        }
Пример #3
0
        public ResponseFixture()
        {
            var mockClient = new Mock <IHttpClient>();

            // Setup mockClient to take any string, and return MockRealtimeResponse
            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(MockRealtimeResponse));
            using (var climaRealtimeService = new ClimaCellService("FakeKey", httpClient: mockClient.Object))
            {
                // Remember, all this is doing is returning MockRealtimeResponse whose response content is populated by Realtime.Normal.json
                // so the passed fields do not matter at all
                NormalRealtimeResponse = climaRealtimeService.GetRealtime(Latitude, Longitude, new List <string> {
                    "mockField"
                }).Result;
            }

            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(MockNowcastResponse));
            using (var climaNowcastService = new ClimaCellService("FakeKey", httpClient: mockClient.Object))
            {
                NormalNowcastResponse = climaNowcastService.GetNowcast(Latitude, Longitude, new List <string> {
                    "mockField"
                }).Result;
            }

            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(MockHourlyResponse));
            using (var climaHourlyService = new ClimaCellService("FakeKey", httpClient: mockClient.Object))
            {
                NormalHourlyResponse = climaHourlyService.GetHourly(Latitude, Longitude, new List <string> {
                    "mockField"
                }).Result;
            }

            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(MockDailyResponse));
            using (var climaDailyService = new ClimaCellService("FakeKey", httpClient: mockClient.Object))
            {
                NormalDailyResponse = climaDailyService.GetDaily(Latitude, Longitude, new List <string> {
                    "mockField"
                }).Result;
            }

            // BadRequest / Unauthorized request
            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(MockBadRequestResponse));
            using (var climaDailyService = new ClimaCellService("FakeKey", httpClient: mockClient.Object))
            {
                BadRequestRealtimeResponse = climaDailyService.GetRealtime(Latitude, Longitude, new List <string> {
                    "mockField"
                }).Result;
            }

            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(MockInvalidAPIKeyRequest));
            using (var climaDailyService = new ClimaCellService("FakeKey", httpClient: mockClient.Object))
            {
                UnauthorizedRealtimeResponse = climaDailyService.GetRealtime(Latitude, Longitude, new List <string> {
                    "mockField"
                }).Result;
            }
        }
Пример #4
0
        public async void Hourly_AllFieldsParsed()
        {
            var mockClient = new Mock <IHttpClient>();

            mockClient.Setup(f => f.HttpRequestAsync(It.IsAny <string>())).Returns(Task.FromResult(ResponseFixture.MockHourlyResponse));
            using (var service = new ClimaCellService("FakeKey", httpClient: mockClient.Object, jsonSerializerService: new JsonMissingMemberFixture()))
            {
                var resp = await service.GetHourly(ResponseFixture.Latitude, ResponseFixture.Longitude, new List <string> {
                    "mockField"
                });

                Assert.True(resp.Response.IsSuccessStatus);
            }
        }
Пример #5
0
 public async void Hourly_AtleaseOneFieldIsRequired()
 {
     using var service = new ClimaCellService("ABCD1234");
     await Assert.ThrowsAsync <ArgumentException>(async() => await service.GetHourly(42, -71, new List <string>()));
 }