public void ShouldThrowWhenToNumberIsMissingOrInvalid()
        {
            // Arrange.
            var restClient = new Mock <IRestClient>();

            var restResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = RestResponses.Valid
            };

            restClient.Setup(mock => mock.Execute(It.IsAny <IRestRequest>())).Returns(restResponse);

            var dispatcher = new ReachSmsDispatcher(
                _logService.Object, restClient.Object, _configurationService.Object, _smsNumberFormatter, _smsMessageFormatters);

            _smsRequest = new SmsRequestBuilder()
                          .WithMessageType(MessageTypes.SendAccountUnlockCode)
                          .WithTokens(_communicationTokens)
                          .WithToNumber(null)
                          .Build();

            // Act.
            Action action = () => dispatcher.SendSms(_smsRequest);

            // Assert.
            var exception = action.ShouldThrowExactly <DomainException>();

            exception.WithMessage(ErrorCodes.SmsError);
            exception.WithInnerException <ArgumentNullException>();
        }
        public void ShouldThrowWhenRestResponseMessageResultIsMissing()
        {
            // Arrange.
            var restClient = new Mock <IRestClient>();

            var restResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = RestResponses.MissingMessageResult
            };

            restClient.Setup(mock => mock.Execute(It.IsAny <IRestRequest>())).Returns(restResponse);

            var dispatcher = new ReachSmsDispatcher(
                _logService.Object, restClient.Object, _configurationService.Object, _smsNumberFormatter, _smsMessageFormatters);

            // Act.
            Action action = () => dispatcher.SendSms(_smsRequest);

            // Assert.
            var exception = action.ShouldThrowExactly <DomainException>();

            exception.WithMessage(ErrorCodes.SmsError);
            exception.WithInnerException <BoundaryException>();

            exception.Where(e => e.InnerException.Data.Contains("content"));
            exception.Where(e => e.Data.Contains("toNumber"));
            exception.Where(e => e.Data.Contains("messageType"));
        }
        public void ShouldThrowWhenRestResponseMessageResultIsUnsuccessful()
        {
            // Arrange.
            var restClient = new Mock <IRestClient>();

            var restResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = RestResponses.UnsuccessfulMessageResult
            };

            restClient.Setup(mock => mock.Execute(It.IsAny <IRestRequest>())).Returns(restResponse);

            var dispatcher = new ReachSmsDispatcher(
                _logService.Object, restClient.Object, _configurationService.Object, _smsNumberFormatter, _smsMessageFormatters);

            // Act.
            Action action = () => dispatcher.SendSms(_smsRequest);

            // Assert.
            action.ShouldThrowExactly <DomainException>();
        }
        public void ShouldSendSms()
        {
            // Arrange.
            var restClient = new Mock <IRestClient>();

            var restResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = RestResponses.Valid
            };

            restClient.Setup(mock => mock.Execute(It.IsAny <IRestRequest>())).Returns(restResponse);

            var dispatcher = new ReachSmsDispatcher(
                _logService.Object, restClient.Object, _configurationService.Object, _smsNumberFormatter, _smsMessageFormatters);

            // Act.
            dispatcher.SendSms(_smsRequest);

            // Assert.
            restClient.Verify(mock => mock.Execute(It.IsAny <IRestRequest>()), Times.Once);
            _logService.Verify(mock => mock.Info(It.IsAny <string>(), It.IsAny <object[]>()), Times.Once);
        }