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);
        }
Beispiel #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);
        }
Beispiel #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
        }
Beispiel #4
0
        public static List <IEvent> ConfirmEmailAddress(List <IEvent> eventStream, ConfirmCustomerEmailAddress command)
        {
            var current = CustomerState.Reconstitute(eventStream);

            // TODO

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

            IsEmailAddressConfirmed = true;
        }
Beispiel #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"));
            }
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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
                       ));
        }
Beispiel #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
        }
Beispiel #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);
        }
Beispiel #19
0
 public void ConfirmEmailAddress(ConfirmCustomerEmailAddress command)
 {
     // TODO
 }
Beispiel #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));
 }
Beispiel #22
0
        public List <IEvent> ConfirmEmailAddress(ConfirmCustomerEmailAddress command)
        {
            // TODO

            return(new List <IEvent>()); // TODO
        }
Beispiel #23
0
 public IEvent ConfirmCustomerEmailAddress(ConfirmCustomerEmailAddress confirmCustomerEmailAddressEvent)
 {
     throw new System.NotImplementedException();
 }