diff --git a/assets/microservices.drawio b/assets/microservices.drawio
new file mode 100644
index 0000000..5a0fae2
--- /dev/null
+++ b/assets/microservices.drawio
@@ -0,0 +1 @@
+7V1Ze6JIFP01PupXC+tjTGKSnp6Z9JieZOYlH0qpTBAMoIn966fYBUqMSgkx+JDIpaqs5XDvubcWOvhy/n7jaIvZ77ZOzA4C+nsHX3UQEgSg0n++ZB1KEEBSKJk6hh7KYCoYGr9IJASRdGnoxM0k9Gzb9IxFVji2LYuMvYxMcxz7LZtsYpvZX11oU1IQDMeaWZQ+Gro3C6UKklP5LTGms/iXoRS1eK7FiaOWuDNNt982RPi6gy8d2/bCb/P3S2L6vRf3y+Pd+tH8/iLdfPvhvmo/+789/PF3NyxssE+WpAkOsbyDi374Mb990nToPvywFo//yHfKU78Lo8F0vXXcYUSn/Rdd2o43s6e2pZnXqbQ/Xjor4pcK6YVjLy09uAL0yn0h3ngWXaS5v9v2Ikr/H/G8dQQTbenZVDTz5mZ0N+ljP//EtrxL27SdoGJ4MMD0Q+XEinEGg9/0HPuFbCSU6GcwSO7Ewx4kJuYoKH9FHM+gKKGiD/ZuNAquvXTGUVe9P/z587/+ejS++Pb2qIBb9NMgXSFM53fjBgKjMbkh9px4zpomcIipecYqC1MtQvs0SZdkvbcNWj8EokcTYhDhch0/cCBbhqc5U+JF2VJg0C8b9UhFAVz2gY7cQocPdMKBK0kXq6jqMJYBx95IUJqFBDoYzvrJz98TBDkW/BMIAMCx4Oo9+onwar15dU8cg3YOceIqfR1wiahR4Eqsb/PAJWIxA64WWKXAgmJdwCqr9kozl9EvdZBketEwZBAnvS7t+EbXDUbigiZQweI9vUm/Tf3/F/d39N6N5pE3bR0XSWsYlhqmKUBacxch+Z0Y7z5UNxG38C140Hqx3xGvqEQzjalFBWM6gD6S+sY8YMFBBSOkIDGVXxnzKa2BaYzoX+3X0iF+302JRRwKCDToG7+eHzTzpeeuplEpA21umD5yb4m5Ij5ycvjUyURbBm3LwtGyraAmhmluIBSA/vUA7Y09H7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DLmSXxzB+b2mMZw+iK/oQc0wxBMirezVfy3SGo401irIFmkt0vZAGr1M30AeJk9f5I6v/wc=
\ No newline at end of file
diff --git a/src/BuildingBlocks/BuildingBlocks.csproj b/src/BuildingBlocks/BuildingBlocks.csproj
index 6c4d765..542d6b7 100644
--- a/src/BuildingBlocks/BuildingBlocks.csproj
+++ b/src/BuildingBlocks/BuildingBlocks.csproj
@@ -25,6 +25,7 @@
+
diff --git a/src/BuildingBlocks/MessageProcessor/Extensions.cs b/src/BuildingBlocks/MessageProcessor/Extensions.cs
index d7329ae..f2c8fab 100644
--- a/src/BuildingBlocks/MessageProcessor/Extensions.cs
+++ b/src/BuildingBlocks/MessageProcessor/Extensions.cs
@@ -1,4 +1,5 @@
using BuildingBlocks.Core;
+using BuildingBlocks.Mongo;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
diff --git a/src/BuildingBlocks/Mongo/MongoDbContext.cs b/src/BuildingBlocks/Mongo/MongoDbContext.cs
index 1c59a41..4ef4e5b 100644
--- a/src/BuildingBlocks/Mongo/MongoDbContext.cs
+++ b/src/BuildingBlocks/Mongo/MongoDbContext.cs
@@ -1,3 +1,4 @@
+using Microsoft.Extensions.Options;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Driver;
@@ -13,12 +14,12 @@ public class MongoDbContext : IMongoDbContext
public IMongoClient MongoClient { get; }
protected readonly IList> _commands;
- public MongoDbContext(MongoOptions options)
+ public MongoDbContext(IOptions options)
{
RegisterConventions();
- MongoClient = new MongoClient(options.ConnectionString);
- var databaseName = options.DatabaseName;
+ MongoClient = new MongoClient(options.Value.ConnectionString);
+ var databaseName = options.Value.DatabaseName;
Database = MongoClient.GetDatabase(databaseName);
// Every command will be stored and it'll be processed at SaveChanges
diff --git a/src/Services/Booking/src/Booking/Data/BookingDbContext.cs b/src/Services/Booking/src/Booking/Data/BookingDbContext.cs
index 9a1c9b9..14b59b9 100644
--- a/src/Services/Booking/src/Booking/Data/BookingDbContext.cs
+++ b/src/Services/Booking/src/Booking/Data/BookingDbContext.cs
@@ -9,7 +9,7 @@ public class BookingDbContext : AppDbContextBase
{
public const string DefaultSchema = "dbo";
- public BookingDbContext(DbContextOptions options, IHttpContextAccessor httpContextAccessor) : base(options, httpContextAccessor)
+ public BookingDbContext(DbContextOptions options, IHttpContextAccessor httpContextAccessor) : base(options, httpContextAccessor)
{
}
diff --git a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs
index 0c16d0b..89f3213 100644
--- a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs
+++ b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs
@@ -24,13 +24,6 @@ public class CreateBookingTests
public CreateBookingTests(IntegrationTestFixture fixture)
{
_fixture = fixture;
-
- _fixture.RegisterTestServices(services =>
- {
- MockFlightGrpcServices(services);
- MockPassengerGrpcServices(services);
- });
-
_testHarness = fixture.TestHarness;
_channel = fixture.Channel;
}
@@ -48,36 +41,4 @@ public class CreateBookingTests
// Assert
response.Should().BeGreaterOrEqualTo(0);
}
-
- private void MockPassengerGrpcServices(IServiceCollection services)
- {
- services.Replace(ServiceDescriptor.Singleton(x =>
- {
- var mock = Substitute.For();
- mock.GetById(Arg.Any())
- .Returns(new UnaryResult(new FakePassengerResponseDto().Generate()));
-
- return mock;
- }));
- }
-
- private void MockFlightGrpcServices(IServiceCollection services)
- {
- services.Replace(ServiceDescriptor.Singleton(x =>
- {
- var mock = Substitute.For();
-
- mock.GetById(Arg.Any())
- .Returns(new UnaryResult(Task.FromResult(new FakeFlightResponseDto().Generate())));
-
- mock.GetAvailableSeats(Arg.Any())
- .Returns(
- new UnaryResult>(Task.FromResult(FakeSeatsResponseDto.Generate())));
-
- mock.ReserveSeat(new FakeReserveSeatRequestDto().Generate())
- .Returns(new UnaryResult(Task.FromResult(FakeSeatsResponseDto.Generate().First())));
-
- return mock;
- }));
- }
}
diff --git a/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs b/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs
index b1e8679..4669d52 100644
--- a/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs
+++ b/src/Services/Booking/tests/IntegrationTest/IntegrationTestFixture.cs
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Booking.Data;
using BuildingBlocks.Core.Model;
using BuildingBlocks.MassTransit;
+using BuildingBlocks.Mongo;
using BuildingBlocks.Web;
using Grpc.Net.Client;
using MassTransit;
@@ -16,6 +17,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Options;
+using Mongo2Go;
using NSubstitute;
using Respawn;
using Serilog;
@@ -33,6 +36,8 @@ public class IntegrationTestFixture : IAsyncLifetime
{
private WebApplicationFactory _factory;
public Checkpoint Checkpoint { get; set; }
+
+ private MongoDbRunner _mongoRunner;
public Action? TestRegistrationServices { get; set; }
public IServiceProvider ServiceProvider => _factory.Services;
public IConfiguration Configuration => _factory.Services.GetRequiredService();
@@ -67,11 +72,13 @@ public class IntegrationTestFixture : IAsyncLifetime
});
Checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
-
- TestRegistrationServices?.Invoke(services);
});
});
+ // _mongoRunner = MongoDbRunner.Start();
+ // var mongoOptions = _factory.Services.GetRequiredService>();
+ // if (mongoOptions is not null)
+ // mongoOptions.Value.ConnectionString = _mongoRunner.ConnectionString;
return Task.CompletedTask;
}
diff --git a/src/Services/Flight/src/Flight/Data/FlightReadDbContext.cs b/src/Services/Flight/src/Flight/Data/FlightReadDbContext.cs
index 951394d..1b18e7b 100644
--- a/src/Services/Flight/src/Flight/Data/FlightReadDbContext.cs
+++ b/src/Services/Flight/src/Flight/Data/FlightReadDbContext.cs
@@ -8,7 +8,7 @@ namespace Flight.Data;
public class FlightReadDbContext : MongoDbContext
{
- public FlightReadDbContext(IOptions options) : base(options.Value)
+ public FlightReadDbContext(IOptions options) : base(options)
{
Flight = GetCollection(nameof(Flight).Underscore());
}
diff --git a/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs b/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs
index 5010761..1b528a2 100644
--- a/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs
+++ b/src/Services/Flight/tests/IntegrationTest/IntegrationTestFixture.cs
@@ -5,7 +5,9 @@ using BuildingBlocks.Core.Model;
using BuildingBlocks.EFCore;
using BuildingBlocks.MassTransit;
using BuildingBlocks.MessageProcessor;
+using BuildingBlocks.Mongo;
using BuildingBlocks.Web;
+using DotNetCore.CAP.MongoDB;
using Flight.Data;
using FluentAssertions.Common;
using Grpc.Net.Client;
@@ -20,6 +22,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Options;
+using Mongo2Go;
using NSubstitute;
using Respawn;
using Serilog;
@@ -36,6 +40,8 @@ public class FixtureCollection : ICollectionFixture
public class IntegrationTestFixture : IAsyncLifetime
{
private WebApplicationFactory _factory;
+
+ private MongoDbRunner _mongoRunner;
public Checkpoint Checkpoint { get; set; }
public Action? TestRegistrationServices { get; set; }
public IServiceProvider ServiceProvider => _factory.Services;
@@ -67,7 +73,6 @@ public class IntegrationTestFixture : IAsyncLifetime
builder.UseEnvironment("test");
builder.ConfigureServices(services =>
{
- TestRegistrationServices?.Invoke(services);
services.AddMassTransitTestHarness(x =>
{
x.UsingRabbitMq((context, cfg) =>
@@ -85,11 +90,13 @@ public class IntegrationTestFixture : IAsyncLifetime
});
Checkpoint = new Checkpoint {TablesToIgnore = new[] {"__EFMigrationsHistory"}};
-
- TestRegistrationServices?.Invoke(services);
});
});
+ _mongoRunner = MongoDbRunner.Start();
+ var mongoOptions = _factory.Services.GetRequiredService>();
+ mongoOptions.Value.ConnectionString = _mongoRunner.ConnectionString;
+
return Task.CompletedTask;
}
@@ -99,6 +106,7 @@ public class IntegrationTestFixture : IAsyncLifetime
await Checkpoint.Reset(Configuration?.GetConnectionString("DefaultConnection"));
await _factory.DisposeAsync();
+ _mongoRunner.Dispose();
}
public async Task ExecuteScopeAsync(Func action)