private async Task PublishEventsAsync() { if (publishedEvents.Count > 0) { if (EventBuffer == null) { throw new InvalidOperationException($"Cannot publish events from {this} because its {nameof(EventBuffer)} has not been set"); } if (EventMessageFactory == null) { throw new InvalidOperationException($"Cannot publish events from {this} because its {nameof(EventMessageFactory)} has not been set"); } } foreach (var ev in publishedEvents) { var eventMessage = await EventMessageFactory.CreateMessageAsync(ev); if (eventMessage.Metadata.GetEventId() == null) { eventMessage.SetMetadata(BasicEventMetadataNames.EventId, Guid.NewGuid().ToString()); } EventBuffer.PushEvent(eventMessage); } }
public async Task CreateMessageAsync_CreatesCorrectMessageType() { IEvent @event = new Event1(); IEventMessageDraft message = await sut.CreateMessageAsync(@event); message.Should().BeOfType <EventMessageDraft <Event1> >(); message.Event.Should().Be(@event); }