public async Task InBoundSmsCommandHandlerTest_Success()
        {
            //Arrange
            var command = new InBoundSmsCommand();

            _mockValidator.Setup(x => x.ValidateAsync(command, CancellationToken.None)).ReturnsAsync(new ValidationResult());
            _mockSmsDao.Setup(x => x.ApplyInBoundCacheRuleAsync(It.IsAny <Sms>())).Returns(Task.CompletedTask);

            //Act
            var result = await _handler.Handle(command, CancellationToken.None);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsValid);
        }
        public async Task InBoundSmsCommandValidatorTest_ToIsMissing()
        {
            //Arrange
            var command = new InBoundSmsCommand {
                From = "12345678",
                Text = "tecxt"
            };


            //Act
            var result = await _validator.ValidateAsync(command, CancellationToken.None);

            //Assert
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual("To is missing.", result.Errors.Single().ErrorMessage);
        }
        public async Task InBoundSmsCommandValidatorTestSuccess()
        {
            //Arrange
            var command = new InBoundSmsCommand {
                To   = "12345678",
                From = "12345678",
                Text = "text"
            };

            _mockSmsDao.Setup(x => x.IsAccountNumberExistsAsync(command.To)).ReturnsAsync(true);

            //Act
            var result = await _validator.ValidateAsync(command, CancellationToken.None);

            //Assert
            Assert.IsTrue(result.IsValid);
        }
Example #4
0
        public async Task <HttpResponseMessage> InboundSms(SmsCommand request)
        {
            //validate the request.
            var command = new InBoundSmsCommand {
                To   = request.To,
                From = request.From,
                Text = request.Text
            };
            var result = await _bus.Send(command);

            if (!result.IsValid)
            {
                return(await ErrorAsync(result.ValidationResult));
            }

            return(await SuccessAsync("inbound sms ok."));
        }
        public async Task InBoundSmsCommandValidatorTest_FromIsMissing()
        {
            //Arrange
            var command = new InBoundSmsCommand {
                To   = "12345678",
                Text = "tecxt"
            };

            _mockSmsDao.Setup(x => x.IsAccountNumberExistsAsync(command.To)).ReturnsAsync(true);

            //Act
            var result = await _validator.ValidateAsync(command, CancellationToken.None);

            //Assert
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual("From is missing.", result.Errors.Single().ErrorMessage);
        }
        public async Task InBoundSmsCommandHandlerTest_ValidationError()
        {
            //Arrange
            var command = new InBoundSmsCommand();

            var validationResult = new ValidationResult {
                Errors = { new ValidationFailure("prop", "messgae") }
            };

            _mockValidator.Setup(x => x.ValidateAsync(command, CancellationToken.None)).ReturnsAsync(validationResult);

            //Act
            var result = await _handler.Handle(command, CancellationToken.None);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, validationResult.Errors.Count);
            Assert.AreEqual(validationResult.Errors.Single().ErrorMessage, result.ValidationResult.Errors.Single().ErrorMessage);
        }