diff --git a/CQRS.Tests/CQRS.Tests.csproj b/CQRS.Tests/CQRS.Tests.csproj index ba1bc3be4..84f1f53ea 100644 --- a/CQRS.Tests/CQRS.Tests.csproj +++ b/CQRS.Tests/CQRS.Tests.csproj @@ -12,7 +12,7 @@ - + diff --git a/Core.Api.Testing/ApiFixture.cs b/Core.Api.Testing/ApiFixture.cs index f1699127e..a258ae545 100644 --- a/Core.Api.Testing/ApiFixture.cs +++ b/Core.Api.Testing/ApiFixture.cs @@ -48,6 +48,7 @@ public virtual Task DisposeAsync() return Task.CompletedTask; } + // TODO: Add Poly here public async Task Get(string path = "", int maxNumberOfRetries = 0, int retryIntervalInMs = 1000, Func>? check = null) { diff --git a/Core.ElasticSearch/Indices/IndexNameMapper.cs b/Core.ElasticSearch/Indices/IndexNameMapper.cs index e3c586559..9bdfb0a22 100644 --- a/Core.ElasticSearch/Indices/IndexNameMapper.cs +++ b/Core.ElasticSearch/Indices/IndexNameMapper.cs @@ -18,7 +18,7 @@ public static void AddCustomMap(Type streamType, string mappedStreamName) public static string ToIndexPrefix() => ToIndexPrefix(typeof(TStream)); - public static string ToIndexPrefix(Type streamType) => Instance.typeNameMap.GetOrAdd(streamType, (_) => + public static string ToIndexPrefix(Type streamType) => Instance.typeNameMap.GetOrAdd(streamType, _ => { var modulePrefix = streamType.Namespace!.Split(".").First(); return $"{modulePrefix}-{streamType.Name}".ToLower(); diff --git a/Core.EventStoreDB/Subscriptions/EventStoreDBSubscriptionToAll.cs b/Core.EventStoreDB/Subscriptions/EventStoreDBSubscriptionToAll.cs index e4560a028..cf5d7f620 100644 --- a/Core.EventStoreDB/Subscriptions/EventStoreDBSubscriptionToAll.cs +++ b/Core.EventStoreDB/Subscriptions/EventStoreDBSubscriptionToAll.cs @@ -23,7 +23,7 @@ public class EventStoreDBSubscriptionToAllOptions public class EventStoreDBSubscriptionToAll { - private readonly INoMediatorEventBus noMediatorEventBus; + private readonly INoMediatorEventBus eventBus; private readonly EventStoreClient eventStoreClient; private readonly ISubscriptionCheckpointRepository checkpointRepository; private readonly ILogger logger; @@ -34,12 +34,12 @@ public class EventStoreDBSubscriptionToAll public EventStoreDBSubscriptionToAll( EventStoreClient eventStoreClient, - INoMediatorEventBus noMediatorEventBus, + INoMediatorEventBus eventBus, ISubscriptionCheckpointRepository checkpointRepository, ILogger logger ) { - this.noMediatorEventBus = noMediatorEventBus ?? throw new ArgumentNullException(nameof(noMediatorEventBus)); + this.eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); this.eventStoreClient = eventStoreClient ?? throw new ArgumentNullException(nameof(eventStoreClient)); this.checkpointRepository = checkpointRepository ?? throw new ArgumentNullException(nameof(checkpointRepository)); @@ -98,7 +98,7 @@ private async Task HandleEvent(StreamSubscription subscription, ResolvedEvent re } // publish event to internal event bus - await noMediatorEventBus.Publish(streamEvent, ct); + await eventBus.Publish(streamEvent, ct); await checkpointRepository.Store(SubscriptionId, resolvedEvent.Event.Position.CommitPosition, ct); } diff --git a/Core.Kafka/Producers/KafkaProducer.cs b/Core.Kafka/Producers/KafkaProducer.cs index 1409c21f0..66f0049f1 100644 --- a/Core.Kafka/Producers/KafkaProducer.cs +++ b/Core.Kafka/Producers/KafkaProducer.cs @@ -26,7 +26,7 @@ public async Task Publish(IExternalEvent @event, CancellationToken cancellationT using var p = new ProducerBuilder(config.ProducerConfig).Build(); await Task.Yield(); // publish event to kafka topic taken from config - var result = await p.ProduceAsync(config.Topic, + await p.ProduceAsync(config.Topic, new Message { // store event type name in message Key diff --git a/Core.Marten/Config.cs b/Core.Marten/Config.cs index 2499d1c5f..e6b925b90 100644 --- a/Core.Marten/Config.cs +++ b/Core.Marten/Config.cs @@ -1,9 +1,13 @@ +using Baseline.ImTools; +using Core.Events; using Core.Ids; using Core.Marten.Ids; using Core.Marten.OptimisticConcurrency; +using Core.Marten.Subscriptions; using Core.Threading; using Marten; using Marten.Events.Daemon.Resiliency; +using Marten.Events.Projections; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Weasel.Core; @@ -37,45 +41,21 @@ public static IServiceCollection AddMarten(this IServiceCollection services, ICo .AddScoped() .AddScoped() .AddScoped() - .AddScoped(); - - var documentStore = services - .AddMarten(options => - { - SetStoreOptions(options, martenConfig, configureOptions); - }) - .AddAsyncDaemon(DaemonMode.Solo) - .InitializeStore(); - - SetupSchema(documentStore, martenConfig, 1); + .AddScoped() + .AddMarten(sp => SetStoreOptions(sp, martenConfig, configureOptions)) + .ApplyAllDatabaseChangesOnStartup() + .AddAsyncDaemon(DaemonMode.Solo); return services; } - private static void SetupSchema(IDocumentStore documentStore, Config martenConfig, int retryLeft = 1) - { - try - { - if (martenConfig.ShouldRecreateDatabase) - documentStore.Advanced.Clean.CompletelyRemoveAll(); - - using (NoSynchronizationContextScope.Enter()) - { - documentStore.Schema.ApplyAllConfiguredChangesToDatabaseAsync().Wait(); - } - } - catch - { - if (retryLeft == 0) throw; - - Thread.Sleep(1000); - SetupSchema(documentStore, martenConfig, --retryLeft); - } - } - - private static void SetStoreOptions(StoreOptions options, Config config, - Action? configureOptions = null) + private static StoreOptions SetStoreOptions( + IServiceProvider serviceProvider, + Config config, + Action? configureOptions = null + ) { + var options = new StoreOptions(); options.Connection(config.ConnectionString); options.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate; @@ -88,6 +68,14 @@ private static void SetStoreOptions(StoreOptions options, Config config, nonPublicMembersStorage: NonPublicMembersStorage.All ); + options.Projections.Add( + new MartenSubscription(new[] { new MartenEventPublisher(serviceProvider) }), + ProjectionLifecycle.Async, + "MartenSubscription" + ); + configureOptions?.Invoke(options); + + return options; } } diff --git a/Core.Marten/Core.Marten.csproj b/Core.Marten/Core.Marten.csproj index 1bf3d9235..7923537a9 100644 --- a/Core.Marten/Core.Marten.csproj +++ b/Core.Marten/Core.Marten.csproj @@ -5,7 +5,7 @@ - + diff --git a/Core.Marten/Repository/MartenRepository.cs b/Core.Marten/Repository/MartenRepository.cs index 3bad03285..ccf2c2791 100644 --- a/Core.Marten/Repository/MartenRepository.cs +++ b/Core.Marten/Repository/MartenRepository.cs @@ -15,15 +15,12 @@ public interface IMartenRepository where T : class, IAggregate public class MartenRepository: IMartenRepository where T : class, IAggregate { private readonly IDocumentSession documentSession; - private readonly IEventBus eventBus; public MartenRepository( - IDocumentSession documentSession, - IEventBus eventBus + IDocumentSession documentSession ) { this.documentSession = documentSession; - this.eventBus = eventBus; } public Task Find(Guid id, CancellationToken cancellationToken) => @@ -39,7 +36,6 @@ public async Task Add(T aggregate, CancellationToken cancellationToken) ); await documentSession.SaveChangesAsync(cancellationToken); - await eventBus.Publish(events, cancellationToken); return events.Length; } @@ -59,7 +55,6 @@ public async Task Update(T aggregate, long? expectedVersion = null, Cancel ); await documentSession.SaveChangesAsync(cancellationToken); - await eventBus.Publish(events, cancellationToken); return nextVersion; } diff --git a/Core.Marten/Subscriptions/MartenEventPublisher.cs b/Core.Marten/Subscriptions/MartenEventPublisher.cs new file mode 100644 index 000000000..e21defbce --- /dev/null +++ b/Core.Marten/Subscriptions/MartenEventPublisher.cs @@ -0,0 +1,42 @@ +using Core.Events; +using Marten; +using Marten.Events; +using Microsoft.Extensions.DependencyInjection; +using IEvent = Core.Events.IEvent; + +namespace Core.Marten.Subscriptions; + +public class MartenEventPublisher: IMartenEventsConsumer +{ + private readonly IServiceProvider serviceProvider; + + public MartenEventPublisher( + IServiceProvider serviceProvider + ) + { + this.serviceProvider = serviceProvider; + } + + public async Task ConsumeAsync(IDocumentOperations documentOperations, IReadOnlyList streamActions, + CancellationToken ct) + { + foreach (var @event in streamActions.SelectMany(streamAction => streamAction.Events)) + { + // TODO: align all handlers to use StreamEvent + // var streamEvent = new StreamEvent( + // @event.Data, + // new EventMetadata( + // (ulong)@event.Version, + // (ulong)@event.Sequence + // ) + // ); + + using var scope = serviceProvider.CreateScope(); + var eventBus = scope.ServiceProvider.GetRequiredService(); + + if (@event.Data is not IEvent mappedEvent) continue; + + await eventBus.Publish(mappedEvent, ct); + } + } +} diff --git a/Core.Marten/Subscriptions/MartenSubscription.cs b/Core.Marten/Subscriptions/MartenSubscription.cs new file mode 100644 index 000000000..38f5d85e0 --- /dev/null +++ b/Core.Marten/Subscriptions/MartenSubscription.cs @@ -0,0 +1,43 @@ +using Marten; +using Marten.Events; +using Marten.Events.Projections; + +namespace Core.Marten.Subscriptions; + +public class MartenSubscription: IProjection +{ + private readonly IEnumerable consumers; + + public MartenSubscription(IEnumerable consumers) + { + this.consumers = consumers; + } + + public void Apply( + IDocumentOperations operations, + IReadOnlyList streams + ) => + throw new NotImplementedException("Subscriptions should work only in the async scope"); + + public async Task ApplyAsync( + IDocumentOperations operations, + IReadOnlyList streams, + CancellationToken ct + ) + { + foreach (var consumer in consumers) + { + await consumer.ConsumeAsync(operations, streams, ct); + } + } +} + + +public interface IMartenEventsConsumer +{ + Task ConsumeAsync( + IDocumentOperations documentOperations, + IReadOnlyList streamActions, + CancellationToken ct + ); +} diff --git a/Core.Testing/ApiFixture.cs b/Core.Testing/ApiFixture.cs index ecf9c6a5b..6a52c6f7e 100644 --- a/Core.Testing/ApiFixture.cs +++ b/Core.Testing/ApiFixture.cs @@ -1,8 +1,10 @@ +using System.Linq.Expressions; using Core.Api.Testing; using Core.Commands; using Core.Events; using Core.Events.External; using Core.Requests; +using FluentAssertions; using MediatR; using Microsoft.Extensions.DependencyInjection; using IEventBus = Core.Events.IEventBus; @@ -16,7 +18,7 @@ public abstract class ApiWithEventsFixture: ApiFixture where private readonly DummyExternalCommandBus externalCommandBus = new(); public override TestContext CreateTestContext() => - new TestContext(GetConfiguration, (services) => + new TestContext(GetConfiguration, services => { SetupServices?.Invoke(services); services.AddSingleton(eventsLog); @@ -46,10 +48,40 @@ public async Task PublishInternalEvent(IEvent @event, CancellationToken ct = def await eventBus.Publish(@event, ct); } - public IReadOnlyCollection PublishedInternalEventsOfType() + public IReadOnlyCollection PublishedInternalEventsOfType() => + eventsLog.PublishedEvents.OfType().ToList(); + + // TODO: Add Poly here + public async Task ShouldPublishInternalEventOfType( + Expression> predicate, + int maxNumberOfRetries = 5, + int retryIntervalInMs = 1000) { - return eventsLog.PublishedEvents.OfType().ToList(); + var retryCount = maxNumberOfRetries; + var finished = false; + + do + { + try + { + PublishedInternalEventsOfType().Should() + .HaveCount(1) + .And.Contain(predicate); + + finished = true; + } + catch + { + if (retryCount == 0) + throw; + } + + await Task.Delay(retryIntervalInMs); + retryCount--; + } while (!finished); } + + } public abstract class ApiWithEventsFixture: ApiFixture diff --git a/Core.Tests/Core.Tests.csproj b/Core.Tests/Core.Tests.csproj index e45a0f594..8f3ea6da2 100644 --- a/Core.Tests/Core.Tests.csproj +++ b/Core.Tests/Core.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/Core.WebApi/Tracing/Correlation/CorrelationIdMiddleware.cs b/Core.WebApi/Tracing/Correlation/CorrelationIdMiddleware.cs index d845107a3..13dbbb689 100644 --- a/Core.WebApi/Tracing/Correlation/CorrelationIdMiddleware.cs +++ b/Core.WebApi/Tracing/Correlation/CorrelationIdMiddleware.cs @@ -15,16 +15,14 @@ public class CorrelationIdMiddleware private readonly RequestDelegate next; private readonly ILogger logger; - private readonly Func correlationIdFactory; - public CorrelationIdMiddleware(RequestDelegate next, ILogger logger, Func correlationIdFactory) + public CorrelationIdMiddleware(RequestDelegate next, ILogger logger) { this.next = next ?? throw new ArgumentNullException(nameof(next)); this.logger = logger; - this.correlationIdFactory = correlationIdFactory; } - public async Task Invoke(HttpContext context) + public async Task Invoke(HttpContext context, Func correlationIdFactory) { // get correlation id from header or generate a new one context.TraceIdentifier = @@ -54,8 +52,8 @@ public static class CorrelationIdMiddlewareConfig { public static IServiceCollection AddCorrelationIdMiddleware(this IServiceCollection services) { - services.TryAddScoped(); services.TryAddScoped>(sp => sp.GetRequiredService().New); + services.TryAddScoped(); return services; } diff --git a/EventSourcing.Integration.Tests/EventSourcing.Integration.Tests.csproj b/EventSourcing.Integration.Tests/EventSourcing.Integration.Tests.csproj index 4b1161e5e..35e1a5525 100644 --- a/EventSourcing.Integration.Tests/EventSourcing.Integration.Tests.csproj +++ b/EventSourcing.Integration.Tests/EventSourcing.Integration.Tests.csproj @@ -12,7 +12,7 @@ - + diff --git a/Marten.Integration.Tests/Marten.Integration.Tests.csproj b/Marten.Integration.Tests/Marten.Integration.Tests.csproj index f26ab51f8..7259cea72 100644 --- a/Marten.Integration.Tests/Marten.Integration.Tests.csproj +++ b/Marten.Integration.Tests/Marten.Integration.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/MediatR.Tests/MediatR.Tests.csproj b/MediatR.Tests/MediatR.Tests.csproj index a12c752b4..b3865b6cf 100644 --- a/MediatR.Tests/MediatR.Tests.csproj +++ b/MediatR.Tests/MediatR.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/Sample/AsyncProjections/SmartHome.Temperature/MotionSensors/RebuildingMotionSensorsViews/RebuildMotionSensorsViews.cs b/Sample/AsyncProjections/SmartHome.Temperature/MotionSensors/RebuildingMotionSensorsViews/RebuildMotionSensorsViews.cs index f28e89f31..7ee0fba64 100644 --- a/Sample/AsyncProjections/SmartHome.Temperature/MotionSensors/RebuildingMotionSensorsViews/RebuildMotionSensorsViews.cs +++ b/Sample/AsyncProjections/SmartHome.Temperature/MotionSensors/RebuildingMotionSensorsViews/RebuildMotionSensorsViews.cs @@ -20,10 +20,8 @@ IDocumentSession session public async Task Handle(RebuildMotionSensorsViews command, CancellationToken cancellationToken) { - using (var daemon = session.DocumentStore.BuildProjectionDaemon()) - { - await daemon.RebuildProjection(cancellationToken); - } + using var daemon = await session.DocumentStore.BuildProjectionDaemonAsync(); + await daemon.RebuildProjection(cancellationToken); return Unit.Value; } } diff --git a/Sample/ECommerce/Carts/Carts.Api.Tests/Settings.cs b/Sample/ECommerce/Carts/Carts.Api.Tests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/ECommerce/Carts/Carts.Api.Tests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/ECommerce/Orders/Orders.Api.Tests/Orders/InitializingOrder/InitializeOrderTests.cs b/Sample/ECommerce/Orders/Orders.Api.Tests/Orders/InitializingOrder/InitializeOrderTests.cs index b165a9198..fcde2204b 100644 --- a/Sample/ECommerce/Orders/Orders.Api.Tests/Orders/InitializingOrder/InitializeOrderTests.cs +++ b/Sample/ECommerce/Orders/Orders.Api.Tests/Orders/InitializingOrder/InitializeOrderTests.cs @@ -16,8 +16,8 @@ public class InitializeOrderFixture: ApiWithEventsFixture public readonly List ProductItems = new() { - new PricedProductItemRequest {ProductId = Guid.NewGuid(), Quantity = 10, UnitPrice = 3}, - new PricedProductItemRequest {ProductId = Guid.NewGuid(), Quantity = 3, UnitPrice = 7} + new PricedProductItemRequest { ProductId = Guid.NewGuid(), Quantity = 10, UnitPrice = 3 }, + new PricedProductItemRequest { ProductId = Guid.NewGuid(), Quantity = 3, UnitPrice = 7 } }; public decimal TotalPrice => ProductItems.Sum(pi => pi.Quantity!.Value * pi.UnitPrice!.Value); @@ -64,18 +64,17 @@ public async Task InitializeOrder_ShouldPublish_OrderInitializedEvent() { var createdId = await fixture.CommandResponse.GetResultFromJson(); - fixture.PublishedInternalEventsOfType() - .Should() - .HaveCount(1) - .And.Contain(@event => + await fixture.ShouldPublishInternalEventOfType( + @event => @event.OrderId == createdId && @event.ClientId == fixture.ClientId && @event.InitializedAt > fixture.TimeBeforeSending && @event.ProductItems.Count == fixture.ProductItems.Count && @event.ProductItems.All( pi => fixture.ProductItems.Exists( - expi => expi.ProductId == pi.ProductId && expi.Quantity == pi.Quantity)) - ); + expi => expi.ProductId == pi.ProductId && expi.Quantity == pi.Quantity) + ) + ); } // [Fact] diff --git a/Sample/ECommerce/Orders/Orders.Api.Tests/Settings.cs b/Sample/ECommerce/Orders/Orders.Api.Tests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/ECommerce/Orders/Orders.Api.Tests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/ECommerce/Payments/Payments.Api.Tests/Payments/RequestingPayment/RequestPaymentsTests.cs b/Sample/ECommerce/Payments/Payments.Api.Tests/Payments/RequestingPayment/RequestPaymentsTests.cs index aa72d1718..d5612d86c 100644 --- a/Sample/ECommerce/Payments/Payments.Api.Tests/Payments/RequestingPayment/RequestPaymentsTests.cs +++ b/Sample/ECommerce/Payments/Payments.Api.Tests/Payments/RequestingPayment/RequestPaymentsTests.cs @@ -54,10 +54,8 @@ public async Task RequestPayment_ShouldPublish_PaymentInitializedEvent() { var createdId = await fixture.CommandResponse.GetResultFromJson(); - fixture.PublishedInternalEventsOfType() - .Should() - .HaveCount(1) - .And.Contain(@event => + await fixture.ShouldPublishInternalEventOfType( + @event => @event.PaymentId == createdId && @event.OrderId == fixture.OrderId && @event.Amount == fixture.Amount diff --git a/Sample/ECommerce/Payments/Payments.Api.Tests/Settings.cs b/Sample/ECommerce/Payments/Payments.Api.Tests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/ECommerce/Payments/Payments.Api.Tests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/ECommerce/Shipments/Shipments.Api.Tests/Packages/SendPackageTests.cs b/Sample/ECommerce/Shipments/Shipments.Api.Tests/Packages/SendPackageTests.cs index 05581079e..3b24d24ab 100644 --- a/Sample/ECommerce/Shipments/Shipments.Api.Tests/Packages/SendPackageTests.cs +++ b/Sample/ECommerce/Shipments/Shipments.Api.Tests/Packages/SendPackageTests.cs @@ -20,16 +20,8 @@ public class SendPackageFixture: ApiWithEventsFixture public readonly List ProductItems = new() { - new ProductItem - { - ProductId = Guid.NewGuid(), - Quantity = 10 - }, - new ProductItem - { - ProductId = Guid.NewGuid(), - Quantity = 3 - } + new ProductItem { ProductId = Guid.NewGuid(), Quantity = 10 }, + new ProductItem { ProductId = Guid.NewGuid(), Quantity = 3 } }; public HttpResponseMessage CommandResponse = default!; @@ -67,10 +59,8 @@ public async Task SendPackage_ShouldPublish_PackageWasSentEvent() { var createdId = await fixture.CommandResponse.GetResultFromJson(); - fixture.PublishedInternalEventsOfType() - .Should() - .HaveCount(1) - .And.Contain(@event => + await fixture.ShouldPublishInternalEventOfType( + @event => @event.PackageId == createdId && @event.OrderId == fixture.OrderId && @event.SentAt > fixture.TimeBeforeSending @@ -78,7 +68,7 @@ public async Task SendPackage_ShouldPublish_PackageWasSentEvent() && @event.ProductItems.All( pi => fixture.ProductItems.Exists( expi => expi.ProductId == pi.ProductId && expi.Quantity == pi.Quantity)) - ); + ); } [Fact] diff --git a/Sample/ECommerce/Shipments/Shipments.Api.Tests/Settings.cs b/Sample/ECommerce/Shipments/Shipments.Api.Tests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/ECommerce/Shipments/Shipments.Api.Tests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/EventStoreDB/ECommerce/Carts/Carts.Api.Tests/Settings.cs b/Sample/EventStoreDB/ECommerce/Carts/Carts.Api.Tests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/EventStoreDB/ECommerce/Carts/Carts.Api.Tests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/MeetingsManagement/MeetingsManagement.Api/MeetingsManagement.Api.csproj b/Sample/MeetingsManagement/MeetingsManagement.Api/MeetingsManagement.Api.csproj index 916b1c97e..b336fa256 100644 --- a/Sample/MeetingsManagement/MeetingsManagement.Api/MeetingsManagement.Api.csproj +++ b/Sample/MeetingsManagement/MeetingsManagement.Api/MeetingsManagement.Api.csproj @@ -5,7 +5,7 @@ - + diff --git a/Sample/MeetingsManagement/MeetingsManagement.Api/Startup.cs b/Sample/MeetingsManagement/MeetingsManagement.Api/Startup.cs index 4ca7048d4..d0784c382 100644 --- a/Sample/MeetingsManagement/MeetingsManagement.Api/Startup.cs +++ b/Sample/MeetingsManagement/MeetingsManagement.Api/Startup.cs @@ -35,8 +35,8 @@ public void ConfigureServices(IServiceCollection services) c.SwaggerDoc("v1", new OpenApiInfo { Title = "Meeting Management", Version = "v1" }); c.OperationFilter(); }) - .AddCoreServices() .AddKafkaProducerAndConsumer() + .AddCoreServices() .AddMeetingsManagement(config) .AddCorrelationIdMiddleware() .AddOptimisticConcurrencyMiddleware( diff --git a/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Meetings/CreatingMeeting/CreateMeetingTests.cs b/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Meetings/CreatingMeeting/CreateMeetingTests.cs index ceca75d7f..80abe182b 100644 --- a/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Meetings/CreatingMeeting/CreateMeetingTests.cs +++ b/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Meetings/CreatingMeeting/CreateMeetingTests.cs @@ -58,8 +58,8 @@ public async Task CreateCommand_ShouldReturn_CreatedStatus_With_MeetingId() public void CreateCommand_ShouldPublish_MeetingCreateEvent() { // assert MeetingCreated event was produced to external bus - fixture.PublishedExternalEventsOfType() - .Should().Contain(@event => + fixture.ShouldPublishInternalEventOfType( + @event => @event.MeetingId == fixture.MeetingId && @event.Name == fixture.MeetingName ); diff --git a/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/MeetingsManagement.IntegrationTests.csproj b/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/MeetingsManagement.IntegrationTests.csproj index 122c49a1a..7d2f8ae67 100644 --- a/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/MeetingsManagement.IntegrationTests.csproj +++ b/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/MeetingsManagement.IntegrationTests.csproj @@ -13,7 +13,7 @@ - + diff --git a/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Settings.cs b/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/MeetingsManagement/MeetingsManagement.IntegrationTests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/MeetingsManagement/MeetingsManagement/MeetingsManagement.csproj b/Sample/MeetingsManagement/MeetingsManagement/MeetingsManagement.csproj index 09a22b93a..ce34c4d29 100644 --- a/Sample/MeetingsManagement/MeetingsManagement/MeetingsManagement.csproj +++ b/Sample/MeetingsManagement/MeetingsManagement/MeetingsManagement.csproj @@ -6,7 +6,7 @@ - + diff --git a/Sample/MeetingsManagement/MeetingsSearch.Api/Startup.cs b/Sample/MeetingsManagement/MeetingsSearch.Api/Startup.cs index 80cd02ab4..70efb510c 100644 --- a/Sample/MeetingsManagement/MeetingsSearch.Api/Startup.cs +++ b/Sample/MeetingsManagement/MeetingsSearch.Api/Startup.cs @@ -28,8 +28,9 @@ public void ConfigureServices(IServiceCollection services) c.OperationFilter(); }); - services.AddCoreServices() + services .AddKafkaConsumer() + .AddCoreServices() .AddMeetingsSearch(config) .AddCorrelationIdMiddleware(); } diff --git a/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/MeetingsSearch.IntegrationTests.csproj b/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/MeetingsSearch.IntegrationTests.csproj index 9163b3eae..41e537555 100644 --- a/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/MeetingsSearch.IntegrationTests.csproj +++ b/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/MeetingsSearch.IntegrationTests.csproj @@ -13,7 +13,7 @@ - + diff --git a/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/Settings.cs b/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/MeetingsManagement/MeetingsSearch.IntegrationTests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/Tickets/Tickets.Api.Tests/Reservations/CreatingTentativeReservation/CreateTentativeReservationTests.cs b/Sample/Tickets/Tickets.Api.Tests/Reservations/CreatingTentativeReservation/CreateTentativeReservationTests.cs index bf0ecaa70..1df4365b9 100644 --- a/Sample/Tickets/Tickets.Api.Tests/Reservations/CreatingTentativeReservation/CreateTentativeReservationTests.cs +++ b/Sample/Tickets/Tickets.Api.Tests/Reservations/CreatingTentativeReservation/CreateTentativeReservationTests.cs @@ -28,7 +28,7 @@ protected override Dictionary GetConfiguration(string fixtureNam public override async Task InitializeAsync() { // send create command - CommandResponse = await Post(new CreateTentativeReservationRequest {SeatId = SeatId}); + CommandResponse = await Post(new CreateTentativeReservationRequest { SeatId = SeatId }); } } @@ -60,14 +60,12 @@ public async Task CreateCommand_ShouldPublish_TentativeReservationCreated() { var createdReservationId = await fixture.CommandResponse.GetResultFromJson(); - fixture.PublishedInternalEventsOfType() - .Should() - .HaveCount(1) - .And.Contain(@event => + await fixture.ShouldPublishInternalEventOfType( + @event => @event.ReservationId == createdReservationId && @event.SeatId == fixture.SeatId && !string.IsNullOrEmpty(@event.Number) - ); + ); } [Fact] @@ -83,7 +81,7 @@ public async Task CreateCommand_ShouldCreate_ReservationDetailsReadModel() var queryResponse = await fixture.Get(query); queryResponse.EnsureSuccessStatusCode(); - var reservationDetails = await queryResponse.GetResultFromJson(); + var reservationDetails = await queryResponse.GetResultFromJson(); reservationDetails.Id.Should().Be(createdReservationId); reservationDetails.Number.Should().NotBeNull().And.NotBeEmpty(); reservationDetails.Status.Should().Be(ReservationStatus.Tentative); diff --git a/Sample/Tickets/Tickets.Api.Tests/Settings.cs b/Sample/Tickets/Tickets.Api.Tests/Settings.cs new file mode 100644 index 000000000..217120083 --- /dev/null +++ b/Sample/Tickets/Tickets.Api.Tests/Settings.cs @@ -0,0 +1,3 @@ +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] diff --git a/Sample/Tickets/Tickets.Tests/Tickets.Tests.csproj b/Sample/Tickets/Tickets.Tests/Tickets.Tests.csproj index 7a65bfc26..3a5ad0c9d 100644 --- a/Sample/Tickets/Tickets.Tests/Tickets.Tests.csproj +++ b/Sample/Tickets/Tickets.Tests/Tickets.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Sample/Tickets/Tickets/Maintenance/MaintenanceCommandHandler.cs b/Sample/Tickets/Tickets/Maintenance/MaintenanceCommandHandler.cs index f0c859186..5b0afaff6 100644 --- a/Sample/Tickets/Tickets/Maintenance/MaintenanceCommandHandler.cs +++ b/Sample/Tickets/Tickets/Maintenance/MaintenanceCommandHandler.cs @@ -17,9 +17,9 @@ public MaintenanceCommandHandler(IDocumentStore documentStore) public async Task Handle(RebuildProjection command, CancellationToken cancellationToken) { - using var daemon = documentStore.BuildProjectionDaemon(); + using var daemon = await documentStore.BuildProjectionDaemonAsync(); await daemon.RebuildProjection(command.ViewName, cancellationToken); return Unit.Value; } -} \ No newline at end of file +} diff --git a/Workshops/BuildYourOwnEventStore/01-CreateStreamsTable/01-CreateStreamsTable.csproj b/Workshops/BuildYourOwnEventStore/01-CreateStreamsTable/01-CreateStreamsTable.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/01-CreateStreamsTable/01-CreateStreamsTable.csproj +++ b/Workshops/BuildYourOwnEventStore/01-CreateStreamsTable/01-CreateStreamsTable.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/02-CreateEventsTable/02-CreateEventsTable.csproj b/Workshops/BuildYourOwnEventStore/02-CreateEventsTable/02-CreateEventsTable.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/02-CreateEventsTable/02-CreateEventsTable.csproj +++ b/Workshops/BuildYourOwnEventStore/02-CreateEventsTable/02-CreateEventsTable.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/03-CreateAppendEventFunction/03-CreateAppendEventFunction.csproj b/Workshops/BuildYourOwnEventStore/03-CreateAppendEventFunction/03-CreateAppendEventFunction.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/03-CreateAppendEventFunction/03-CreateAppendEventFunction.csproj +++ b/Workshops/BuildYourOwnEventStore/03-CreateAppendEventFunction/03-CreateAppendEventFunction.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/03-OptimisticConcurrency/03-OptimisticConcurrency.csproj b/Workshops/BuildYourOwnEventStore/03-OptimisticConcurrency/03-OptimisticConcurrency.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/03-OptimisticConcurrency/03-OptimisticConcurrency.csproj +++ b/Workshops/BuildYourOwnEventStore/03-OptimisticConcurrency/03-OptimisticConcurrency.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/04-EventStoreMethods/04-EventStoreMethods.csproj b/Workshops/BuildYourOwnEventStore/04-EventStoreMethods/04-EventStoreMethods.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/04-EventStoreMethods/04-EventStoreMethods.csproj +++ b/Workshops/BuildYourOwnEventStore/04-EventStoreMethods/04-EventStoreMethods.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/05-StreamAggregation/05-StreamAggregation.csproj b/Workshops/BuildYourOwnEventStore/05-StreamAggregation/05-StreamAggregation.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/05-StreamAggregation/05-StreamAggregation.csproj +++ b/Workshops/BuildYourOwnEventStore/05-StreamAggregation/05-StreamAggregation.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/06-TimeTraveling/06-TimeTraveling.csproj b/Workshops/BuildYourOwnEventStore/06-TimeTraveling/06-TimeTraveling.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/06-TimeTraveling/06-TimeTraveling.csproj +++ b/Workshops/BuildYourOwnEventStore/06-TimeTraveling/06-TimeTraveling.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/07-AggregateAndRepository/07-AggregateAndRepository.csproj b/Workshops/BuildYourOwnEventStore/07-AggregateAndRepository/07-AggregateAndRepository.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/07-AggregateAndRepository/07-AggregateAndRepository.csproj +++ b/Workshops/BuildYourOwnEventStore/07-AggregateAndRepository/07-AggregateAndRepository.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/08-Snapshots/08-Snapshots.csproj b/Workshops/BuildYourOwnEventStore/08-Snapshots/08-Snapshots.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/08-Snapshots/08-Snapshots.csproj +++ b/Workshops/BuildYourOwnEventStore/08-Snapshots/08-Snapshots.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/09-Projections/09-Projections.csproj b/Workshops/BuildYourOwnEventStore/09-Projections/09-Projections.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/09-Projections/09-Projections.csproj +++ b/Workshops/BuildYourOwnEventStore/09-Projections/09-Projections.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/10-ProjectionsWithMarten/10-ProjectionsWithMarten.csproj b/Workshops/BuildYourOwnEventStore/10-ProjectionsWithMarten/10-ProjectionsWithMarten.csproj index 11050d45e..67aa87a8b 100644 --- a/Workshops/BuildYourOwnEventStore/10-ProjectionsWithMarten/10-ProjectionsWithMarten.csproj +++ b/Workshops/BuildYourOwnEventStore/10-ProjectionsWithMarten/10-ProjectionsWithMarten.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/EventStoreBasics.Tests/EventStoreBasics.Tests.csproj b/Workshops/BuildYourOwnEventStore/EventStoreBasics.Tests/EventStoreBasics.Tests.csproj index d1d3e5d44..76f012947 100644 --- a/Workshops/BuildYourOwnEventStore/EventStoreBasics.Tests/EventStoreBasics.Tests.csproj +++ b/Workshops/BuildYourOwnEventStore/EventStoreBasics.Tests/EventStoreBasics.Tests.csproj @@ -6,7 +6,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/EventStoreBasics/EventStoreBasics.csproj b/Workshops/BuildYourOwnEventStore/EventStoreBasics/EventStoreBasics.csproj index 533a28996..fb4e5cc5f 100644 --- a/Workshops/BuildYourOwnEventStore/EventStoreBasics/EventStoreBasics.csproj +++ b/Workshops/BuildYourOwnEventStore/EventStoreBasics/EventStoreBasics.csproj @@ -7,7 +7,7 @@ - + diff --git a/Workshops/BuildYourOwnEventStore/Tools/Tools.csproj b/Workshops/BuildYourOwnEventStore/Tools/Tools.csproj index 058207321..2a69201e6 100644 --- a/Workshops/BuildYourOwnEventStore/Tools/Tools.csproj +++ b/Workshops/BuildYourOwnEventStore/Tools/Tools.csproj @@ -8,7 +8,7 @@ - +