public static void should_have_stored_committed_events <TEvent>( this IEnumerable <CommittedEventSequence <TEvent> > batches, IStreams streams, IEventContentConverter event_content_converter) where TEvent : Dolittle.Runtime.Events.Store.CommittedEvent { var eventLog = streams.DefaultEventLog; foreach (var batch in batches) { var storedEvents = eventLog.FindSync( Builders <Event> .Filter.Gte(_ => _.EventLogSequenceNumber, batch.First().EventLogSequenceNumber.Value) & Builders <Event> .Filter.Lte(_ => _.EventLogSequenceNumber, batch.Last().EventLogSequenceNumber.Value)).ToList(); switch (batch) { case CommittedEvents committedEvents: should_have_stored_committed_events(event_content_converter, committedEvents, storedEvents); break; case CommittedAggregateEvents committedAggregateEvents: should_have_stored_committed_events(event_content_converter, committedAggregateEvents, storedEvents); break; default: throw new Exception("Wrong committed events type"); } } }
static void should_be_the_same_base_committed_event(IEventContentConverter event_content_converter, CommittedEvent committed_event, Event stored_event) { JToken.DeepEquals(JToken.Parse(event_content_converter.ToJson(stored_event.Content)), JToken.Parse(committed_event.Content)).ShouldBeTrue(); stored_event.Metadata.Occurred.ShouldBeCloseTo(committed_event.Occurred.UtcDateTime, TimeSpan.FromSeconds(1)); stored_event.Metadata.Public.ShouldEqual(committed_event.Public); stored_event.Metadata.EventSource.ShouldEqual(committed_event.EventSource.Value); stored_event.Metadata.TypeGeneration.ShouldEqual(committed_event.Type.Generation.Value); stored_event.Metadata.TypeId.ShouldEqual(committed_event.Type.Id.Value); should_have_same_execution_context(committed_event.ExecutionContext, stored_event.ExecutionContext); stored_event.EventLogSequenceNumber.ShouldEqual(committed_event.EventLogSequenceNumber.Value); }
static void should_have_stored_committed_events(IEventContentConverter event_content_converter, CommittedEvents events, List <Event> stored_events) { stored_events.Count.ShouldEqual(events.Count); if (stored_events.Count == 0) { return; } stored_events.ShouldEachConformTo(_ => _.Aggregate.WasAppliedByAggregate == false); stored_events.ShouldEachConformTo(_ => _.EventHorizon.FromEventHorizon == false); for (var i = 0; i < stored_events.Count; i++) { should_be_the_same_base_committed_event(event_content_converter, events[i], stored_events[i]); } }
static void should_have_stored_committed_events(IEventContentConverter event_content_converter, CommittedAggregateEvents aggregate_events, List <Event> stored_events) { stored_events.Count.ShouldEqual(aggregate_events.Count); if (stored_events.Count == 0) { return; } stored_events.ShouldEachConformTo(_ => _.Aggregate.WasAppliedByAggregate == true); stored_events.ShouldEachConformTo(_ => _.Aggregate.TypeGeneration.Equals(ArtifactGeneration.First.Value)); stored_events.ShouldEachConformTo(_ => _.Aggregate.TypeId.Equals(aggregate_events.AggregateRoot.Value)); stored_events.ShouldEachConformTo(_ => _.Metadata.EventSource.Equals(aggregate_events.EventSource)); stored_events.ShouldEachConformTo(_ => _.EventHorizon.FromEventHorizon == false); for (var i = 0; i < stored_events.Count; i++) { var storedEvent = stored_events[i]; var committedEvent = aggregate_events[i]; storedEvent.Aggregate.Version.ShouldEqual(committedEvent.AggregateRootVersion.Value); should_be_the_same_base_committed_event(event_content_converter, committedEvent, storedEvent); } }
public static void should_have_stored_committed_events <TEvent>(this CommittedEventSequence <TEvent> events, IStreams streams, IEventContentConverter event_content_converter) where TEvent : Dolittle.Runtime.Events.Store.CommittedEvent { var eventLog = streams.DefaultEventLog; var storedEvents = eventLog.FindSync(Builders <Event> .Filter.Empty).ToList(); switch (events) { case CommittedEvents committedEvents: should_have_stored_committed_events(event_content_converter, committedEvents, storedEvents); break; case CommittedAggregateEvents committedAggregateEvents: should_have_stored_committed_events(event_content_converter, committedAggregateEvents, storedEvents); break; default: throw new Exception("Wrong committed events type"); } }
/// <summary> /// Initializes a new instance of the <see cref="EventConverter"/> class. /// </summary> /// <param name="contentConverter">The <see cref="IEventContentConverter"/>.</param> public EventConverter(IEventContentConverter contentConverter) { _contentConverter = contentConverter; }