Exemple #1
0
        public void ShouldValidateSMSWithInvalidInvite()
        {
            var smsValidationCode = "SMSValidationCodeMock";
            MessagingVerification expectedResult = new MessagingVerification
            {
                HdId = "invalid" + HdIdMock,
                VerificationAttempts = 0,
                SMSValidationCode    = smsValidationCode,
                ExpireDate           = DateTime.Now.AddDays(1),
            };

            Mock <IMessagingVerificationDelegate> messagingVerificationDelegate = new Mock <IMessagingVerificationDelegate>();

            messagingVerificationDelegate.Setup(s => s.GetLastForUser(It.IsAny <string>(), It.IsAny <string>())).Returns(expectedResult);

            Mock <IUserProfileDelegate> userProfileDelegate = new Mock <IUserProfileDelegate>();
            var userProfileMock = new Database.Wrapper.DBResult <UserProfile>()
            {
                Payload = new UserProfile(),
                Status  = Database.Constants.DBStatusCode.Read,
            };

            userProfileDelegate.Setup(s => s.GetUserProfile(It.IsAny <string>())).Returns(userProfileMock);
            userProfileDelegate.Setup(s => s.Update(It.IsAny <UserProfile>(), It.IsAny <bool>())).Returns(new Database.Wrapper.DBResult <UserProfile>());

            IUserSMSService service = new UserSMSService(
                new Mock <ILogger <UserSMSService> >().Object,
                messagingVerificationDelegate.Object,
                userProfileDelegate.Object,
                new Mock <INotificationSettingsService>().Object);

            bool actualResult = service.ValidateSMS(HdIdMock, smsValidationCode);

            Assert.True(!actualResult);
        }
Exemple #2
0
        public void ShouldSanitizeSMS()
        {
            string smsNumber = "1234561234";

            Mock <IMessagingVerificationDelegate> messagingVerificationDelegateMock = new ();

            messagingVerificationDelegateMock
            .Setup(
                s => s.Insert(It.IsAny <MessagingVerification>())).Returns(default(Guid));

            IUserSMSService service = new UserSMSService(
                new Mock <ILogger <UserSMSService> >().Object,
                messagingVerificationDelegateMock.Object,
                new Mock <IUserProfileDelegate>().Object,
                new Mock <INotificationSettingsService>().Object);

            service.CreateUserSMS(HdIdMock, smsNumber);
            messagingVerificationDelegateMock
            .Verify(
                s => s.Insert(It.Is <MessagingVerification>(x => x.HdId == HdIdMock && x.SMSNumber.All(char.IsDigit))));

            smsNumber = "(123)4561234";
            service.CreateUserSMS(HdIdMock, smsNumber);
            messagingVerificationDelegateMock
            .Verify(
                s => s.Insert(It.Is <MessagingVerification>(x => x.HdId == HdIdMock && x.SMSNumber.All(char.IsDigit))));

            smsNumber = "123 456 1234";
            service.CreateUserSMS(HdIdMock, smsNumber);
            messagingVerificationDelegateMock
            .Verify(
                s => s.Insert(It.Is <MessagingVerification>(x => x.HdId == HdIdMock && x.SMSNumber.All(char.IsDigit))));

            smsNumber = "+1 123-456-1234";
            service.CreateUserSMS(HdIdMock, smsNumber);
            messagingVerificationDelegateMock
            .Verify(
                s => s.Insert(It.Is <MessagingVerification>(x => x.HdId == HdIdMock && x.SMSNumber.All(char.IsDigit))));
        }