コード例 #1
0
        public async Task <IActionResult> SearchPhoneNumber([FromQuery] string areaCode = "")
        {
            // TODO: Fix the bug that stops users from searching for a number when they already have one!
            _logger.LogInformationWithDate($"Searching for the phone number with this area code: {areaCode}");
            var response = "{{\"response\":\"{0}\"}}";
            // Search in storage first.
            var phoneNumberSid = (await _twilioService.GetPhoneNumberSids()).FirstOrDefault();
            var data           = await _storageService.GetData(phoneNumberSid);

            if (data != null)
            {
                _logger.LogInformationWithDate($"Found phone number result: {data}");
                return(new ContentResult {
                    Content = string.Format(response, data), ContentType = "application/json", StatusCode = 200
                });
            }

            // if no result, then search the twilioservice
            var result = await _twilioService.SearchPhoneNumber(areaCode);

            // TODO: Add the phone number to storage after we get it from Twilio
            _logger.LogInformationWithDate($"Found phone number after searching Twilio: {result}");
            return(new ContentResult {
                Content = string.Format(response, result), ContentType = "application/json", StatusCode = 200
            });
        }
コード例 #2
0
        public async Task PurchasePhoneNumber_WithValidAreaCode_ReturnsPhoneNumber()
        {
            // Arrange
            _mockOptions.SetupGet(x => x.CurrentValue).Returns(new TwilioOptions
            {
                AccountSid = "AC0629FB275E074F7FB143C9B39F1AFDE0",
                AuthToken  = "0629FB275E074F7FB143C9B39F1AFDE0"
            });
            _sut = new TwilioService(_mockOptions.Object);

            var areaCode = "510";

            // Act
            var result = await _sut.SearchPhoneNumber(areaCode);

            // Assert
            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Matches(@"^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$", result);
        }