Esempio n. 1
0
        public async Task BlockingCustomer_CustomerAlreadyBlocked_BusinessErrorIsReturned()
        {
            var customerProfileClient = new Mock <ICustomerProfileClient>();

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

            var credentialsClient = new Mock <ICredentialsClient>();

            var postProcessService = new Mock <IPostProcessService>();

            var customerFlagsRepository = new Mock <ICustomerFlagsRepository>();

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

            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 expectedCode = CustomerBlockErrorCode.CustomerAlreadyBlocked;
            var actualCode   = await customersService.BlockCustomerAsync(Guid.NewGuid().ToString());

            Assert.Equal(expectedCode, actualCode);

            sessionsServiceClient
            .Verify(x => x.SessionsApi.DeleteSessionIfExistsAsync(It.IsAny <string>()),
                    Times.Never);
        }
Esempio n. 2
0
        public async Task BlockingCustomer_EverythingValid_Successful()
        {
            var sessions = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() };

            var customerProfileClient = new Mock <ICustomerProfileClient>();

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

            var credentialsClient = new Mock <ICredentialsClient>();

            var postProcessService = new Mock <IPostProcessService>();

            var customerFlagsRepository = new Mock <ICustomerFlagsRepository>();

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

            var sessionsServiceClient = new Mock <ISessionsServiceClient>();

            sessionsServiceClient
            .Setup(x => x.SessionsApi.GetActiveSessionsAsync(It.IsAny <string>()))
            .ReturnsAsync(sessions.Select(x => new ClientSession {
                SessionToken = x
            }).ToList);

            sessionsServiceClient
            .Setup(x => x.SessionsApi.DeleteSessionIfExistsAsync(It.IsAny <string>()))
            .Returns(Task.CompletedTask);

            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 expectedCode = CustomerBlockErrorCode.None;
            var actualCode   = await customersService.BlockCustomerAsync(Guid.NewGuid().ToString());

            Assert.Equal(expectedCode, actualCode);

            sessionsServiceClient
            .Verify(x => x.SessionsApi.DeleteSessionIfExistsAsync(It.Is <string>(y => sessions.Contains(y))),
                    Times.Exactly(sessions.Length));
        }