Ejemplo n.º 1
0
        public async Task UserTriesToConfirmEmail_WithVerificationCodeThatNotExistsInTheStorage_VerificationCodeMismatchReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();

            var verificationEmailGetResponse = GetMockedVerificationCode();

            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,
                    logFactory
                    );
            }

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

            Assert.Equal(VerificationCodeError.VerificationCodeMismatch.ToString(), result.Error.ToString());
            Assert.False(result.IsVerified);
        }
Ejemplo n.º 2
0
        public async Task UserTriesToConfirmEmail_WithCustomerThatIsAlreadyVerified_AlreadyVerifiedReturned()
        {
            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,
                VerificationCode = "DDD666",
                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(VerificationCodeError.AlreadyVerified.ToString(), result.Error.ToString());
            Assert.True(result.IsVerified);
        }
Ejemplo n.º 3
0
        public async Task UserTriesToConfirmEmail_WithAdminThatIsAlreadyVerified_AlreadyVerifiedReturned()
        {
            var verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();

            var verificationEmailGetResponse = GetMockedVerificationCode();

            verificationEmailGetResponse.SetupProperty(_ => _.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,
                    logFactory
                    );
            }

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

            Assert.Equal(VerificationCodeError.AlreadyVerified.ToString(), result.Error.ToString());
            Assert.True(result.IsVerified);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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 GenerateVerificationCode_Should_Return_Error_If_countryCode_Or_phoneNumber_Is_InvalidAsync(string countryCode, string phoneNumber)
        {
            var emailHelperMock               = new Mock <IEmailHelper>();
            var randomNumberProvider          = new Mock <IRandomNumberProvider>();
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();
            var userRepositoryMock            = new Mock <IUserRepository>();
            var emailVerificationService      = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.GenerateVerificationCodeAsync(countryCode, phoneNumber);

            result.IsSuccessed.Should().BeFalse();
            result.GetErrorString().Should().Be(Constants.PhoneVerifyMessages.Country_Phone_Empty);
        }
        public async Task ValidateVerificationCode_Should_Return_Error_If_CountryCode_Or_PhoneNumber_Or_VerificationCode_Is_InvalidAsync(string countryCode, string phoneNumber, int verificationCode)
        {
            var emailHelperMock               = new Mock <IEmailHelper>();
            var randomNumberProvider          = new Mock <IRandomNumberProvider>();
            var userRepositoryMock            = new Mock <IUserRepository>();
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();
            var emailVerificationService      = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.ValidateVerificationCodeAsync(countryCode, phoneNumber, verificationCode);

            Assert.IsFalse(result.IsSuccessed);
            Assert.AreEqual(Constants.PhoneVerifyMessages.Country_Phone_VerifyCode_Empty, result.GetErrorString());
        }
Ejemplo n.º 8
0
 private App()
 {
     EmailVerificationService = new EmailVerificationService();
     SftpService               = new SftpService();
     HttpService               = new HttpService();
     TenderService             = new TenderService();
     MedicalExaminationService = new MedicalExaminationService(
         new MedicalExaminationRepository(new MySQLStream <MedicalExamination>(), new IntSequencer()));
     PatientFeedbackService = new PatientFeedbackService(
         new PatientFeedbackRepository(new MySQLStream <PatientFeedback>(), new IntSequencer()));
     MedicalExaminationReportService = new MedicalExaminationReportService(
         new MedicalExaminationReportRepository(new MySQLStream <MedicalExaminationReport>(), new IntSequencer()));
     PrescriptionService = new PrescriptionService(
         new PrescriptionRepository(new MySQLStream <Prescription>(), new IntSequencer()));
     MedicalRecordService = new MedicalRecordService(
         new MedicalRecordRepository(new MySQLStream <MedicalRecord>(), new IntSequencer()), EmailVerificationService);
     QuestionService = new QuestionService(
         new QuestionRepository(new MySQLStream <Question>(), new IntSequencer()));
     AnswerService = new AnswerService(
         new AnswerRepository(new MySQLStream <Answer>(), new IntSequencer()), QuestionService);
     AllergiesService = new AllergiesService(
         new AllergiesRepository(new MySQLStream <Allergies>(), new IntSequencer()));
     PatientService = new PatientService(
         new PatientRepository(new MySQLStream <Patient>(), new IntSequencer()));
     SurveyService = new SurveyService(
         new SurveyRepository(new MySQLStream <Survey>(), new IntSequencer()), MedicalExaminationService, AnswerService);
     DoctorService = new DoctorService(
         new DoctorRepository(new MySQLStream <Doctor>(), new IntSequencer()));
     ReportService = new ReportService(
         new ReportRepository(new MySQLStream <Report>(), new IntSequencer()), SftpService);
     DoctorWorkDayService = new DoctorWorkDayService(
         new DoctorWorkDayRepository(new MySQLStream <DoctorWorkDay>(), new IntSequencer()), DoctorService);
     SpetialitationService = new SpetialitationService(
         new SpecialitationRepository(new MySQLStream <Specialitation>(), new IntSequencer()));
     AppointmentService = new AppointmentService(
         new AppointmentRepository(new MySQLStream <Appointment>(), new IntSequencer()), PatientService);
     EPrescriptionService = new EPrescriptionService(
         new EPrescriptionRepository(new MySQLStream <EPrescription>(), new IntSequencer()), SftpService);
     PharmacyService = new PharmacyService(
         new PharmacyRepository(new MySQLStream <Pharmacies>(), new IntSequencer()));
     RoomService = new RoomService(
         new RoomRepository(new MySQLStream <Room>(), new IntSequencer()));
     ManagerService = new ManagerService(
         new ManagerRepository(new MySQLStream <Manager>(), new IntSequencer()));
     SecretaryService = new SecretaryService(
         new SecretaryRepository(new MySQLStream <Secretary>(), new IntSequencer()));
     SystemAdministratorService = new SystemAdministratorService(
         new SystemAdministratorRepository(new MySQLStream <SystemAdministrator>(), new IntSequencer()));
     UserService = new UserService(
         new UserRepository(new MySQLStream <User>(), new IntSequencer()), PatientService, SystemAdministratorService);
 }
        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);
        }
Ejemplo n.º 10
0
        UserTriesToGenerateVerificationEmail_WithCustomerThatIsAlreadyVerifiedInCustomerProfile_AlreadyVerifiedReturned()
        {
            const string customerId                  = "70fb9648-f482-4c29-901b-25fe6febd8af";
            var          callRateLimiterService      = new Mock <ICallRateLimiterService>();
            var          verificationEmailRepository = new Mock <IEmailVerificationCodeRepository>();
            var          customerProfileClient       = new Mock <ICustomerProfileClient>();

            callRateLimiterService.Setup(x => x.IsAllowedToCallEmailVerificationAsync(customerId))
            .ReturnsAsync(true);

            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           = "*****@*****.**",
                    IsEmailVerified = true
                }
            });

            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.RequestVerificationAsync(customerId);

            Assert.Equal(VerificationCodeError.AlreadyVerified.ToString(), result.Error.ToString());
        }
        public async Task ValidateVerificationCode_Should_Return_Error_If_VerificationCode_Not_Yet_Generated(string countryCode, string phoneNumber, int verificationCode)
        {
            var emailHelperMock      = new Mock <IEmailHelper>();
            var randomNumberProvider = new Mock <IRandomNumberProvider>();
            var expectedOutput       = await UserBuilder.Builder()
                                       .WithPhoneNumber(TEST_NUMBER, TEST_COUNTRY_CODE)
                                       .BuildAsync();

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetUserByPhoneNumber(It.IsAny <string>())).Returns(Task.FromResult(Result.Ok <User>(expectedOutput)));
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();
            var emailVerificationService      = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.ValidateVerificationCodeAsync(countryCode, phoneNumber, verificationCode);

            Assert.IsFalse(result.IsSuccessed);
            Assert.AreEqual(Constants.PhoneVerifyMessages.Error_Message, result.GetErrorString());
        }
        public async Task GenerateVerificationCode_Should_Return_True_If_countryCode_And_phoneNumber_Are_ValidAsync(string countryCode, string phoneNumber)
        {
            var emailHelperMock               = new Mock <IEmailHelper>();
            var randomNumberProvider          = new Mock <IRandomNumberProvider>();
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();

            var expectedOutput = await UserBuilder.Builder()
                                 .WithPhoneNumber(TEST_NUMBER, TEST_COUNTRY_CODE)
                                 .BuildAsync();

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetUserByPhoneNumber(It.IsAny <string>())).Returns(Task.FromResult(Result.Ok <User>(expectedOutput)));

            var emailVerificationService = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.GenerateVerificationCodeAsync(countryCode, phoneNumber);

            result.IsSuccessed.Should().BeTrue();
        }
        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 SendEmailAsync_Gets_Invoked_If_GenerateVerificationCode_Is_Called_First_Time_With_Valid_PhoneNumber(string countryCode, string phoneNumber)
        {
            var emailHelperMock      = new Mock <IEmailHelper>();
            var randomNumberProvider = new Mock <IRandomNumberProvider>();
            var expectedOutput       = await UserBuilder.Builder()
                                       .WithPhoneNumber(TEST_NUMBER, TEST_COUNTRY_CODE)
                                       .BuildAsync();

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetUserByPhoneNumber(It.IsAny <string>())).Returns(Task.FromResult(Result.Ok <User>(expectedOutput)));
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();

            verificationCodeDataStoreMock.Setup(x => x.GetValueOrDefault(It.IsAny <string>())).Returns(TEST_VERIFICATION_CODE);
            verificationCodeDataStoreMock.Setup(x => x.ContainsKey(It.IsAny <string>())).Returns(false);
            var emailVerificationService = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.GenerateVerificationCodeAsync(countryCode, phoneNumber);

            Assert.IsTrue(result.IsSuccessed);
            emailHelperMock.Verify(x => x.SendAsync(It.IsAny <string>()), Times.Once);
        }
        public async Task ValidateVerificationCode_Should_Return_Error_If_VerificationCode_Generated_But_Supplied_Incorrect_VerificationCode(string countryCode, string phoneNumber, int verificationCode)
        {
            var emailHelperMock      = new Mock <IEmailHelper>();
            var randomNumberProvider = new Mock <IRandomNumberProvider>();
            var expectedOutput       = await UserBuilder.Builder()
                                       .WithPhoneNumber(TEST_NUMBER, TEST_COUNTRY_CODE)
                                       .BuildAsync();

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetUserByPhoneNumber(It.IsAny <string>())).Returns(Task.FromResult(Result.Ok <User>(expectedOutput)));
            randomNumberProvider.Setup(x => x.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(verificationCode);
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();

            verificationCodeDataStoreMock.Setup(x => x.GetValueOrDefault(It.IsAny <string>())).Returns(verificationCode);
            verificationCodeDataStoreMock.Setup(x => x.ContainsKey(It.IsAny <string>())).Returns(true);
            var emailVerificationService = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.ValidateVerificationCodeAsync(countryCode, phoneNumber, TEST_VERIFICATION_CODE_OTHER);

            Assert.IsFalse(result.IsSuccessed);
            Assert.AreEqual(Constants.PhoneVerifyMessages.Code_Error, result.GetErrorString());
        }
        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,
                    _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 ValidateVerificationCode_Should_Return_True_When_Supplied_Correct_VerificationCode(string countryCode, string phoneNumber, int verificationCode)
        {
            var emailHelperMock      = new Mock <IEmailHelper>();
            var randomNumberProvider = new Mock <IRandomNumberProvider>();
            var expectedOutput       = await UserBuilder.Builder()
                                       .WithPhoneNumber(TEST_NUMBER, TEST_COUNTRY_CODE)
                                       .BuildAsync();

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetUserByPhoneNumber(It.IsAny <string>())).Returns(Task.FromResult(Result.Ok <User>(expectedOutput)));

            userRepositoryMock.Setup(x => x.SaveChangesAsync(It.IsAny <string>())).Returns(Task.FromResult(Result.Ok()));
            randomNumberProvider.Setup(x => x.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(verificationCode);
            var verificationCodeDataStoreMock = new Mock <IVerificationCodeDataStore>();

            verificationCodeDataStoreMock.Setup(x => x.GetValueOrDefault(It.IsAny <string>())).Returns(verificationCode);
            verificationCodeDataStoreMock.Setup(x => x.ContainsKey(It.IsAny <string>())).Returns(true);
            var emailVerificationService = new EmailVerificationService(emailHelperMock.Object, randomNumberProvider.Object, verificationCodeDataStoreMock.Object, userRepositoryMock.Object);
            var result = await emailVerificationService.ValidateVerificationCodeAsync(countryCode, phoneNumber, verificationCode);

            Assert.IsTrue(result.IsSuccessed);
        }