Beispiel #1
0
        public void AppliesEmittedEvents()
        {
            var aggregateRootRepository = CreateAggregateRootRepository();
            var someAggregate           = new SomeAggregate
            {
                UnitOfWork = new ConsoleOutUnitOfWork(aggregateRootRepository),
            };

            someAggregate.Initialize("root_id");

            someAggregate.DoSomething();

            Assert.That(someAggregate.StuffThatWasDone.Count, Is.EqualTo(1));
            Assert.That(someAggregate.StuffThatWasDone.First(), Is.EqualTo("emitted an event"));
        }
Beispiel #2
0
        public void ProvidesSuitableMetadataOnEvents()
        {
            var timeForFirstEvent = new DateTime(1979, 3, 19, 19, 0, 0, DateTimeKind.Utc);
            var timeForNextEvent  = timeForFirstEvent.AddMilliseconds(2);

            var aggregateRootRepository = CreateAggregateRootRepository();
            var eventCollector          = new InMemoryUnitOfWork(aggregateRootRepository, _defaultDomainTypeNameMapper);

            var someAggregate = new SomeAggregate
            {
                UnitOfWork = eventCollector,
            };

            someAggregate.Initialize("root_id");

            TimeMachine.FixCurrentTimeTo(timeForFirstEvent);

            someAggregate.DoSomething();

            TimeMachine.FixCurrentTimeTo(timeForNextEvent);

            someAggregate.DoSomething();

            var events     = eventCollector.Cast <SomeEvent>().ToList();
            var firstEvent = events[0];

            Assert.That(firstEvent.Meta[DomainEvent.MetadataKeys.TimeUtc], Is.EqualTo(timeForFirstEvent.ToString("u")));
            Assert.That(firstEvent.Meta[DomainEvent.MetadataKeys.Owner], Is.EqualTo("d60.Cirqus.Tests.Aggregates.TestEventApplication+SomeAggregate, d60.Cirqus.Tests"));
            Assert.That(firstEvent.Meta[DomainEvent.MetadataKeys.Type], Is.EqualTo("d60.Cirqus.Tests.Aggregates.TestEventApplication+SomeEvent, d60.Cirqus.Tests"));
            Assert.That(firstEvent.Meta[DomainEvent.MetadataKeys.SequenceNumber], Is.EqualTo("0"));
            Assert.That(firstEvent.Meta[DomainEvent.MetadataKeys.AggregateRootId], Is.EqualTo("root_id"));

            var nextEvent = events[1];

            Assert.That(nextEvent.Meta[DomainEvent.MetadataKeys.TimeUtc], Is.EqualTo(timeForNextEvent.ToString("u")));
            Assert.That(nextEvent.Meta[DomainEvent.MetadataKeys.Owner], Is.EqualTo("d60.Cirqus.Tests.Aggregates.TestEventApplication+SomeAggregate, d60.Cirqus.Tests"));
            Assert.That(nextEvent.Meta[DomainEvent.MetadataKeys.Type], Is.EqualTo("d60.Cirqus.Tests.Aggregates.TestEventApplication+SomeEvent, d60.Cirqus.Tests"));
            Assert.That(nextEvent.Meta[DomainEvent.MetadataKeys.SequenceNumber], Is.EqualTo("1"));
            Assert.That(nextEvent.Meta[DomainEvent.MetadataKeys.AggregateRootId], Is.EqualTo("root_id"));
        }