diff --git a/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs b/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs index 3a84a0db..b49b8c8b 100644 --- a/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs @@ -25,6 +25,8 @@ 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; @@ -33,9 +35,7 @@ namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService using Moq; using NUnit.Framework; - - using JsonSerializer = System.Text.Json.JsonSerializer; - + [TestFixture] public class ConfigurationServiceTestFixture { @@ -43,15 +43,13 @@ public class ConfigurationServiceTestFixture public async Task VerifyInitializeServiceWithEmptyConfiguration() { var configuration = new Mock(); - configuration.Setup(x => x.GetSection(ConfigurationService.AddressSection)).Returns(new Mock().Object); - configuration.Setup(x => x.GetSection(ConfigurationService.BookInputConfigurationSection)).Returns(new Mock().Object); + configuration.Setup(x => x.GetSection(ConfigurationService.ServerConfigurationSection)).Returns(new Mock().Object); var service = new ConfigurationService(configuration.Object); await service.InitializeService(); Assert.Multiple(() => { - configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); - configuration.Verify(x => x.GetSection(ConfigurationService.BookInputConfigurationSection), Times.Once); + configuration.Verify(x => x.GetSection(ConfigurationService.ServerConfigurationSection), Times.Once); Assert.That(service.ServerConfiguration.ServerAddress, Is.Null); Assert.That(service.ServerConfiguration.BookInputConfiguration, Is.Null); }); @@ -60,8 +58,7 @@ public async Task VerifyInitializeServiceWithEmptyConfiguration() Assert.Multiple(() => { - configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); - configuration.Verify(x => x.GetSection(ConfigurationService.BookInputConfigurationSection), Times.Once); + configuration.Verify(x => x.GetSection(ConfigurationService.ServerConfigurationSection), Times.Once); }); } @@ -69,25 +66,31 @@ public async Task VerifyInitializeServiceWithEmptyConfiguration() public async Task VerifyInitializeServiceWithConfiguration() { var serverAddressMockConfigurationSection = new Mock(); - serverAddressMockConfigurationSection.Setup(x => x.Value).Returns("https://a.b.c"); - - var bookInputMockConfigurationSection = new Mock(); - var bookInputConfiguration = new BookInputConfiguration { ShowName = true, ShowShortName = true }; - var defaultBookInputConfigurationJson = JsonSerializer.Serialize(bookInputConfiguration); - bookInputMockConfigurationSection.Setup(x => x.Value).Returns(defaultBookInputConfigurationJson); + + var serverConfiguration = new ServerConfiguration + { + ServerAddress = "https://a.b.c", + BookInputConfiguration = new BookInputConfiguration() + { + ShowName = true, + ShowShortName = true + } + }; + + var serverConfigurationJson = JsonSerializer.Serialize(serverConfiguration); + serverAddressMockConfigurationSection.Setup(x => x.Value).Returns(serverConfigurationJson); var configuration = new Mock(); - configuration.Setup(x => x.GetSection(ConfigurationService.AddressSection)).Returns(serverAddressMockConfigurationSection.Object); - configuration.Setup(x => x.GetSection(ConfigurationService.BookInputConfigurationSection)).Returns(bookInputMockConfigurationSection.Object); + configuration.Setup(x => x.GetSection(ConfigurationService.ServerConfigurationSection)).Returns(serverAddressMockConfigurationSection.Object); var service = new ConfigurationService(configuration.Object); await service.InitializeService(); Assert.Multiple(() => { - Assert.That(service.ServerConfiguration.ServerAddress, Is.EqualTo(serverAddressMockConfigurationSection.Object.Value)); + Assert.That(service.ServerConfiguration.ServerAddress, Is.EqualTo(serverConfiguration.ServerAddress)); Assert.That(service.ServerConfiguration.BookInputConfiguration, Is.Not.Null); - Assert.That(service.ServerConfiguration.BookInputConfiguration.ShowName, Is.EqualTo(bookInputConfiguration.ShowName)); - Assert.That(service.ServerConfiguration.BookInputConfiguration.ShowShortName, Is.EqualTo(bookInputConfiguration.ShowShortName)); + Assert.That(service.ServerConfiguration.BookInputConfiguration.ShowName, Is.EqualTo(serverConfiguration.BookInputConfiguration.ShowName)); + Assert.That(service.ServerConfiguration.BookInputConfiguration.ShowShortName, Is.EqualTo(serverConfiguration.BookInputConfiguration.ShowShortName)); }); } } diff --git a/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs b/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs index 5b5d2e79..dfc6bc5d 100644 --- a/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs +++ b/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs @@ -24,8 +24,9 @@ namespace COMET.Web.Common.Model.Configuration; -using System.Text.Json.Serialization; - +/// +/// Holds all of the configuration related to the Book feature +/// public class BookInputConfiguration { /// diff --git a/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs b/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs index 02b2dbcc..ea151de6 100644 --- a/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs +++ b/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs @@ -39,14 +39,9 @@ namespace COMET.Web.Common.Server.Services.ConfigurationService public class ConfigurationService : BaseConfigurationService { /// - /// Gets the ServerAddress section key + /// Gets the ServerConfiguration section key /// - public const string AddressSection = "ServerAddress"; - - /// - /// Gets the BookInputConfiguration section key - /// - public const string BookInputConfigurationSection = "BookInputConfiguration"; + public const string ServerConfigurationSection = "ServerConfiguration"; /// /// Gets the @@ -74,19 +69,12 @@ public override Task InitializeService() } this.ServerConfiguration = new ServerConfiguration(); - - var addressSection = this.configuration.GetSection(AddressSection); - if (addressSection.Exists()) - { - this.ServerConfiguration.ServerAddress = addressSection.Value; - } - - var bookInputConfigurationSection = this.configuration.GetSection(BookInputConfigurationSection); - - if (bookInputConfigurationSection.Exists()) + var serverConfigurationSection = this.configuration.GetSection(ServerConfigurationSection); + + if (serverConfigurationSection.Exists()) { - this.ServerConfiguration.BookInputConfiguration = JsonSerializer.Deserialize(bookInputConfigurationSection.Value); + this.ServerConfiguration = JsonSerializer.Deserialize(serverConfigurationSection.Value); } this.IsInitialized = true; diff --git a/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs b/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs index eb571c42..fb340cbb 100644 --- a/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs +++ b/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs @@ -26,7 +26,6 @@ namespace COMET.Web.Common.Services.ConfigurationService { using COMET.Web.Common.Model.Configuration; - using COMET.Web.Common.Model.DTO; /// /// Service that holds the configuration for the application @@ -36,7 +35,7 @@ public interface IConfigurationService /// /// Holds all of the configuration related values /// - public ServerConfiguration ServerConfiguration { get; set; } + ServerConfiguration ServerConfiguration { get; set; } /// /// Initializes the diff --git a/COMET.Web.Common/wwwroot/server_configuration.json b/COMET.Web.Common/wwwroot/server_configuration.json index 8d343028..af29ad44 100644 --- a/COMET.Web.Common/wwwroot/server_configuration.json +++ b/COMET.Web.Common/wwwroot/server_configuration.json @@ -1,7 +1,9 @@ { - "ServerAddress": "", - "BookInputConfiguration": { - "ShowName": true, - "ShowShortName": true + "ServerConfiguration": { + "ServerAddress": "", + "BookInputConfiguration": { + "ShowName": true, + "ShowShortName": true + } } }