public async Task LookupNumber_CallsTwilioWrapper() { var options = new Mock <IOptions <TwilioSettings> >(); options.Setup(x => x.Value).Returns(new TwilioSettings { Sid = "123", Token = "ABC", PhoneNo = "1234567890" }); var twilioWrapper = new Mock <ITwilioWrapper>(); var sut = new TwilioPhoneNumberLookupService(options.Object, twilioWrapper.Object); await sut.LookupNumber("123456789", "us"); twilioWrapper.Verify(x => x.FetchPhoneNumberResource(It.IsAny <FetchPhoneNumberOptions>(), It.IsAny <ITwilioRestClient>()), Times.Once); }
public async Task LookupNumber_ReturnsVoipType_WhenResponseIncludesVoipCarrier() { var options = new Mock <IOptions <TwilioSettings> >(); options.Setup(x => x.Value).Returns(new TwilioSettings { Sid = "123", Token = "ABC", PhoneNo = "1234567890" }); var twilioWrapper = new Mock <ITwilioWrapper>(); twilioWrapper.Setup(x => x.FetchPhoneNumberResource(It.IsAny <FetchPhoneNumberOptions>(), It.IsAny <ITwilioRestClient>())) .ReturnsAsync(PhoneNumberResource.FromJson(TwilioResponseJsonVoip)); var sut = new TwilioPhoneNumberLookupService(options.Object, twilioWrapper.Object); var result = await sut.LookupNumber("123456789", "us"); result.Type.ShouldBe(PhoneNumberType.Voip); }
public async Task LookupNumber_ReturnsCorrectPhoneNumberInResult() { var options = new Mock <IOptions <TwilioSettings> >(); options.Setup(x => x.Value).Returns(new TwilioSettings { Sid = "123", Token = "ABC", PhoneNo = "1234567890" }); var twilioWrapper = new Mock <ITwilioWrapper>(); twilioWrapper.Setup(x => x.FetchPhoneNumberResource(It.IsAny <FetchPhoneNumberOptions>(), It.IsAny <ITwilioRestClient>())) .ReturnsAsync(PhoneNumberResource.FromJson(TwilioResponseJson)); var sut = new TwilioPhoneNumberLookupService(options.Object, twilioWrapper.Object); var result = await sut.LookupNumber("123456789", "us"); result.PhoneNumberE164.ToString().ShouldBe(new Twilio.Types.PhoneNumber("+15108675309").ToString()); }
public async Task LookupNumber_ReturnsFailedLokupResult_IfTheTwilioCallReturnsNullPhoneNumberResource() { var options = new Mock <IOptions <TwilioSettings> >(); options.Setup(x => x.Value).Returns(new TwilioSettings { Sid = "123", Token = "ABC", PhoneNo = "1234567890" }); var twilioWrapper = new Mock <ITwilioWrapper>(); twilioWrapper.Setup(x => x.FetchPhoneNumberResource(It.IsAny <FetchPhoneNumberOptions>(), It.IsAny <ITwilioRestClient>())) .ReturnsAsync(null); var sut = new TwilioPhoneNumberLookupService(options.Object, twilioWrapper.Object); var result = await sut.LookupNumber("123456789", "us"); result.LookupFailed.ShouldBeTrue(); }
public async Task LookupNumber_CallsTwilioWrapper_WithCorrectCountryCode() { FetchPhoneNumberOptions fetchOptions = null; var options = new Mock <IOptions <TwilioSettings> >(); options.Setup(x => x.Value).Returns(new TwilioSettings { Sid = "123", Token = "ABC", PhoneNo = "1234567890" }); var twilioWrapper = new Mock <ITwilioWrapper>(); twilioWrapper.Setup(x => x.FetchPhoneNumberResource(It.IsAny <FetchPhoneNumberOptions>(), It.IsAny <ITwilioRestClient>())) .Callback <FetchPhoneNumberOptions, ITwilioRestClient>((x, y) => fetchOptions = x); var sut = new TwilioPhoneNumberLookupService(options.Object, twilioWrapper.Object); await sut.LookupNumber("123456789", "us"); fetchOptions.CountryCode.ShouldBe("us"); }