public void BasicDispatchOfSomeEvents() { var allPotatoesView = new MongoDbViewManager <AllPotatoesView>(_mongoDatabase); var potatoTimeToBeConsumedView = new MongoDbViewManager <PotatoTimeToBeConsumedView>(_mongoDatabase); _dispatcher.AddViewManager(allPotatoesView); _dispatcher.AddViewManager(potatoTimeToBeConsumedView); // act var firstPointInTime = new DateTime(1979, 3, 1, 12, 0, 0, DateTimeKind.Utc); TimeMachine.FixCurrentTimeTo(firstPointInTime); _commandProcessor.ProcessCommand(new BitePotato("potato1", 0.5m)); _commandProcessor.ProcessCommand(new BitePotato("potato2", 0.3m)); _commandProcessor.ProcessCommand(new BitePotato("potato2", 0.3m)); _commandProcessor.ProcessCommand(new BitePotato("potato3", 0.3m)); var nextPointInTime = new DateTime(1981, 6, 9, 12, 0, 0, DateTimeKind.Utc); TimeMachine.FixCurrentTimeTo(nextPointInTime); _commandProcessor.ProcessCommand(new BitePotato("potato1", 0.5m)); _commandProcessor.ProcessCommand(new BitePotato("potato2", 0.5m)); var lastPointInTime = new DateTime(1981, 6, 9, 12, 0, 0, DateTimeKind.Utc); _commandProcessor.ProcessCommand(new BitePotato("potato3", 0.8m)); Thread.Sleep(1000); // assert var allPotatoes = allPotatoesView.Load(GlobalInstanceLocator.GetViewInstanceId()); Assert.That(allPotatoes, Is.Not.Null); var potato1View = potatoTimeToBeConsumedView.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("potato1")); var potato2View = potatoTimeToBeConsumedView.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("potato2")); var potato3View = potatoTimeToBeConsumedView.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("potato3")); Assert.That(potato1View, Is.Not.Null); Assert.That(potato2View, Is.Not.Null); Assert.That(potato3View, Is.Not.Null); Assert.That(allPotatoes.NamesOfPotatoes.Count, Is.EqualTo(3)); Assert.That(allPotatoes.NamesOfPotatoes["potato1"], Is.EqualTo("Jeff")); Assert.That(allPotatoes.NamesOfPotatoes["potato2"], Is.EqualTo("Bunny")); Assert.That(allPotatoes.NamesOfPotatoes["potato3"], Is.EqualTo("Walter")); Assert.That(potato1View.Name, Is.EqualTo("Jeff")); Assert.That(potato1View.TimeOfCreation.ToUniversalTime(), Is.EqualTo(firstPointInTime)); Assert.That(potato1View.TimeToBeEaten, Is.EqualTo(nextPointInTime - firstPointInTime)); Assert.That(potato2View.Name, Is.EqualTo("Bunny")); Assert.That(potato2View.TimeOfCreation.ToUniversalTime(), Is.EqualTo(firstPointInTime)); Assert.That(potato2View.TimeToBeEaten, Is.EqualTo(nextPointInTime - firstPointInTime)); Assert.That(potato3View.Name, Is.EqualTo("Walter")); Assert.That(potato3View.TimeOfCreation.ToUniversalTime(), Is.EqualTo(firstPointInTime)); Assert.That(potato3View.TimeToBeEaten, Is.EqualTo(lastPointInTime - firstPointInTime)); }
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")); }
public void TimeStampsCanRoundtripAsTheyShould() { var someLocalTime = new DateTime(2015, 10, 31, 12, 10, 15, DateTimeKind.Local); var someUtcTime = someLocalTime.ToUniversalTime(); TimeMachine.FixCurrentTimeTo(someUtcTime); var serializer = new JsonDomainEventSerializer(); var processor = CreateCommandProcessor(config => config .EventStore(e => e.RegisterInstance(_eventStore)) .EventDispatcher(e => e.UseConsoleOutEventDispatcher()) .Options(o => o.RegisterInstance <IDomainEventSerializer>(serializer)));; RegisterForDisposal(processor); processor.ProcessCommand(new MakeSomeRootEmitTheEvent("rootid")); var domainEvents = _eventStore.Stream().Select(serializer.Deserialize).Single(); Assert.That(domainEvents.GetUtcTime(), Is.EqualTo(someUtcTime)); }