Пример #1
0
        public void GivenACreateAction_ThenItSendsAMessage()
        {
            var notificationServiceMock = new Mock <INotificationService>();

            notificationServiceMock
            .Setup(m => m.SendAsync(It.IsAny <string>()))
            .ReturnsAsync(MessageResource.FromJson("{}"));

            HttpContext.Current = new HttpContext(
                new HttpRequest(null, "http://tempuri.org", null),
                new HttpResponse(null));
            var controller = new NotificationsController(notificationServiceMock.Object);

            var lead = new Lead
            {
                HouseTitle = "La Maison",
                Name       = "Alice",
                Phone      = "555-5555",
                Message    = "Welcome back!"
            };

            controller
            .WithCallTo(c => c.Create(lead))
            .ShouldRedirectTo <HomeController>(c => c.Index());


            const string message = "New lead received for La Maison. " +
                                   "Call Alice at 555-5555. Message: Welcome back!";

            notificationServiceMock.Verify(c => c.SendAsync(message), Times.Once);
        }
        public MessageResource SendSMS(string toPhoneNumber, string fromPhoneNumber, string message)
        {
            if ((string.IsNullOrEmpty(AccountSID)) || (string.IsNullOrEmpty(AuthToken)))
            {
                throw new AuthenticationException("Missing/Invalid AccountSID or AuthToken");
            }

            if ((string.IsNullOrEmpty(toPhoneNumber)) || (string.IsNullOrEmpty(fromPhoneNumber)))
            {
                throw new ApiException(111, 111, "Invalid To/From phone number", "Invalid To/From phone number");
            }

            string messageResourceJson = "{ 'To':'" + toPhoneNumber + "', 'From':'" + fromPhoneNumber + "', 'status':'Queued'}";

            return(MessageResource.FromJson(messageResourceJson));
        }