ConfirmCustomerEmailAddress_WrongHashAfterPreviousCorrectConfirmation_ConfirmationFailedEventReturned()
        {
            // given
            var customerRegisteredEvent            = CreateCustomerRegisteredEvent();
            var customerEmailAddressConfirmedEvent = new CustomerEmailAddressConfirmed(_customerId);

            var customer = Customer.Reconstitute(
                new IEvent[] { customerRegisteredEvent, customerEmailAddressConfirmedEvent });

            var wrongHash = Guid.NewGuid().ToString();

            var confirmCustomerEmailAddress = new ConfirmCustomerEmailAddress(
                _customerId.Value.ToString(),
                wrongHash);

            // when
            var resultEvent = customer.ConfirmCustomerEmailAddress(confirmCustomerEmailAddress);

            // then
            Assert.NotNull(resultEvent);
            Assert.IsType <CustomerEmailAddressConfirmationFailed>(resultEvent);

            var confirmationFailed = (CustomerEmailAddressConfirmationFailed)resultEvent;

            Assert.Equal(_customerId.Value, confirmationFailed.Id.Value);
        }
Пример #2
0
        public void ConfirmCustomerEmailAddress_ConfirmUpdatedEmailAddress_AddressConfirmedEventReturned()
        {
            // given
            var customerRegisteredEvent = CreateCustomerRegisteredEvent();

            var addressConfirmedEvent = new CustomerEmailAddressConfirmed(_customerId);

            var newEmailAddress             = new EmailAddress("*****@*****.**");
            var newEmailHash                = new CustomHash();
            var customerEmailAddressChanged = new CustomerEmailAddressChanged(
                _customerId,
                newEmailAddress,
                newEmailHash);

            var customer = Customer.Reconstitute(
                new IEvent[] { customerRegisteredEvent, addressConfirmedEvent, customerEmailAddressChanged });

            var confirmCustomerEmailAddress = new ConfirmCustomerEmailAddress(
                _customerId.Value.ToString(),
                newEmailHash.Value.ToString());

            // when
            var resultEvent = customer.ConfirmCustomerEmailAddress(confirmCustomerEmailAddress);

            // then
            Assert.NotNull(resultEvent);
            Assert.IsType <CustomerEmailAddressConfirmed>(resultEvent);
            var addressConfirmed = (CustomerEmailAddressConfirmed)resultEvent;

            Assert.Equal(_customerId.Value, addressConfirmed.Id.Value);
            Assert.True(customer.IsEmailAddressConfirmed);
        }
Пример #3
0
        public static List <IEvent> ConfirmEmailAddress(List <IEvent> eventStream, ConfirmCustomerEmailAddress command)
        {
            bool isEmailAddressConfirmed = false;
            Hash confirmationHash        = null;

            foreach (var @event in eventStream)
            {
                if (@event is CustomerRegistered)
                {
                    // TODO
                }
                else if (@event is CustomerEmailAddressConfirmed)
                {
                    // TODO
                }
                else if (@event is CustomerEmailAddressChanged)
                {
                    // TODO
                }
            }

            // TODO

            return(new List <IEvent>()); // TODO
        }
Пример #4
0
        public static List <IEvent> ConfirmEmailAddress(List <IEvent> eventStream, ConfirmCustomerEmailAddress command)
        {
            var current = CustomerState.Reconstitute(eventStream);

            // TODO

            return(new List <IEvent>()); // TODO
        }
Пример #5
0
        public void ConfirmEmailAddress(ConfirmCustomerEmailAddress command)
        {
            if (!command.ConfirmationHash.Equals(ConfirmationHash))
            {
                throw new WrongConfirmationHashException();
            }

            IsEmailAddressConfirmed = true;
        }
Пример #6
0
        private void WHEN_ConfirmEmailAddress_With(Hash confirmationHash)
        {
            var command = ConfirmCustomerEmailAddress.Build(customerID.Value, confirmationHash.Value);

            try {
                recordedEvents = registeredCustomer.ConfirmEmailAddress(command);
            } catch (NullReferenceException e) {
                throw new XunitException(THelper.propertyIsNull("confirmationHash"));
            }
        }
Пример #7
0
        private void givenEmailAddressWasConfirmed()
        {
            var command = ConfirmCustomerEmailAddress.Build(customerID.Value, confirmationHash.Value);

            try {
                registeredCustomer.ConfirmEmailAddress(command);
            } catch (WrongConfirmationHashException e) {
                throw new XunitException("unexpected error in givenEmailAddressWasConfirmed: " + e.Message);
            }
        }
        public IEvent ConfirmCustomerEmailAddress(
            ConfirmCustomerEmailAddress confirmCustomerEmailAddressEvent)
        {
            if (Hash.Value != confirmCustomerEmailAddressEvent.Hash.Value)
            {
                return(new CustomerEmailAddressConfirmationFailed(Id));
            }

            return(new CustomerEmailAddressConfirmed(confirmCustomerEmailAddressEvent.Id));
        }
Пример #9
0
        void confirmEmailAddress_withWrongConfirmationHash()
        {
            // Given
            givenARegisteredCustomer();

            // When confirmCustomerEmailAddress
            // Then it should throw WrongConfirmationHashException
            var command = ConfirmCustomerEmailAddress.Build(customerID.Value, wrongConfirmationHash.Value);

            Assert.Throws <WrongConfirmationHashException>(() => Customer2.ConfirmEmailAddress(registeredCustomer, command));
        }
Пример #10
0
        void confirmEmailAddress()
        {
            // Given
            givenARegisteredCustomer();

            // When confirmCustomerEmailAddress
            // Then it should succeed
            var command         = ConfirmCustomerEmailAddress.Build(customerID.Value, confirmationHash.Value);
            var changedCustomer = Customer2.ConfirmEmailAddress(registeredCustomer, command);

            // and the emailAddress of the changed Customer should be confirmed
            Assert.True(changedCustomer.IsEmailAddressConfirmed);
        }
Пример #11
0
        void confirmEmailAddress_withWrongConfirmationHash()
        {
            // Given
            givenARegisteredCustomer();

            // When confirmCustomerEmailAddress
            // Then it should throw WrongConfirmationHashException
            var command = ConfirmCustomerEmailAddress.Build(customerID.Value, wrongConfirmationHash.Value);

            Assert.Throws <WrongConfirmationHashException>(() => registeredCustomer.ConfirmEmailAddress(command));

            // and the emailAddress should not be confirmed
            Assert.False(registeredCustomer.IsEmailAddressConfirmed);
        }
Пример #12
0
        void confirmEmailAddress_whenItWasPreviouslyConfirmedAndThenChanged()
        {
            // Given
            givenARegisteredCustomer();
            givenEmailAddressWasConfirmed();
            givenEmailAddressWasChanged();

            // When confirmEmailAddress
            // Then it should throw WrongConfirmationHashException
            var command         = ConfirmCustomerEmailAddress.Build(customerID.Value, changedConfirmationHash.Value);
            var changedCustomer = Customer2.ConfirmEmailAddress(registeredCustomer, command);

            // and the emailAddress of the changed Customer should be confirmed
            Assert.True(changedCustomer.IsEmailAddressConfirmed);
        }
Пример #13
0
        void confirmEmailAddress_whenItWasPreviouslyConfirmedAndThenChanged()
        {
            // Given
            givenARegisteredCustomer();
            givenEmailAddressWasConfirmed();
            givenEmailAddressWasChanged();

            // When confirmCustomerEmailAddress
            // Then it should succeed
            var command = ConfirmCustomerEmailAddress.Build(customerID.Value, changedConfirmationHash.Value);

            registeredCustomer.ConfirmEmailAddress(command);

            // and the emailAddress should be confirmed
            Assert.True(registeredCustomer.IsEmailAddressConfirmed);
        }
        public void ConfirmCustomerEmailAddress_RightHash_CustomerIsEmailAddressConfirmed()
        {
            // given
            var customerRegisteredEvent = CreateCustomerRegisteredEvent();
            var customer = Customer.Reconstitute(new[] { customerRegisteredEvent });

            var confirmCustomerEmailAddressEvent = new ConfirmCustomerEmailAddress(
                _customerId.Value.ToString(),
                _hash.Value.ToString());

            // when
            customer.ConfirmCustomerEmailAddress(confirmCustomerEmailAddressEvent);

            // then
            Assert.True(customer.IsEmailAddressConfirmed);
        }
        public static CustomerState ConfirmEmailAddress(CustomerState current, ConfirmCustomerEmailAddress command)
        {
            if (!command.ConfirmationHash.Equals(current.ConfirmationHash))
            {
                throw new WrongConfirmationHashException();
            }


            return(new CustomerState(
                       current.CustomerId,
                       current.EmailAddress,
                       current.ConfirmationHash,
                       current.Name,
                       true
                       ));
        }
Пример #16
0
        public void ConfirmCustomerEmailAddress_CorrectConfirmationEventReturned()
        {
            // given
            ID           customerId              = new ID();
            EmailAddress emailAddress            = new EmailAddress("*****@*****.**");
            CustomHash   hash                    = new CustomHash();
            PersonName   personName              = new PersonName("given", "fam");
            var          customerRegisteredEvent = new CustomerRegistered(customerId, emailAddress, hash, personName);
            var          customer                = Customer.Reconstitute(new[] { customerRegisteredEvent });

            var confirmCustomerEmailAddressEvent = new ConfirmCustomerEmailAddress(customerId.Value.ToString(), hash.Value.ToString());

            // when
            var resultEvent = customer.ConfirmCustomerEmailAddress(confirmCustomerEmailAddressEvent);

            // then
        }
Пример #17
0
        public void ConfirmCustomerEmailAddress_CorrectConfirmationEventReturned()
        {
            // given
            var customerRegisteredEvent = CreateCustomerRegisteredEvent();
            var customer = Customer.Reconstitute(new[] { customerRegisteredEvent });

            var confirmCustomerEmailAddressEvent = new ConfirmCustomerEmailAddress(_customerId.Value.ToString(), _hash.Value.ToString());

            // when
            var resultEvent = customer.ConfirmCustomerEmailAddress(confirmCustomerEmailAddressEvent);

            // then
            Assert.NotNull(resultEvent);
            Assert.IsType <CustomerEmailAddressConfirmed>(resultEvent);

            var confirmedEvent = (CustomerEmailAddressConfirmed)resultEvent;

            Assert.Equal(_customerId.Value, confirmedEvent.Id.Value);
        }
        ConfirmCustomerEmailAddress_CorrectHashAfterPreviousCorrectConfirmation_NoEventReturned()
        {
            // given
            var customerRegisteredEvent            = CreateCustomerRegisteredEvent();
            var customerEmailAddressConfirmedEvent = new CustomerEmailAddressConfirmed(_customerId);

            var customer = Customer.Reconstitute(
                new IEvent[] { customerRegisteredEvent, customerEmailAddressConfirmedEvent });

            var confirmCustomerEmailAddress = new ConfirmCustomerEmailAddress(
                _customerId.Value.ToString(),
                _hash.Value.ToString());

            // when
            var resultEvent = customer.ConfirmCustomerEmailAddress(confirmCustomerEmailAddress);

            // then
            Assert.Null(resultEvent);
        }
Пример #19
0
 public void ConfirmEmailAddress(ConfirmCustomerEmailAddress command)
 {
     // TODO
 }
Пример #20
0
        public static List <IEvent> ConfirmEmailAddress(CustomerState current, ConfirmCustomerEmailAddress command)
        {
            // TODO

            return(new List <IEvent>()); // TODO
        }
 public IEvent ConfirmCustomerEmailAddress(
     ConfirmCustomerEmailAddress confirmCustomerEmailAddressEvent)
 {
     return(new CustomerEmailAddressConfirmed(confirmCustomerEmailAddressEvent.Id));
 }
Пример #22
0
        public List <IEvent> ConfirmEmailAddress(ConfirmCustomerEmailAddress command)
        {
            // TODO

            return(new List <IEvent>()); // TODO
        }
Пример #23
0
 public IEvent ConfirmCustomerEmailAddress(ConfirmCustomerEmailAddress confirmCustomerEmailAddressEvent)
 {
     throw new System.NotImplementedException();
 }