예제 #1
0
        public void RegisterNewCustomer_WithValidData_ShouldSucceed()
        {
            var customerChecker = Substitute.For <ICustomerChecker>();

            customerChecker.IsCustomerEmailInUse(CustomerRegistrationSampleData.Email)
            .Returns(false);

            var registration = CustomerRegistration.RegisterNewCustomer(
                CustomerRegistrationSampleData.Id,
                CustomerRegistrationSampleData.Email,
                CustomerRegistrationSampleData.Password,
                CustomerRegistrationSampleData.FirstName,
                CustomerRegistrationSampleData.LastName,
                customerChecker
                );

            Assert.That(registration, Is.Not.Null);

            var domainEvent = AssertPublishedDomainEvent <NewCustomerRegisteredDomainEvent>(registration);

            Assert.That(domainEvent.CustomerRegistrationId, Is.EqualTo(CustomerRegistrationSampleData.Id));
            Assert.That(domainEvent.Email, Is.EqualTo(CustomerRegistrationSampleData.Email));
            Assert.That(domainEvent.Password, Is.EqualTo(CustomerRegistrationSampleData.Password));
            Assert.That(domainEvent.FirstName, Is.EqualTo(CustomerRegistrationSampleData.FirstName));
            Assert.That(domainEvent.LastName, Is.EqualTo(CustomerRegistrationSampleData.LastName));
        }
        public async Task <Unit> Handle(RegisterNewCustomerCommand command, CancellationToken cancellationToken)
        {
            var customerRegistration = CustomerRegistration.RegisterNewCustomer(
                new CustomerRegistrationId(command.CustomerRegistrationId),
                command.Email,
                _passwordHasher.HashPassword(command.Password),
                command.FirstName,
                command.LastName,
                _customerChecker
                );

            await _customerRegistrationRepository.AddAsync(customerRegistration);

            return(Unit.Value);
        }
예제 #3
0
        public void RegisterNewCustomer_WithAlreadyUsedEmail_ShouldFail()
        {
            var customerChecker = Substitute.For <ICustomerChecker>();

            customerChecker.IsCustomerEmailInUse(CustomerRegistrationSampleData.Email)
            .Returns(true);

            AssertBrokenRule <CustomerEmailMustBeUniqueRule>(() =>
            {
                CustomerRegistration.RegisterNewCustomer(
                    CustomerRegistrationSampleData.Id,
                    CustomerRegistrationSampleData.Email,
                    CustomerRegistrationSampleData.Password,
                    CustomerRegistrationSampleData.FirstName,
                    CustomerRegistrationSampleData.LastName,
                    customerChecker
                    );
            });
        }