Exemple #1
0
        public async Task WhenGetAddressesCalledAndNoAddressesFound_ThenReturnNull()
        {
            _restClient.LastResponse = new RestClient.APIResponse(new HttpResponseMessage())
            {
                IsSuccess = false
            };

            _restClient.GetAsync <IEnumerable <PostalAddressModel> >(Arg.Any <string>())
            .ReturnsForAnyArgs(new List <PostalAddressModel>());

            var service = new GetAddressIoSearchService(new OptionsWrapper <AddressSearchServiceSettings>(new AddressSearchServiceSettings()), _restClient);

            var result = await service.GetAddresses("test");

            result.Should().BeNull();
        }
Exemple #2
0
        public async Task WhenGetAddressesCalled_ThenReturnResult()
        {
            _restClient.GetAsync <GetAddressIoResult>(Arg.Any <string>())
            .ReturnsForAnyArgs(new GetAddressIoResult
            {
                Addresses = new List <GetAddressIOAddressModel>()
            });

            _restClient.LastResponse.IsSuccess = true;

            var service = new GetAddressIoSearchService(new OptionsWrapper <AddressSearchServiceSettings>(new AddressSearchServiceSettings()), _restClient);

            var result = await service.GetAddresses("test");

            result.Should().BeOfType <List <PostalAddressModel> >();
        }
Exemple #3
0
        public async Task WhenGetAddressesCalled_ThenCorrectUrlIsGenerated()
        {
            _restClient.GetAsync <GetAddressIoResult>(Arg.Any <string>())
            .ReturnsForAnyArgs(new GetAddressIoResult
            {
                Addresses = new List <GetAddressIOAddressModel>()
            });

            var service = new GetAddressIoSearchService(new OptionsWrapper <AddressSearchServiceSettings>(new AddressSearchServiceSettings
            {
                Key = "1",
                AddressIdentifierPattern = "2",
                FindAddressesBaseUrl     = "3",
                RetrieveAddressBaseUrl   = "4"
            }), _restClient);

            await service.GetAddresses("test");

            await _restClient.Received().GetAsync <GetAddressIoResult>(Arg.Is("3/test?api-key=1&expand=true"));
        }
Exemple #4
0
        public async Task WhenGetAddressCalledAndNoAddressFound_ThenReturnNull()
        {
            var client = Substitute.For <IRestClient>();

            client.GetAsync <GetAddressIoResult>(Arg.Any <string>())
            .ReturnsForAnyArgs(new GetAddressIoResult
            {
                Addresses = new List <GetAddressIOAddressModel>()
            });

            client.LastResponse = new RestClient.APIResponse(new HttpResponseMessage())
            {
                IsSuccess = false
            };

            var service = new GetAddressIoSearchService(new OptionsWrapper <AddressSearchServiceSettings>(new AddressSearchServiceSettings()), client);

            var result = await service.GetAddress("test");

            result.Should().BeNull();
        }
Exemple #5
0
        public async Task WhenGetAddressesCalledAndServiceLimitReached_ThenThrowServiceLimitReachedException()
        {
            var client = Substitute.For <IRestClient>();

            client.GetAsync <GetAddressIoResult>(Arg.Any <string>())
            .ReturnsForAnyArgs(new GetAddressIoResult
            {
                Addresses = new List <GetAddressIOAddressModel>()
            });

            client.LastResponse = new RestClient.APIResponse(new HttpResponseMessage())
            {
                IsSuccess  = false,
                StatusCode = HttpStatusCode.TooManyRequests
            };

            var service = new GetAddressIoSearchService(new OptionsWrapper <AddressSearchServiceSettings>(new AddressSearchServiceSettings()), client);

            Assert.ThrowsAsync <AddressServiceRequestLimitReachedException>(async() =>
            {
                await service.GetAddresses("test");
            });
        }