Exemplo n.º 1
0
        public void Returns_event_after_emitting()
        {
            var content = Fake.Strings.Random();
            var id      = EventId.New();
            var seq     = Sequence.First;
            var sut     = NewSut();

            var ev = sut.Emit(content, id, seq);

            ev.Id.Should().Be(id);
            ev.Content.Should().Be(content);
            ev.Sequence.Should().Be(seq);
            sut.Sequence.Should().Be(seq);
        }
Exemplo n.º 2
0
        private static UncommittedEventStream BuildFrom(VersionedEventSource version, DateTimeOffset committed, CorrelationId correlationId, IEnumerable <IEvent> events)
        {
            var envelopes            = new List <EventEnvelope>();
            VersionedEventSource vsn = null;

            events.ForEach(e =>
            {
                vsn = vsn == null ? version : new VersionedEventSource(vsn.Version.NextSequence(), vsn.EventSource, vsn.Artifact);
                envelopes.Add(e.ToEnvelope(BuildEventMetadata(EventId.New(), vsn, e.ToArtifact().Initial(), correlationId, committed)));
            });

            if (envelopes == null || !envelopes.Any())
            {
                throw new ApplicationException("There are no envelopes");
            }
            return(BuildStreamFrom(envelopes.ToEventStream()));
        }
Exemplo n.º 3
0
        static EventStream BuildEventStreamFrom(VersionedEventSource version, DateTimeOffset committed, CorrelationId correlationId, IEnumerable <IEvent> events)
        {
            var envelopes            = new List <EventEnvelope>();
            VersionedEventSource vsn = null;

            events.ForEach(e =>
            {
                vsn          = vsn == null ? version : new VersionedEventSource(vsn.Version.NextSequence(), new EventSourceKey(vsn.EventSource, vsn.Artifact));
                var envelope = e.ToEnvelope(BuildEventMetadata(EventId.New(), vsn, e is SimpleEvent ? Artifacts.artifact_for_simple_event : Artifacts.artifact_for_another_event, correlationId, DateTimeOffset.UtcNow));
                envelopes.Add(envelope);
            });

            if (envelopes?.Any() != true)
            {
                throw new ApplicationException("There are no envelopes");
            }
            return(EventStream.From(envelopes));
        }
        /// <summary>
        /// Injects an event
        /// </summary>
        public void InjectEvent(TenantId tenant, EventSourceId eventSourceId, IEvent @event)
        {
            _logger.Information($"Injecting event!");

            _executionContextManager.CurrentFor(tenant);
            var executionContext = _executionContextManager.Current;

            using (var eventStore = _getEventStore())
            {
                var artifact       = _artifactTypeMap.GetArtifactFor(@event.GetType());
                var eventSourceKey = new EventSourceKey(eventSourceId, artifact.Id);
                var version        = eventStore.GetNextVersionFor(eventSourceKey);

                var uncommittedEventStream = new UncommittedEventStream(
                    CommitId.New(),
                    executionContext.CorrelationId,
                    new VersionedEventSource(version, eventSourceKey),
                    DateTimeOffset.Now,
                    EventStream.From(new [] {
                    new EventEnvelope(
                        new EventMetadata(
                            EventId.New(),
                            new VersionedEventSource(version, eventSourceKey),
                            executionContext.CorrelationId,
                            artifact,
                            DateTimeOffset.Now,
                            executionContext
                            ),
                        @event.ToPropertyBag()
                        )
                })
                    );

                _logger.Information("Commit events to store");
                var committedEventStream = eventStore.Commit(uncommittedEventStream);

                _logger.Information("Process committed events");
                _processingHub.Process(committedEventStream);
            }
        }
 public AnotherSimpleEvent(string contents, int count)
     : this(EventId.New(), contents, count)
 {
 }
 public static EventEnvelope ToNewEnvelope(this EventEnvelope envelope, VersionedEventSource versionedEventSource, DateTimeOffset committed, CorrelationId correlationId)
 {
     return(new EventEnvelope(new EventMetadata(EventId.New(), versionedEventSource, correlationId, envelope.Metadata.Artifact, committed, envelope.Metadata.OriginalContext), envelope.Event));
 }
Exemplo n.º 7
0
 internal static Event Single(EventId?id = null, int sequenceSeed = 0)
 => Event.New(Strings.Random(), id ?? EventId.New(), sequenceSeed == 0 ? Sequence.First : Sequence.First.Add(sequenceSeed));
Exemplo n.º 8
0
        public static CommittedEvent build_committed_event(VersionedEventSource versionedEventSource, IEvent @event, CommittedEventVersion version)
        {
            var metadata = new EventMetadata(EventId.New(), versionedEventSource, CorrelationId.New(), new Artifact(ArtifactId.New(), 1), DateTime.UtcNow, GetOriginalContext());

            return(new CommittedEvent(version, metadata, @event));
        }
Exemplo n.º 9
0
 public void Generates_non_empty_guid_equivalents_by_default()
 {
     (EventId.New() != Guid.Empty).Should().BeTrue();
     (EventId.New() == Guid.Empty).Should().BeFalse();
     ((Guid)EventId.New()).Should().NotBeEmpty();
 }
        UncommittedEventStream BuildFrom(VersionedEventSource version, CorrelationId correlationId, DateTimeOffset committed, IEnumerable <VersionedEvent> events)
        {
            var envelopes = events.Select(e => e.Event.ToEnvelope(BuildEventMetadata(e.Event, EventId.New(), ToVersionedEventSource(e, version.EventSource, version.Artifact), correlationId, committed))).ToList();

            if (envelopes == null || !envelopes.Any())
            {
                throw new ApplicationException("There are no envelopes");
            }
            return(BuildStreamFrom(EventStream.From(envelopes)));
        }