public bool CreateSms(Sms sms)
        {
            if (sms.SmsReference.IsNullOrEmpty())
                return false;

            _smsContext.Smses.Add(sms);

            return _smsContext.SaveChanges() > 0;
        }
        public string Send(Sms sms, string callbackUrl)
        {
            _smsRepository.CreateSms(sms.CreateReference(_referenceGenerator).SetDirection(Direction.Outbound));

            if (!_smsServiceSettings.SendEnabled)
                return sms.SmsReference;

            var result = _smsProvider.SendSms(sms, callbackUrl);

            _smsRepository.UpdateSmsSid(sms.SmsReference, result.MessageIdentifier);

            _smsRepository.UpdateSmsStatus(sms.SmsReference, result.Outcome ? Status.Queued : Status.Error);

            return result.Outcome? sms.SmsReference : string.Empty;
        }
        public SmsProviderResult SendSms(Sms sms, string callbackUrl)
        {
            if (_twilioNumbers.Numbers.All(t => t.Number != sms.From))
                return new SmsProviderResult { Outcome = false};

            var result =
                new TwilioRestClient(_twilioSettings.AccountSid, _twilioSettings.AuthToken).SendMessage(sms.From, sms.To,
                    sms.Body, callbackUrl);

            return new SmsProviderResult
            {
                MessageIdentifier = result.Sid,
                Outcome = string.Equals(result.Status, "Queued", StringComparison.InvariantCultureIgnoreCase),
            };
        }
        public void CreateReference_Sets_NoteReference()
        {
            //arrange
            const string reference = "ABCDE12345";
            var mockReferenceGenerator = new Mock<IReferenceGenerator>();
            var sms = new Sms();

            mockReferenceGenerator.Setup(x => x.CreateReference(It.IsAny<int>())).Returns(reference);

            //act
            sms.CreateReference(mockReferenceGenerator.Object);

            //assert
            sms.SmsReference.Should().NotBeNullOrWhiteSpace();
            sms.SmsReference.Should().Be(reference);

            mockReferenceGenerator.Verify(x => x.CreateReference(It.IsAny<int>()), Times.Once);
        }
 public bool ProcessSms(Sms sms)
 {
     return _smsRepository.CreateSms(sms.CreateReference(_referenceGenerator));
 }