public async Task GetLocationsReturnsLocations()
        {
            //Setup
            var expectedResponse = GetTestResponse();

            var httpResponse = new HttpResponseMessage
            {
                Content    = new StringContent(JsonConvert.SerializeObject(expectedResponse)),
                StatusCode = HttpStatusCode.Accepted,
            };

            var fakeHttpRequestSender  = A.Fake <IFakeHttpRequestSender>();
            var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            var httpClient             = new HttpClient(fakeHttpMessageHandler);

            httpClient.BaseAddress = new System.Uri("https://dummy.com");

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);

            var nationalStatisticsLocationService = new NationalStatisticsLocationService(fakeLogger, httpClient);

            //Act
            var actual = await nationalStatisticsLocationService.GetLocationsAsync().ConfigureAwait(false);

            //Assert
            actual.Should().BeEquivalentTo(expectedResponse.Locations);

            httpResponse.Dispose();
            httpClient.Dispose();
            fakeHttpMessageHandler.Dispose();
        }
Exemple #2
0
        public void Then_The_Current_Download_Name_Is_Returned()
        {
            //Arrange
            var client          = new HttpClient(Mock.Of <HttpMessageHandler>());
            var locationService = new NationalStatisticsLocationService(client);

            //Act
            var actual = locationService.GetName();

            //Assert
            actual.Should().Be(string.Format(Constants.NationalOfficeOfStatisticsLocationUrl, 2000, 0));
        }
Exemple #3
0
        public void Then_If_It_Is_Not_Successful_An_Exception_Is_Thrown()
        {
            //Arrange
            var response = new HttpResponseMessage
            {
                Content    = new StringContent(""),
                StatusCode = HttpStatusCode.BadRequest
            };
            var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, new Uri(string.Format(Constants.NationalOfficeOfStatisticsLocationUrl, 2000, 0)));
            var client             = new HttpClient(httpMessageHandler.Object);
            var locationService    = new NationalStatisticsLocationService(client);

            //Act Assert
            Assert.ThrowsAsync <HttpRequestException>(() => locationService.GetLocations());
        }
Exemple #4
0
        public async Task Then_The_Endpoint_Is_Called_And_Location_Data_Returned(
            OnsLocationApiResponse importLocations)
        {
            //Arrange
            importLocations.ExceededTransferLimit = false;
            var response = new HttpResponseMessage
            {
                Content    = new StringContent(JsonConvert.SerializeObject(importLocations)),
                StatusCode = HttpStatusCode.Accepted
            };
            var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, new Uri(string.Format(Constants.NationalOfficeOfStatisticsLocationUrl, 2000, 0)));
            var client             = new HttpClient(httpMessageHandler.Object);
            var locationService    = new NationalStatisticsLocationService(client);

            //Act
            var actual = await locationService.GetLocations();

            //Assert
            actual.Should().BeEquivalentTo(importLocations.Features);
        }