[InlineData(" ")] //Whitespace string public void Send_ShouldThrowArgumentNullException_WithInvalidMessage(string messageToTest) { var testService = new TwilioSmsService(Options.Create(_options)); var recipient = "+15555551212"; var exception = Assert.Throws <ArgumentNullException>(() => testService.Send(recipient, messageToTest)); Assert.Equal("message", exception.ParamName); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddSingleton <ISmsService>(_ = new TwilioSmsService( Configuration["Twilio:AccountSid"], Configuration["Twilio:AuthToken"])); services.AddRazorPages(); }
public void Constructor_WithValidArguments_ShouldConstruct() { var client = Substitute.For <HttpClient>(); var options = Substitute.For <IOptions <TwilioOptions> >(); var config = new TwilioOptions(); options.Value.Returns(config); var actual = new TwilioSmsService(options, client); Assert.NotNull(actual); }
[InlineData(" ")] //Whitespace string public void Send_ShouldThrowArgumentNullException_WithInvalidRecipient(string recipientToTest) { // Arrange var testService = new TwilioSmsService(Options.Create(_options)); var message = "Valid Message"; // Act var exception = Assert.Throws <ArgumentNullException>(() => testService.Send(recipientToTest, message)); // Assert Assert.Equal("recipient", exception.ParamName); }
public IHttpActionResult SendTestSms(SendSmsRequest request) { TwilioSmsService twilioSms = new TwilioSmsService(); List <String> recipientNumbers = new List <string>(); recipientNumbers.Add(request.To); IEnumerable <String> resp = twilioSms.SendSms(request.From, recipientNumbers, request.MessageBody, System.Configuration.ConfigurationManager.AppSettings["smsAccountSid"], System.Configuration.ConfigurationManager.AppSettings["smsAuth"]); return(Ok(new SendSmsResponse() { Data = resp, Success = Common.Enumerations.ResponseStatus.Succeeded })); }
public void Send_ShouldExecuteWithoutError_WithValidInputs() { //Arrange _options.FromPhoneNumber = "+15005550006"; var recipient = "+15155551212"; var message = "Sent from Unit Test"; var testService = new TwilioSmsService(Options.Create(_options)); //Act testService.Send(recipient, message); //Assert //TODO: Production implementation should have a return value to be able to validate success. Assert.True(true); }
public void Send_ShouldThrowTwilioError_WhenInvalidPhoneNumberIsUsed() { // Arrange _options.FromPhoneNumber = "+15005550001"; //Magic number for invalid var expectedErrorCode = 21212; var recipient = "+15555551212"; var message = "Testing"; var testService = new TwilioSmsService(Options.Create(_options)); // Act var exception = Assert.Throws <ApiException>(() => testService.Send(recipient, message)); // Assert Assert.Equal(expectedErrorCode, exception.Code); }
static void Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Environment.CurrentDirectory) .AddJsonFile("appsettings.json") .AddUserSecrets <TwilioSmsService>() .AddEnvironmentVariables() .Build(); ISmsService smsService = new TwilioSmsService(configuration["Twillio:AccountSid"], configuration["Twillio:AuthToken"]); string to = "+4367761289711"; string message = "Hello World from Twilio SMS service."; smsService.SendSms(to, message); }
public async Task SendAndWaitForResponseAsync_WithValidParams_ShouldSendAndReceiveSms() { // Setup var options = Substitute.For <IOptions <TwilioOptions> >(); var config = new TwilioOptions { AccountSID = "xxx", AuthToken = "yyy", Region = "Middle East & Africa" }; options.Value.Returns(config); var communicator = new TwilioSmsService(options, new HttpClient()); var request = new SmsRequest { From = "+12019847676", Destination = "+27718690000", Message = "Test message" }; // Perform await communicator.SendAndWaitForResponseAsync(request, CancellationToken.None); }
public AuthController(UserService userService, TwilioSmsService twilioSmsService) { this.userService = userService; this.twilioSmsService = twilioSmsService; }