/// <summary>
        /// Converts the <see cref="CommittedAggregateEvents" /> to <see cref="Contracts.CommittedAggregateEvents" />s.
        /// </summary>
        /// <param name="committedAggregateEvents">The committed events.</param>
        /// <returns>The converted <see cref="Contracts.CommittedAggregateEvents" />.</returns>
        public static Contracts.CommittedAggregateEvents ToProtobuf(this CommittedAggregateEvents committedAggregateEvents)
        {
            var protobuf = new Contracts.CommittedAggregateEvents
            {
                AggregateRootId      = committedAggregateEvents.AggregateRoot.Value.ToProtobuf(),
                EventSourceId        = committedAggregateEvents.EventSource.ToProtobuf(),
                AggregateRootVersion = committedAggregateEvents.AsEnumerable().LastOrDefault()?.AggregateRootVersion
            };

            protobuf.Events.AddRange(committedAggregateEvents.Select(_ => _.ToProtobuf()));
            return(protobuf);
        }
示例#2
0
    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);
        }
    }