From c2a4c0e147598deb5ae2cfe1e6193b7ef17ac76d Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Fri, 11 Jun 2021 23:17:03 +0300 Subject: [PATCH] Rename IMongoDbSettings to IDatabaseSettings and move related files from Settings to Database directory. --- .../Controllers/TestFeedbackReceiver.cs | 4 ++-- .../Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs | 6 +++--- .../Services/TestFeedbackReceiverService.cs | 12 ++++++------ .../Services/TestTokensService.cs | 6 +++--- .../DatabaseSettings.cs} | 8 ++++++-- .../IDatabaseSettings.cs} | 6 +++--- .../Services/FeedbackReceiverService.cs | 4 ++-- Retroactiune.WebAPI/Services/TokensService.cs | 4 ++-- Retroactiune.WebAPI/Startup.cs | 10 +++++----- Retroactiune.WebAPI/TestingStartup.cs | 10 +++++----- Retroactiune.WebAPI/appsettings.Testing.json | 2 +- Retroactiune.WebAPI/appsettings.json | 2 +- 12 files changed, 39 insertions(+), 35 deletions(-) rename Retroactiune.WebAPI/{Settings/RetroactiuneDbSettings.cs => Database/DatabaseSettings.cs} (50%) rename Retroactiune.WebAPI/{Settings/IMongoDbSettings.cs => Database/IDatabaseSettings.cs} (69%) diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs index 32e99c5..6c25987 100644 --- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs +++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs @@ -14,10 +14,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Driver; +using Retroactiune.Database; using Retroactiune.DataTransferObjects; using Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures; using Retroactiune.Models; -using Retroactiune.Settings; using Xunit; namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers @@ -30,7 +30,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers public TestFeedbackReceiver(WebApiTestingFactory factory) { _client = factory.CreateClient(); - var dbSettings = factory.Services.GetService>(); + var dbSettings = factory.Services.GetService>(); _mongoDb = new MongoDbFixture(dbSettings); } diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs index e751883..e39f2f5 100644 --- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs +++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs @@ -3,20 +3,20 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Options; using MongoDB.Driver; +using Retroactiune.Database; using Retroactiune.Models; -using Retroactiune.Settings; namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures { public class MongoDbFixture : IAsyncDisposable { - private readonly IMongoDbSettings _settings; + private readonly IDatabaseSettings _settings; public IMongoDatabase Database { get; } public IMongoCollection FeedbackReceiverCollection => Database.GetCollection(_settings.FeedbackReceiverCollectionName); - public MongoDbFixture(IOptions options) + public MongoDbFixture(IOptions options) { _settings = options.Value; var client = new MongoClient(_settings.ConnectionString); diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs index d0a8b12..9825c16 100644 --- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestFeedbackReceiverService.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using AutoFixture.Xunit2; using MongoDB.Driver; using Moq; +using Retroactiune.Database; using Retroactiune.Models; using Retroactiune.Services; -using Retroactiune.Settings; using Xunit; namespace Retroactiune.Tests.Retroactiune.WebAPI.Services @@ -20,7 +20,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Arrange var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB"); @@ -55,7 +55,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Arrange var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB"); @@ -96,7 +96,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Arrange var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB"); @@ -137,7 +137,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Arrange var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB"); @@ -172,7 +172,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Arrange var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); var mongoCursorMock = new Mock>(); diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestTokensService.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestTokensService.cs index 2c736e3..a73b93c 100644 --- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestTokensService.cs +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Services/TestTokensService.cs @@ -3,9 +3,9 @@ using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using Moq; +using Retroactiune.Database; using Retroactiune.Models; using Retroactiune.Services; -using Retroactiune.Settings; using Xunit; namespace Retroactiune.Tests.Retroactiune.WebAPI.Services @@ -18,7 +18,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Setup var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB"); @@ -45,7 +45,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Services // Setup var mongoDatabaseMock = new Mock(); var mongoClientMock = new Mock(); - var mongoSettingsMock = new Mock(); + var mongoSettingsMock = new Mock(); var mongoCollectionMock = new Mock>(); mongoSettingsMock.SetupGet(i => i.DatabaseName).Returns("MyDB"); diff --git a/Retroactiune.WebAPI/Settings/RetroactiuneDbSettings.cs b/Retroactiune.WebAPI/Database/DatabaseSettings.cs similarity index 50% rename from Retroactiune.WebAPI/Settings/RetroactiuneDbSettings.cs rename to Retroactiune.WebAPI/Database/DatabaseSettings.cs index b14e376..c8e79cd 100644 --- a/Retroactiune.WebAPI/Settings/RetroactiuneDbSettings.cs +++ b/Retroactiune.WebAPI/Database/DatabaseSettings.cs @@ -1,6 +1,10 @@ -namespace Retroactiune.Settings +namespace Retroactiune.Database { - public class RetroactiuneDbSettings : IMongoDbSettings + /// + /// DatabaseSettingsOptions acts as a model for the database settings, it is used in conjunction with the built in + /// ASP .NET Core configuration options. + /// + public class DatabaseSettings : IDatabaseSettings { public string FeedbackCollectionName { get; set; } public string TokensCollectionName { get; set; } diff --git a/Retroactiune.WebAPI/Settings/IMongoDbSettings.cs b/Retroactiune.WebAPI/Database/IDatabaseSettings.cs similarity index 69% rename from Retroactiune.WebAPI/Settings/IMongoDbSettings.cs rename to Retroactiune.WebAPI/Database/IDatabaseSettings.cs index 512854f..c84174a 100644 --- a/Retroactiune.WebAPI/Settings/IMongoDbSettings.cs +++ b/Retroactiune.WebAPI/Database/IDatabaseSettings.cs @@ -1,9 +1,9 @@ -namespace Retroactiune.Settings +namespace Retroactiune.Database { /// - /// Interface for repressing the application's MongoDb settings Options. + /// Interface for repressing the application's database settings. /// - public interface IMongoDbSettings + public interface IDatabaseSettings { public string FeedbackCollectionName { get; set; } public string TokensCollectionName { get; set; } diff --git a/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs b/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs index 1eb452c..a819b02 100644 --- a/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs +++ b/Retroactiune.WebAPI/Services/FeedbackReceiverService.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using MongoDB.Driver; +using Retroactiune.Database; using Retroactiune.Models; -using Retroactiune.Settings; namespace Retroactiune.Services { @@ -16,7 +16,7 @@ namespace Retroactiune.Services { private readonly IMongoCollection _collection; - public FeedbackReceiverService(IMongoClient client, IMongoDbSettings settings) + public FeedbackReceiverService(IMongoClient client, IDatabaseSettings settings) { var database = client.GetDatabase(settings.DatabaseName); _collection = database.GetCollection(settings.FeedbackReceiverCollectionName); diff --git a/Retroactiune.WebAPI/Services/TokensService.cs b/Retroactiune.WebAPI/Services/TokensService.cs index 853ff7e..71b4c00 100644 --- a/Retroactiune.WebAPI/Services/TokensService.cs +++ b/Retroactiune.WebAPI/Services/TokensService.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using MongoDB.Driver; +using Retroactiune.Database; using Retroactiune.Models; -using Retroactiune.Settings; namespace Retroactiune.Services { @@ -11,7 +11,7 @@ namespace Retroactiune.Services { private readonly IMongoCollection _collection; - public TokensService(IMongoClient client, IMongoDbSettings settings) + public TokensService(IMongoClient client, IDatabaseSettings settings) { var database = client.GetDatabase(settings.DatabaseName); _collection = database.GetCollection(settings.TokensCollectionName); diff --git a/Retroactiune.WebAPI/Startup.cs b/Retroactiune.WebAPI/Startup.cs index 9a841f7..56fc8a4 100644 --- a/Retroactiune.WebAPI/Startup.cs +++ b/Retroactiune.WebAPI/Startup.cs @@ -9,8 +9,8 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MongoDB.Driver; +using Retroactiune.Database; using Retroactiune.Services; -using Retroactiune.Settings; namespace Retroactiune { @@ -28,9 +28,9 @@ namespace Retroactiune public void ConfigureServices(IServiceCollection services) { // Database Configuration - services.Configure(Configuration.GetSection(nameof(RetroactiuneDbSettings))); - services.AddSingleton(sp => - sp.GetRequiredService>().Value); + services.Configure(Configuration.GetSection(nameof(DatabaseSettings))); + services.AddSingleton(sp => + sp.GetRequiredService>().Value); // AutoMapper services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); @@ -41,7 +41,7 @@ namespace Retroactiune services.AddSingleton(); services.AddSingleton(i => { - var settings = i.GetService>(); + var settings = i.GetService>(); return new MongoClient(settings.Value.ConnectionString); }); diff --git a/Retroactiune.WebAPI/TestingStartup.cs b/Retroactiune.WebAPI/TestingStartup.cs index 2e25b91..b5252d1 100644 --- a/Retroactiune.WebAPI/TestingStartup.cs +++ b/Retroactiune.WebAPI/TestingStartup.cs @@ -4,8 +4,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using MongoDB.Driver; +using Retroactiune.Database; using Retroactiune.Services; -using Retroactiune.Settings; namespace Retroactiune { @@ -26,9 +26,9 @@ namespace Retroactiune public void ConfigureServices(IServiceCollection services) { // Database Configuration - services.Configure(Configuration.GetSection(nameof(RetroactiuneDbSettings))); - services.AddSingleton(sp => - sp.GetRequiredService>().Value); + services.Configure(Configuration.GetSection(nameof(DatabaseSettings))); + services.AddSingleton(sp => + sp.GetRequiredService>().Value); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); @@ -36,7 +36,7 @@ namespace Retroactiune services.AddSingleton(); services.AddSingleton(i => { - var settings = i.GetService>(); + var settings = i.GetService>(); return new MongoClient(settings.Value.ConnectionString); }); diff --git a/Retroactiune.WebAPI/appsettings.Testing.json b/Retroactiune.WebAPI/appsettings.Testing.json index 974424a..ddce3c1 100644 --- a/Retroactiune.WebAPI/appsettings.Testing.json +++ b/Retroactiune.WebAPI/appsettings.Testing.json @@ -1,5 +1,5 @@ { - "RetroactiuneDbSettings": { + "DatabaseSettings": { "FeedbackCollectionName": "feedback", "TokensCollectionName": "tokens", "FeedbackReceiverCollectionName": "feedback_receiver", diff --git a/Retroactiune.WebAPI/appsettings.json b/Retroactiune.WebAPI/appsettings.json index af55352..115992e 100644 --- a/Retroactiune.WebAPI/appsettings.json +++ b/Retroactiune.WebAPI/appsettings.json @@ -1,5 +1,5 @@ { - "RetroactiuneDbSettings": { + "DatabaseSettings": { "FeedbackCollectionName": "feedback", "TokensCollectionName": "tokens", "FeedbackReceiverCollectionName": "feedback_receiver",