Exemplo n.º 1
0
        public void ChangeName(string forename, string surname)
        {
            var e = new CustomerNameChanged(forename, surname);

            this.Apply(e);
            this.Events.Add(e);
        }
        private void When(CustomerNameChanged e)
        {
            this.Version = e.Version;

            this.FirstName = e.FirstName;
            this.LastName  = e.LastName;
        }
Exemplo n.º 3
0
        public void Saving_with_concurrent_event_edits_should_be_subject_to_concurrency_checks()
        {
            // test created in response to an issue with concurrent edits happening within the window between
            // reading the current version number of the aggregate and the event source record being updated with
            // the new version number. this would leave the event stream for an event source out of sequence and
            // the aggregate in a state in which it could not be retrieved :o
            var concurrencyExceptionThrown = false;

            var targetStore = new MsSqlServerEventStore(connectionString);

            var theEventSourceId = Guid.NewGuid();
            var theCommitId      = Guid.NewGuid();

            // make sure that the event source for the aggregate is created
            var creationEvent = Prepare.Events(new CustomerCreatedEvent("Foo", 35))
                                .ForSourceUncomitted(theEventSourceId, theCommitId);

            targetStore.Store(creationEvent);

            var tasks = new Task[130];

            // now simulate concurreny updates coming in on the same aggregate
            for (int idx = 0; idx < tasks.Length; idx++)
            {
                tasks[idx] = Task.Factory.StartNew(() =>
                {
                    var changeEvent = new CustomerNameChanged(DateTime.Now.Ticks.ToString())
                    {
                        CustomerId = theEventSourceId
                    };
                    var eventStream = Prepare.Events(changeEvent)
                                      .ForSourceUncomitted(theEventSourceId, Guid.NewGuid(), 2);

                    try
                    {
                        targetStore.Store(eventStream);
                    }
                    catch (ConcurrencyException)
                    {
                        concurrencyExceptionThrown = true;
                    }

                    targetStore.ReadFrom(theEventSourceId, long.MinValue, long.MaxValue);
                });
            }

            Task.WaitAll(tasks);

            if (concurrencyExceptionThrown == false)
            {
                Assert.True(false, "We're expecting concurrency exceptions!");
            }
        }
        public void ChangeCustomersName_SameNameAsChangedPreviouslyTo_NoEventReturned()
        {
            // given
            var customerRegisteredEvent = CreateCustomerRegisteredEvent();

            var newGivenName        = "New";
            var newFamilyName       = "Name";
            var newPersonName       = new PersonName(newGivenName, newFamilyName);
            var customerNameChanged = new CustomerNameChanged(_customerId, newPersonName);

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

            var changeCustomersName = new ChangeCustomersName(_customerId.Value.ToString(), newGivenName, newFamilyName);

            // when
            var resultEvent = customer.ChangeCustomersName(changeCustomersName);

            // then
            Assert.Null(resultEvent);
        }
Exemplo n.º 5
0
 public void On(CustomerNameChanged @event)
 {
     Id        = Guid.Parse(@event.CustomerId);
     FirstName = @event.FirstName;
     LastName  = @event.LastName;
 }
        public void Saving_with_concurrent_event_edits_should_be_subject_to_concurrency_checks()
        {
            // test created in response to an issue with concurrent edits happening within the window between
            // reading the current version number of the aggregate and the event source record being updated with
            // the new version number. this would leave the event stream for an event source out of sequence and
            // the aggregate in a state in which it could not be retrieved :o
            var concurrencyExceptionThrown = false;

            var targetStore = new MsSqlServerEventStore(connectionString);

            var theEventSourceId = Guid.NewGuid();
            var theCommitId = Guid.NewGuid();

            // make sure that the event source for the aggregate is created
            var creationEvent = Prepare.Events(new CustomerCreatedEvent("Foo", 35))
                .ForSourceUncomitted(theEventSourceId, theCommitId);
            targetStore.Store(creationEvent);

            var tasks = new Task[130];

            // now simulate concurreny updates coming in on the same aggregate
            for (int idx = 0; idx < tasks.Length; idx++)
            {
                tasks[idx] = Task.Factory.StartNew(() =>
                {

                    var changeEvent = new CustomerNameChanged(DateTime.Now.Ticks.ToString()) { CustomerId = theEventSourceId };
                    var eventStream = Prepare.Events(changeEvent)
                        .ForSourceUncomitted(theEventSourceId, Guid.NewGuid(), 2);

                    try
                    {
                        targetStore.Store(eventStream);

                    }
                    catch (ConcurrencyException)
                    {
                        concurrencyExceptionThrown = true;
                    }

                    targetStore.ReadFrom(theEventSourceId, long.MinValue, long.MaxValue);

                });
            }

            Task.WaitAll(tasks);

            if (concurrencyExceptionThrown == false)
            {
               Assert.Fail("We're expecting concurrency exceptions!");
            }
        }
Exemplo n.º 7
0
 public void Apply(CustomerNameChanged @event)
 {
     _name = @event.Name;
 }
Exemplo n.º 8
0
 public void Consume(CustomerNameChanged message)
 {
     Interlocked.Increment(ref HandledEvents);
 }
Exemplo n.º 9
0
 private void Apply(CustomerNameChanged e)
 {
     this.Forename = e.Forename;
     this.Surname  = e.Surname;
 }
Exemplo n.º 10
0
 public void On(CustomerNameChanged @event)
 {
     FirstName = @event.FirstName;
     LastName  = @event.LastName;
 }
 void IApplyDomainEvent <CustomerNameChanged> .Apply(CustomerNameChanged domainEvent, bool isNew)
 {
     Name = domainEvent.Name;
 }
Exemplo n.º 12
0
 public void When(CustomerNameChanged evt)
 {
     Name = evt.Name;
 }
Exemplo n.º 13
0
 public void When(CustomerNameChanged evt)
 {
     Name = evt.Name;
 }
Exemplo n.º 14
0
 void When(CustomerNameChanged e)
 {
     CustomerFullName = e.CustomerName;
 }