コード例 #1
0
        public async Task UserTriesToChangePassword_EverythingValid_Successful()
        {
            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
                {
                    Email = "*****@*****.**"
                }
            });

            var credentialsClient = new Mock <ICredentialsClient>();

            credentialsClient.Setup(c => c.Api.ChangePasswordAsync(It.IsAny <CredentialsUpdateRequest>()))
            .ReturnsAsync(new CredentialsUpdateResponse());


            var postProcessService = new Mock <IPostProcessService>();

            var customerFlagsRepository = new Mock <ICustomerFlagsRepository>();

            customerFlagsRepository
            .Setup(c => c.GetByCustomerIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new CustomerFlagsEntity {
                IsBlocked = false
            });

            var sessionsServiceClient = new Mock <ISessionsServiceClient>();

            CustomersService customersService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                customersService = new CustomersService(
                    credentialsClient.Object,
                    postProcessService.Object,
                    customerProfileClient.Object,
                    customerFlagsRepository.Object,
                    sessionsServiceClient.Object,
                    _passwordSuccessfulChangeEmailTemplateId,
                    _passwordSuccessfulChangeEmailSubjectTemplateId,
                    logFactory,
                    MaxBatchValue,
                    _publisher.Object,
                    _customerBlockEmailTemplateId,
                    _customerUnBlockEmailTemplateId,
                    _customerBlockSubjectTemplateId,
                    _customerUnBlockSubjectTemplateId,
                    _customerSupportPhoneNumber);
            }

            var expected = new ChangePasswordResultModel();
            var actual   = await customersService.ChangePasswordAsync("customerId", "password");


            Assert.Equal(expected.Error, actual.Error);
        }
コード例 #2
0
        public async Task UserTriesToChangePassword_CustomerDoesNotExist_ExceptionIsRethrown()
        {
            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
                {
                    Email = "*****@*****.**"
                }
            });

            var credentialsClient = new Mock <ICredentialsClient>();

            var errorResponse = new ErrorResponse
            {
                ModelErrors = new Dictionary <string, List <string> >
                {
                    { nameof(CredentialsCreateRequest.Login), new List <string>() }
                },
                ErrorMessage = "Customer does not exist"
            };

            var exception = new ClientApiException(HttpStatusCode.BadRequest, errorResponse);

            credentialsClient.Setup(c => c.Api.ChangePasswordAsync(It.IsAny <CredentialsUpdateRequest>()))
            .ThrowsAsync(exception);

            var postProcessService = new Mock <IPostProcessService>();

            var customerFlagsRepository = new Mock <ICustomerFlagsRepository>();

            customerFlagsRepository
            .Setup(c => c.GetByCustomerIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new CustomerFlagsEntity {
                IsBlocked = false
            });

            var sessionsServiceClient = new Mock <ISessionsServiceClient>();

            CustomersService customersService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                customersService = new CustomersService(
                    credentialsClient.Object,
                    postProcessService.Object,
                    customerProfileClient.Object,
                    customerFlagsRepository.Object,
                    sessionsServiceClient.Object,
                    _passwordSuccessfulChangeEmailTemplateId,
                    _passwordSuccessfulChangeEmailSubjectTemplateId,
                    logFactory,
                    MaxBatchValue,
                    _publisher.Object,
                    _customerBlockEmailTemplateId,
                    _customerUnBlockEmailTemplateId,
                    _customerBlockSubjectTemplateId,
                    _customerUnBlockSubjectTemplateId,
                    _customerSupportPhoneNumber);
            }


            await Assert.ThrowsAsync <ClientApiException>(() =>
                                                          customersService.ChangePasswordAsync("customerId", "password"));
        }
コード例 #3
0
        public async Task UserTriesToChangePassword_PasswordIsNotInValidFormat_BusinessErrorIsReturned()
        {
            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
                {
                    Email = "*****@*****.**"
                }
            });

            var credentialsClient = new Mock <ICredentialsClient>();

            var errorResponse = new ErrorResponse
            {
                ModelErrors = new Dictionary <string, List <string> >
                {
                    { nameof(CredentialsCreateRequest.Password), new List <string>() }
                }
            };

            var invalidPasswordException = new ClientApiException(HttpStatusCode.BadRequest, errorResponse);


            var postProcessService = new Mock <IPostProcessService>();

            credentialsClient.Setup(c => c.Api.ChangePasswordAsync(It.IsAny <CredentialsUpdateRequest>()))
            .ThrowsAsync(invalidPasswordException);

            var customerFlagsRepository = new Mock <ICustomerFlagsRepository>();

            customerFlagsRepository
            .Setup(c => c.GetByCustomerIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new CustomerFlagsEntity {
                IsBlocked = false
            });

            var sessionsServiceClient = new Mock <ISessionsServiceClient>();

            CustomersService customersService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                customersService = new CustomersService(
                    credentialsClient.Object,
                    postProcessService.Object,
                    customerProfileClient.Object,
                    customerFlagsRepository.Object,
                    sessionsServiceClient.Object,
                    _passwordSuccessfulChangeEmailTemplateId,
                    _passwordSuccessfulChangeEmailSubjectTemplateId,
                    logFactory,
                    MaxBatchValue,
                    _publisher.Object,
                    _customerBlockEmailTemplateId,
                    _customerUnBlockEmailTemplateId,
                    _customerBlockSubjectTemplateId,
                    _customerUnBlockSubjectTemplateId,
                    _customerSupportPhoneNumber);
            }

            var expected = new ChangePasswordResultModel(ServicesError.InvalidPasswordFormat);
            var actual   = await customersService.ChangePasswordAsync("customerId", "password");

            Assert.Equal(expected.Error, actual.Error);
        }