public void ValidationErrorTest()
        {
            //Arrange
            const VerifyMobileState verifyMobileState = VerifyMobileState.VerifyMobileCodeInvalid;
            var v = new ValidationResult();

            v.Errors.Add(new ValidationFailure("VerifyMobileCode", "Length should be less than 4 digits"));

            var verifyMobileViewModel = new VerifyMobileViewModelBuilder().PhoneNumber(MobileNumber).VerifyMobileState(verifyMobileState).MobileVerificationCode(InvalidVerificationCode).Build();

            //todo: nice to have to convert into a builder class
            var verifyMobileViewModelServerValidatorMock = new Mock <VerifyMobileViewModelServerValidator>();

            verifyMobileViewModelServerValidatorMock.Setup(x => x.Validate(It.IsAny <VerifyMobileViewModel>())).Returns(v);

            var accountProviderMock = new Mock <IAccountProvider>();

            accountProviderMock.Setup(x => x.VerifyMobile(It.IsAny <Guid>(), It.IsAny <VerifyMobileViewModel>())).Returns(verifyMobileViewModel);

            var accountMediator = new AccountMediatorBuilder().With(accountProviderMock.Object).With(verifyMobileViewModelServerValidatorMock).Build();

            //Act
            var response = accountMediator.VerifyMobile(Guid.NewGuid(), new VerifyMobileViewModel()
            {
                PhoneNumber = MobileNumber, VerifyMobileCode = ValidVerificationCode
            });

            //Assert
            response.Code.Should().Be(AccountMediatorCodes.VerifyMobile.ValidationError);
            response.ValidationResult.Should().NotBeNull();
        }
        public void VerifyMobileTest(VerifyMobileState verifyMobileState, string accountMediatorCode, string pageMessage, UserMessageLevel userMessageLevel)
        {
            //Arrange
            //const VerifyMobileState verifyMobileState = VerifyMobileState.Ok;
            var verifyMobileViewModel = new VerifyMobileViewModelBuilder().PhoneNumber(MobileNumber).VerifyMobileState(verifyMobileState).MobileVerificationCode(ValidVerificationCode).Build();

            var verifyMobileViewModelServerValidatorMock = new Mock <VerifyMobileViewModelServerValidator>();

            verifyMobileViewModelServerValidatorMock.Setup(x => x.Validate(It.IsAny <VerifyMobileViewModel>())).Returns(new ValidationResult());

            var accountProviderMock = new Mock <IAccountProvider>();

            accountProviderMock.Setup(x => x.VerifyMobile(It.IsAny <Guid>(), It.IsAny <VerifyMobileViewModel>())).Returns(verifyMobileViewModel);

            var accountMediator = new AccountMediatorBuilder().With(accountProviderMock.Object).With(verifyMobileViewModelServerValidatorMock).Build();

            //Act
            var response = accountMediator.VerifyMobile(Guid.NewGuid(), new VerifyMobileViewModel()
            {
                PhoneNumber = MobileNumber, VerifyMobileCode = ValidVerificationCode
            });

            //Assert
            response.Code.Should().Be(accountMediatorCode);
            response.Message.Text.Should().Be(pageMessage);
            response.Message.Level.Should().Be(userMessageLevel);
        }
Beispiel #3
0
        public void ResendTest(VerifyMobileState verifyMobileState, string accountMediatorCode, string pageMessage, UserMessageLevel userMessageLevel)
        {
            //Arrange
            var verifyMobileViewModel = new VerifyMobileViewModelBuilder().PhoneNumber(MobileNumber).VerifyMobileState(verifyMobileState).Build();

            var accountProviderMock = new Mock <IAccountProvider>();

            accountProviderMock.Setup(x => x.SendMobileVerificationCode(It.IsAny <Guid>(), It.IsAny <VerifyMobileViewModel>())).Returns(verifyMobileViewModel);

            var accountMediator = new AccountMediatorBuilder().With(accountProviderMock.Object).Build();

            //Act
            var response = accountMediator.Resend(Guid.NewGuid(), new VerifyMobileViewModel()
            {
                PhoneNumber = MobileNumber
            });

            //Assert
            response.Code.Should().Be(accountMediatorCode);
            response.Message.Text.Should().Be(pageMessage);
            response.Message.Level.Should().Be(userMessageLevel);
        }
        public void GivenEntityStateError_ThenValidViewModelIsReturned(string errorCode,
                                                                       VerifyMobileState verifyMobileState)
        {
            //Arrange
            var candidateId          = Guid.NewGuid();
            var candidateServiceMock = new Mock <ICandidateService>();

            candidateServiceMock.Setup(cs => cs.VerifyMobileCode(candidateId, VerificationCode))
            .Throws(new CustomException(errorCode));
            var viewModel =
                new VerifyMobileViewModelBuilder().PhoneNumber(PhoneNumber)
                .MobileVerificationCode(VerificationCode)
                .Build();
            var provider = new AccountProviderBuilder().With(candidateServiceMock).Build();

            //Act
            var result = provider.VerifyMobile(candidateId, viewModel);

            //Assert
            result.Status.Should().Be(verifyMobileState);
            result.HasError().Should().BeTrue();
            result.ViewModelMessage.Should().NotBeNull();
        }
 public VerifyMobileViewModelBuilder VerifyMobileState(VerifyMobileState verifyMobileState)
 {
     _verifyMobileState = verifyMobileState;
     return(this);
 }