Пример #1
0
        public async Task UserTriesToLogIn_WithInvalidFormatEmail_InvalidEmailOrPasswordFormatErrorReturned()
        {
            var sessionsServiceClient = new Mock <ISessionsServiceClient>();
            var credentialsClient     = new Mock <ICredentialsClient>();
            var adminUsersService     = new Mock <IAdminUserService>();

            var exception = new ClientApiException(HttpStatusCode.BadRequest, new ErrorResponse());
            var adminUsersServiceResponse = GetAdminUserResult();

            credentialsClient
            .Setup(x => x.Admins.ValidateAsync(It.IsAny <CredentialsValidationRequest>()))
            .Throws(exception);

            adminUsersService
            .Setup(x => x.GetByEmailAsync(It.IsAny <string>(), null))
            .ReturnsAsync(adminUsersServiceResponse);

            AuthService authService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                authService = new AuthService(
                    sessionsServiceClient.Object,
                    credentialsClient.Object,
                    adminUsersService.Object,
                    logFactory);
            }

            var result = await authService.AuthAsync("email", "password");

            Assert.Equal(ServicesError.InvalidEmailOrPasswordFormat.ToString(), result.Error.ToString());
            Assert.Null(result.CustomerId);
            Assert.Null(result.Token);
        }
        public async Task UserTriesToLogIn_WithInvalidFormatEmail_InvalidPasswordFormatErrorReturned()
        {
            var sessionsServiceClient = new Mock <ISessionsServiceClient>();
            var credentialsClient     = new Mock <ICredentialsClient>();
            var customerProfileClient = new Mock <ICustomerProfileClient>();

            var modelError = new ErrorResponse
            {
                ModelErrors = new Dictionary <string, List <string> >
                {
                    { nameof(CredentialsValidationRequest.Password), new List <string>() }
                }
            };
            var exception = new ClientApiException(HttpStatusCode.BadRequest, modelError);

            credentialsClient
            .Setup(x => x.Api.ValidateCredentialsAsync(It.IsAny <CredentialsValidationRequest>()))
            .Throws(exception);

            var customerService = new Mock <ICustomersService>();

            AuthService authService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                authService = new AuthService(
                    sessionsServiceClient.Object,
                    credentialsClient.Object,
                    customerProfileClient.Object,
                    customerService.Object,
                    logFactory);
            }

            var result = await authService.AuthAsync("email", "password");

            Assert.Equal(CustomerManagementError.InvalidPasswordFormat.ToString(), result.Error.ToString());
            Assert.Null(result.CustomerId);
            Assert.Null(result.Token);
        }
Пример #3
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"));
        }
Пример #4
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);
        }