diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index 00522345..55c1006c 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -35,6 +35,10 @@ true PreserveNewest + + + Always + diff --git a/COMET.Web.Common.Tests/Data/server_configuration_tests.json b/COMET.Web.Common.Tests/Data/server_configuration_tests.json new file mode 100644 index 00000000..2b2e5917 --- /dev/null +++ b/COMET.Web.Common.Tests/Data/server_configuration_tests.json @@ -0,0 +1,9 @@ +{ + "ServerConfiguration": { + "ServerAddress": "https://a.b.c", + "BookInputConfiguration": { + "ShowName": true, + "ShowShortName": true + } + } +} diff --git a/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs b/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs index b49b8c8b..9ec3814c 100644 --- a/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs @@ -25,8 +25,6 @@ namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService { - using System.Text.Json; - using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Server.Services.ConfigurationService; @@ -50,8 +48,7 @@ public async Task VerifyInitializeServiceWithEmptyConfiguration() Assert.Multiple(() => { configuration.Verify(x => x.GetSection(ConfigurationService.ServerConfigurationSection), Times.Once); - Assert.That(service.ServerConfiguration.ServerAddress, Is.Null); - Assert.That(service.ServerConfiguration.BookInputConfiguration, Is.Null); + Assert.That(service.ServerConfiguration, Is.Null); }); await service.InitializeService(); @@ -65,8 +62,6 @@ public async Task VerifyInitializeServiceWithEmptyConfiguration() [Test] public async Task VerifyInitializeServiceWithConfiguration() { - var serverAddressMockConfigurationSection = new Mock(); - var serverConfiguration = new ServerConfiguration { ServerAddress = "https://a.b.c", @@ -76,13 +71,12 @@ public async Task VerifyInitializeServiceWithConfiguration() ShowShortName = true } }; - - var serverConfigurationJson = JsonSerializer.Serialize(serverConfiguration); - serverAddressMockConfigurationSection.Setup(x => x.Value).Returns(serverConfigurationJson); - var configuration = new Mock(); - configuration.Setup(x => x.GetSection(ConfigurationService.ServerConfigurationSection)).Returns(serverAddressMockConfigurationSection.Object); - var service = new ConfigurationService(configuration.Object); + var config = new ConfigurationBuilder() + .AddJsonFile("Data/server_configuration_tests.json") + .Build(); + + var service = new ConfigurationService(config); await service.InitializeService(); Assert.Multiple(() => diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 57eddb38..79e6c010 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -30,6 +30,7 @@ + diff --git a/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs b/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs index ea151de6..93ba909f 100644 --- a/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs +++ b/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs @@ -25,10 +25,7 @@ namespace COMET.Web.Common.Server.Services.ConfigurationService { - using System.Text.Json; - using COMET.Web.Common.Model.Configuration; - using COMET.Web.Common.Model.DTO; using COMET.Web.Common.Services.ConfigurationService; using Microsoft.Extensions.Configuration; @@ -68,15 +65,7 @@ public override Task InitializeService() return Task.CompletedTask; } - this.ServerConfiguration = new ServerConfiguration(); - - var serverConfigurationSection = this.configuration.GetSection(ServerConfigurationSection); - - if (serverConfigurationSection.Exists()) - { - this.ServerConfiguration = JsonSerializer.Deserialize(serverConfigurationSection.Value); - } - + this.ServerConfiguration = this.configuration.GetSection(ServerConfigurationSection).Get(); this.IsInitialized = true; return Task.CompletedTask; }