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(); }
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> >(); }
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")); }
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"); }); }