Beispiel #1
0
        public async Task UserTriesToConfirmEmail_WithCustomerThatDoesNotExists_CustomerNotExistingReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();
            var callRateLimiterService      = new Mock <ICallRateLimiterService>();

            var customerProfileClient = new Mock <ICustomerProfileClient>();

            customerProfileClient.Setup(c => c.CustomerProfiles.GetByCustomerIdAsync(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync(
                new CustomerProfileResponse
            {
                Profile = new CustomerProfile.Client.Models.Responses.CustomerProfile
                {
                    Email = "*****@*****.**"
                }
            });

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error      = VerificationCodeError.VerificationCodeDoesNotExist,
                IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync((VerificationCodeModel)null);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((IVerificationCode)null);

            var publisherEmailMessage = new Mock <IRabbitPublisher <EmailMessageEvent> >();
            var publisherCodeVerified = new Mock <IRabbitPublisher <EmailCodeVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    logFactory,
                    publisherEmailMessage.Object,
                    publisherCodeVerified.Object,
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    EmailVerificationLink,
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    customerProfileClient.Object,
                    callRateLimiterService.Object
                    );
            }

            var result = await emailVerificationService.ConfirmCodeAsync("DDD666".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.False(result.IsVerified);
        }
Beispiel #2
0
        UserTriesToConfirmEmail_WithVerificationCodeThatNotExistsInTheSrorage_VerificationCodeMismatchReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();
            var callRateLimiterService      = new Mock <ICallRateLimiterService>();

            var customerProfileClient = new Mock <ICustomerProfileClient>();

            var verificationEmailGetResponse = new VerificationCodeModel
            {
                CustomerId       = "70fb9648-f482-4c29-901b-25fe6febd8af",
                ExpireDate       = DateTime.UtcNow.AddYears(1000),
                VerificationCode = "DDD666",
                IsVerified       = false
            };

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error = VerificationCodeError.VerificationCodeMismatch, IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse);

            var publisherEmailMessage = new Mock <IRabbitPublisher <EmailMessageEvent> >();
            var publisherCodeVerified = new Mock <IRabbitPublisher <EmailCodeVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    logFactory,
                    publisherEmailMessage.Object,
                    publisherCodeVerified.Object,
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    EmailVerificationLink,
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    customerProfileClient.Object,
                    callRateLimiterService.Object
                    );
            }

            var result =
                await emailVerificationService.ConfirmCodeAsync("123456".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.False(result.IsVerified);
        }
        public async Task UserTriesToConfirmEmail_WithNewAdmin_Successfully()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();

            var verificationEmailGetResponse = GetMockedVerificationCode();

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error      = VerificationCodeError.None,
                IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse.Object);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((IVerificationCode)null);

            _adminUserServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new AdminUserResult {
                Profile = new AdminUser {
                    Permissions = new List <Permission>()
                }
            });

            var publisherCodeVerified = new Mock <IRabbitPublisher <AdminEmailVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    publisherCodeVerified.Object,
                    _notificationsServiceMock.Object,
                    _adminUserServiceMock.Object,
                    logFactory
                    );
            }

            var result = await emailVerificationService.ConfirmCodeAsync("DDD666".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.True(result.IsVerified);
        }
        public async Task UserTriesToConfirmEmail_WithVerificationCodeThatHasAlreadyExpired_VerificationCodeExpiredReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();

            var verificationEmailGetResponse = GetMockedVerificationCode();

            verificationEmailGetResponse.SetupProperty(_ => _.ExpireDate, DateTime.UtcNow.AddYears(-1000));

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error      = VerificationCodeError.VerificationCodeExpired,
                IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse.Object);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((IVerificationCode)null);

            var publisherCodeVerified = new Mock <IRabbitPublisher <AdminEmailVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    publisherCodeVerified.Object,
                    _notificationsServiceMock.Object,
                    _adminUserServiceMock.Object,
                    logFactory
                    );
            }

            var result = await emailVerificationService.ConfirmCodeAsync("DDD666".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.False(result.IsVerified);
        }
        public async Task UserTriesToConfirmEmail_WithVerificationCodeThatNotExistsInTheSrorage_VerificationCodeMismatchReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();

            var verificationEmailGetResponse = GetMockedVerificationCode();

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error      = VerificationCodeError.VerificationCodeMismatch,
                IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse.Object);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse.Object);

            var publisherCodeVerified = new Mock <IRabbitPublisher <AdminEmailVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    publisherCodeVerified.Object,
                    _notificationsServiceMock.Object,
                    _adminUserServiceMock.Object,
                    logFactory
                    );
            }

            var result =
                await emailVerificationService.ConfirmCodeAsync("123456".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.False(result.IsVerified);
        }
Beispiel #6
0
        public async Task UserTriesToConfirmEmail_WithAdminThatDoesNotExists_AdminNotExistingReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error      = VerificationCodeError.VerificationCodeDoesNotExist,
                IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync(null as IVerificationCode);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((IVerificationCode)null);

            var publisherCodeVerified = new Mock <IRabbitPublisher <AdminEmailVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    publisherCodeVerified.Object,
                    logFactory
                    );
            }

            var result = await emailVerificationService.ConfirmCodeAsync("DDD666".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.False(result.IsVerified);
        }
Beispiel #7
0
        public async Task UserTriesToConfirmEmail_WithNewCustomer_Successfully()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();
            var callRateLimiterService      = new Mock <ICallRateLimiterService>();

            var customerProfileClient = new Mock <ICustomerProfileClient>();

            customerProfileClient.Setup(c => c.CustomerProfiles.GetByCustomerIdAsync(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync(
                new CustomerProfileResponse
            {
                Profile = new CustomerProfile.Client.Models.Responses.CustomerProfile
                {
                    Email = "*****@*****.**"
                }
            });

            var verificationEmailGetResponse = new VerificationCodeModel
            {
                CustomerId       = "70fb9648-f482-4c29-901b-25fe6febd8af",
                ExpireDate       = DateTime.UtcNow.AddYears(1000),
                VerificationCode = "DDD666",
                IsVerified       = false
            };

            var confirmEmailResponse = new ConfirmVerificationCodeResultModel
            {
                Error      = VerificationCodeError.None,
                IsVerified = true
            };

            verificationEmailRepository
            .Setup(x => x.GetByValueAsync(It.IsAny <string>()))
            .ReturnsAsync(verificationEmailGetResponse);

            verificationEmailRepository
            .Setup(x => x.CreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((IVerificationCode)null);

            var publisherEmailMessage = new Mock <IRabbitPublisher <EmailMessageEvent> >();
            var publisherCodeVerified = new Mock <IRabbitPublisher <EmailCodeVerifiedEvent> >();

            EmailVerificationService emailVerificationService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                emailVerificationService = new EmailVerificationService(
                    verificationEmailRepository.Object,
                    logFactory,
                    publisherEmailMessage.Object,
                    publisherCodeVerified.Object,
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    EmailVerificationLink,
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    customerProfileClient.Object,
                    callRateLimiterService.Object
                    );
            }

            var result = await emailVerificationService.ConfirmCodeAsync("DDD666".ToBase64());

            Assert.Equal(confirmEmailResponse.Error.ToString(), result.Error.ToString());
            Assert.True(result.IsVerified);
        }