public void Aggregate_Should_ApplyChange_For_NewEvents()
        {
            var aggregate = new TestAggregateRoot();

            aggregate.ApplyChange(new TestEventV1());
            aggregate.ApplyChange(new AnotherTestEventV1());

            Assert.That(aggregate.TestEventFired, Is.True);
            Assert.That(aggregate.AnotherTestEventFired, Is.True);
        }
Beispiel #2
0
        public async Task SaveAggregateAsync_save_new_aggregate()
        {
            var aggregate = new TestAggregateRoot()
            {
                Id = ObjectId.Parse(_aggregateId)
            };

            aggregate.ApplyChange(new AnotherTestEventV1()
            {
                Id        = ObjectId.GenerateNewId(),
                FirstName = "Joe",
                SurName   = "Bloggs",
                IsValid   = true
            });

            await _aggregateRepository.SaveAggregateAsync(aggregate);

            var events = (await _eventStore.GetDomainEventsAsync(_aggregateId)).ToList();

            Assert.That(events.Count, Is.EqualTo(1));
            var lastEvent = events.Last();

            Assert.That(lastEvent.AggregateId, Is.EqualTo(_aggregateId));
            Assert.That(lastEvent.Type, Is.EqualTo("AnotherTestEvent"));
            Assert.That(lastEvent.Version, Is.EqualTo(1));
            Assert.That(lastEvent.Commit, Is.EqualTo(1));
            Assert.That(lastEvent.Index, Is.EqualTo(1));
        }