From c324e438422f5f6d6dbd949be44c92de5d54216d Mon Sep 17 00:00:00 2001 From: Robbware Date: Fri, 6 Oct 2023 11:53:26 +0100 Subject: [PATCH 1/5] Move the bookconfiguration settings to the ConfigurationService and allow both the WASM and Server Configuration services to be able to parse complex objects and not just key value pairs. --- .../BookEditor/EditotPopupTestFixture.cs | 13 ++---- .../configuration/server_configuration.json | 6 ++- .../ConfigurationServiceTestFixture.cs | 32 +++++++++++--- COMET.Web.Common/COMET.Web.Common.csproj | 4 +- .../BookEditor/EditorPopup.razor.cs | 41 ++++-------------- .../Configuration/BookInputConfiguration.cs | 42 +++++++++++++++++++ .../Configuration/ServerConfiguration.cs | 36 ++++++++++++++++ .../ConfigurationService.cs | 16 +++++++ .../BaseConfigurationService.cs | 8 ++++ .../IConfigurationService.cs | 8 ++++ .../ConfigurationService.cs | 6 ++- .../wwwroot/BookInputConfiguration.json | 4 -- .../wwwroot/server_configuration.json | 6 ++- .../BookEditor/BookEditorBodyTestFixture.cs | 4 ++ 14 files changed, 166 insertions(+), 60 deletions(-) create mode 100644 COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs create mode 100644 COMET.Web.Common/Model/Configuration/ServerConfiguration.cs delete mode 100644 COMET.Web.Common/wwwroot/BookInputConfiguration.json diff --git a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs index 35d27aa0..38e62fcd 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs @@ -31,6 +31,7 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using COMET.Web.Common.Components; using COMET.Web.Common.Components.BookEditor; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components.BookEditor; @@ -62,8 +63,7 @@ public class EditotPopupTestFixture private bool onCancelCalled; private bool onAcceptCalled; private Mock sessionService; - private MockHttpMessageHandler mockHttpMessageHandler; - private HttpClient httpClient; + private Mock configurationService; [SetUp] public void Setup() @@ -71,14 +71,9 @@ public void Setup() this.context = new TestContext(); this.context.ConfigureDevExpressBlazor(); this.sessionService = new Mock(); + this.configurationService = new Mock(); this.context.Services.AddSingleton(this.sessionService.Object); - this.mockHttpMessageHandler = new MockHttpMessageHandler(); - this.httpClient = this.mockHttpMessageHandler.ToHttpClient(); - this.httpClient.BaseAddress = new Uri("http://localhost/"); - this.context.Services.AddScoped(_ => this.httpClient); - var httpResponse = new HttpResponseMessage(); - httpResponse.Content = new StringContent("{\n \"ShowName\": true,\n \"ShowShortName\" : true \n}\n"); - this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/BookInputConfiguration.json").Respond(_ => httpResponse); + this.context.Services.AddSingleton(this.configurationService.Object); this.book = new Book(); this.activeDomains = new List diff --git a/COMET.Web.Common.Tests/Resources/configuration/server_configuration.json b/COMET.Web.Common.Tests/Resources/configuration/server_configuration.json index 79fc8683..8d343028 100644 --- a/COMET.Web.Common.Tests/Resources/configuration/server_configuration.json +++ b/COMET.Web.Common.Tests/Resources/configuration/server_configuration.json @@ -1,3 +1,7 @@ { - "ServerAddress": "" + "ServerAddress": "", + "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 405bf5c1..1693317b 100644 --- a/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs @@ -25,14 +25,21 @@ namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService { + using System.Text; + + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Server.Services.ConfigurationService; using Microsoft.Extensions.Configuration; using Moq; + using Newtonsoft.Json; + using NUnit.Framework; + using JsonSerializer = System.Text.Json.JsonSerializer; + [TestFixture] public class ConfigurationServiceTestFixture { @@ -41,33 +48,46 @@ 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); 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); Assert.That(service.ServerAddress, Is.Null); + Assert.That(service.BookInputConfiguration, Is.Null); }); await service.InitializeService(); configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); + configuration.Verify(x => x.GetSection(ConfigurationService.BookInputConfigurationSection), Times.Once); } [Test] public async Task VerifyInitializeServiceWithConfiguration() { - var configurationSection = new Mock(); - configurationSection.Setup(x => x.Value).Returns("https://a.b.c"); + 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 configuration = new Mock(); - configuration.Setup(x => x.GetSection(ConfigurationService.AddressSection)).Returns(configurationSection.Object); + configuration.Setup(x => x.GetSection(ConfigurationService.AddressSection)).Returns(serverAddressMockConfigurationSection.Object); + configuration.Setup(x => x.GetSection(ConfigurationService.BookInputConfigurationSection)).Returns(bookInputMockConfigurationSection.Object); var service = new ConfigurationService(configuration.Object); await service.InitializeService(); - + Assert.Multiple(() => { - configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); - Assert.That(service.ServerAddress, Is.EqualTo(configurationSection.Object.Value)); + Assert.That(service.ServerAddress, Is.EqualTo(serverAddressMockConfigurationSection.Object.Value)); + Assert.IsNotNull(service.BookInputConfiguration); + Assert.That(service.BookInputConfiguration.ShowName, Is.EqualTo(bookInputConfiguration.ShowName)); + Assert.That(service.BookInputConfiguration.ShowShortName, Is.EqualTo(bookInputConfiguration.ShowShortName)); }); } } diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 3377b3f0..79e6c010 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -30,6 +30,7 @@ + @@ -47,9 +48,6 @@ Always - - Always - Always diff --git a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs index 34745ef2..f11ef5a5 100644 --- a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs @@ -30,7 +30,9 @@ namespace COMET.Web.Common.Components.BookEditor using CDP4Common.ReportingData; using COMET.Web.Common.Model; + using COMET.Web.Common.Model.DTO; using COMET.Web.Common.Services; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Utilities; using COMET.Web.Common.ViewModels.Components.BookEditor; @@ -57,7 +59,7 @@ public partial class EditorPopup /// Gets or sets the /// [Inject] - public HttpClient HttpClient { get; set; } + public IConfigurationService ConfigurationService { get; set; } /// /// Gets or sets the @@ -100,40 +102,11 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); this.Disposables.Add(this.ViewModel.ValidationErrors.Connect().Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); - - var jsonFile = this.Options.Value.JsonConfigurationFile ?? "BookInputConfiguration.json"; + var configurations = this.ConfigurationService.BookInputConfiguration; - try - { - var configurations = await this.GetBookInputConfigurationAsync(jsonFile); - - if (configurations.TryGetValue(showNameConfigurationProperty, out var showNameValue)) - { - this.showName = showNameValue; - } - - if (configurations.TryGetValue(showShortNameConfigurationProperty, out var showShortNameValue)) - { - this.showShortName = showShortNameValue; - } - } - catch (Exception e) - { - this.Logger.LogError(e, "Error while getting the configuration file."); - } - } - - /// - /// Acquires the BookInput configurations - /// - /// The file name that contains the configurations - /// A KeyValuePair collection with each available configuration - private async Task> GetBookInputConfigurationAsync(string fileName) - { - var path = ContentPathBuilder.BuildPath(fileName); - var jsonContent = await this.HttpClient.GetStreamAsync(path); - var configurations = JsonSerializer.Deserialize>(jsonContent); - return configurations; + //The fields will be shown by default + this.showName = configurations?.ShowName ?? true; + this.showShortName = configurations?.ShowShortName ?? true; } /// diff --git a/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs b/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs new file mode 100644 index 00000000..8ad5a1d9 --- /dev/null +++ b/COMET.Web.Common/Model/Configuration/BookInputConfiguration.cs @@ -0,0 +1,42 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Model.Configuration; + +using System.Text.Json.Serialization; + +public class BookInputConfiguration +{ + /// + /// Verifies if the Name field will be displayed on the Book Input form + /// + [JsonPropertyName("ShowName")] + public bool ShowName { get; set; } + + /// + /// Verifies if the ShortName field will be displayed on the Book Input form + /// + [JsonPropertyName("ShowShortName")] + public bool ShowShortName { get; set; } +} diff --git a/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs b/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs new file mode 100644 index 00000000..58f751c3 --- /dev/null +++ b/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs @@ -0,0 +1,36 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Model.Configuration; + +using System.Text.Json.Serialization; + +public class ServerConfiguration +{ + [JsonPropertyName("ServerAddress")] + public string ServerAddress { get; set; } + + [JsonPropertyName("BookInputConfiguration")] + public BookInputConfiguration BookInputConfiguration { get; set; } +} diff --git a/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs b/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs index cff351c5..59a0b746 100644 --- a/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs +++ b/COMET.Web.Common/Server/Services/ConfigurationService/ConfigurationService.cs @@ -25,6 +25,10 @@ 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; @@ -39,6 +43,11 @@ public class ConfigurationService : BaseConfigurationService /// public const string AddressSection = "ServerAddress"; + /// + /// Gets the BookInputConfiguration section key + /// + public const string BookInputConfigurationSection = "BookInputConfiguration"; + /// /// Gets the /// @@ -71,6 +80,13 @@ public override Task InitializeService() this.ServerAddress = addressSection.Value; } + var bookInputConfigurationSection = this.configuration.GetSection(BookInputConfigurationSection); + + if (bookInputConfigurationSection.Exists()) + { + this.BookInputConfiguration = JsonSerializer.Deserialize(bookInputConfigurationSection.Value); + } + this.IsInitialized = true; return Task.CompletedTask; } diff --git a/COMET.Web.Common/Services/ConfigurationService/BaseConfigurationService.cs b/COMET.Web.Common/Services/ConfigurationService/BaseConfigurationService.cs index c9f7e177..34e09974 100644 --- a/COMET.Web.Common/Services/ConfigurationService/BaseConfigurationService.cs +++ b/COMET.Web.Common/Services/ConfigurationService/BaseConfigurationService.cs @@ -25,6 +25,9 @@ namespace COMET.Web.Common.Services.ConfigurationService { + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Model.DTO; + /// /// Base Service that holds the configuration for the application /// @@ -39,6 +42,11 @@ public abstract class BaseConfigurationService: IConfigurationService /// The Server Address to use /// public string ServerAddress { get; protected set; } + + /// + /// The configuration values for the Book feature + /// + public BookInputConfiguration BookInputConfiguration { get; protected set; } /// /// Initializes the diff --git a/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs b/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs index 9ebc0a75..c58e8376 100644 --- a/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs +++ b/COMET.Web.Common/Services/ConfigurationService/IConfigurationService.cs @@ -25,6 +25,9 @@ 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 /// @@ -34,6 +37,11 @@ public interface IConfigurationService /// The Server Address to use /// string ServerAddress { get; } + + /// + /// The configuration values for the Book feature + /// + BookInputConfiguration BookInputConfiguration { get; } /// /// Initializes the diff --git a/COMET.Web.Common/WebAssembly/Services/ConfigurationService/ConfigurationService.cs b/COMET.Web.Common/WebAssembly/Services/ConfigurationService/ConfigurationService.cs index 02e03248..a6d1b087 100644 --- a/COMET.Web.Common/WebAssembly/Services/ConfigurationService/ConfigurationService.cs +++ b/COMET.Web.Common/WebAssembly/Services/ConfigurationService/ConfigurationService.cs @@ -29,6 +29,7 @@ namespace COMET.Web.Common.WebAssembly.Services.ConfigurationService using System.Text.Json; using COMET.Web.Common.Model; + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Utilities; @@ -87,8 +88,9 @@ public override async Task InitializeService() if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStreamAsync(); - var configurations = JsonSerializer.Deserialize>(jsonContent); - this.ServerAddress = configurations["ServerAddress"]; + var configurations = JsonSerializer.Deserialize(jsonContent); + this.ServerAddress = configurations.ServerAddress; + this.BookInputConfiguration = configurations.BookInputConfiguration; } else if (response.StatusCode == HttpStatusCode.NotFound) { diff --git a/COMET.Web.Common/wwwroot/BookInputConfiguration.json b/COMET.Web.Common/wwwroot/BookInputConfiguration.json deleted file mode 100644 index cd465b2a..00000000 --- a/COMET.Web.Common/wwwroot/BookInputConfiguration.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "ShowName": true, - "ShowShortName" : true -} \ No newline at end of file diff --git a/COMET.Web.Common/wwwroot/server_configuration.json b/COMET.Web.Common/wwwroot/server_configuration.json index 79fc8683..8d343028 100644 --- a/COMET.Web.Common/wwwroot/server_configuration.json +++ b/COMET.Web.Common/wwwroot/server_configuration.json @@ -1,3 +1,7 @@ { - "ServerAddress": "" + "ServerAddress": "", + "BookInputConfiguration": { + "ShowName": true, + "ShowShortName": true + } } diff --git a/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs b/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs index 6b3e6d5f..6b6880c4 100644 --- a/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs +++ b/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs @@ -31,6 +31,7 @@ namespace COMETwebapp.Tests.Components.BookEditor using CDP4Common.ReportingData; using CDP4Common.SiteDirectoryData; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components; @@ -61,6 +62,7 @@ public class BookEditorBodyTestFixture private Section selectedSection; private Page selectedPage; private Note selectedNote; + private Mock configurationService; [SetUp] public void Setup() @@ -68,6 +70,7 @@ public void Setup() this.context = new TestContext(); this.context.ConfigureDevExpressBlazor(); this.sessionService = new Mock(); + this.configurationService = new Mock(); this.selectedBook = new Book(); this.selectedSection = new Section(); @@ -106,6 +109,7 @@ public void Setup() this.context.Services.AddSingleton(this.viewModel.Object); this.context.Services.AddSingleton(this.sessionService.Object); + this.context.Services.AddSingleton(this.configurationService.Object); this.context.Services.AddSingleton(domDataService.Object); this.component = this.context.RenderComponent(); From 585bdd9798969a6ca217a1aa95d6dfca71e331d0 Mon Sep 17 00:00:00 2001 From: Robbware Date: Fri, 6 Oct 2023 11:59:51 +0100 Subject: [PATCH 2/5] Remove unecessary library --- COMET.Web.Common/COMET.Web.Common.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 79e6c010..57eddb38 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -30,7 +30,6 @@ - From 096aae1ab8ec1d5cd5ed864101f5f4ac4e0d0ac6 Mon Sep 17 00:00:00 2001 From: Robbware Date: Fri, 6 Oct 2023 12:35:31 +0100 Subject: [PATCH 3/5] Refactor the ConfigurationService so that we're using a single ServerConfiguration object for all configuration needs. Fix all tests and components that were using the deleted properties from the ConfigurationService. Parse feedback and add documentation. --- .../BookEditor/EditotPopupTestFixture.cs | 2 ++ .../Components/IndexComponentTestFixture.cs | 2 ++ .../Components/LoginTestFixture.cs | 3 ++- ...IterationApplicationTemplateTestFixture.cs | 5 +++- .../ConfigurationServiceTestFixture.cs | 24 +++++++++---------- .../ConfigurationServiceTestFixture.cs | 2 +- .../BookEditor/EditorPopup.razor.cs | 2 +- COMET.Web.Common/Components/Login.razor | 2 +- ...ingleIterationApplicationTemplate.razor.cs | 2 +- .../Configuration/BookInputConfiguration.cs | 2 -- .../Configuration/ServerConfiguration.cs | 13 ++++++---- .../ConfigurationService.cs | 6 +++-- .../BaseConfigurationService.cs | 10 ++------ .../IConfigurationService.cs | 9 ++----- .../ViewModels/Components/LoginViewModel.cs | 4 ++-- .../ConfigurationService.cs | 5 ++-- .../BookEditor/BookEditorBodyTestFixture.cs | 2 ++ .../ModelDashboardTestFixture.cs | 6 ++++- .../ParameterEditorTestFixture.cs | 6 ++++- .../Pages/Viewer/ViewerTestFixture.cs | 6 ++++- 20 files changed, 64 insertions(+), 49 deletions(-) diff --git a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs index 38e62fcd..5b7063cb 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs @@ -31,6 +31,7 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using COMET.Web.Common.Components; using COMET.Web.Common.Components.BookEditor; + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; @@ -72,6 +73,7 @@ public void Setup() this.context.ConfigureDevExpressBlazor(); this.sessionService = new Mock(); this.configurationService = new Mock(); + this.configurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); this.context.Services.AddSingleton(this.sessionService.Object); this.context.Services.AddSingleton(this.configurationService.Object); this.book = new Book(); diff --git a/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs b/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs index 60d7bfc8..85763b4b 100644 --- a/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs @@ -38,6 +38,7 @@ namespace COMET.Web.Common.Tests.Components using COMET.Web.Common.Components; using COMET.Web.Common.Extensions; using COMET.Web.Common.Model; + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.RegistrationService; using COMET.Web.Common.Services.SessionManagement; @@ -68,6 +69,7 @@ public void Setup() this.versionService = new Mock(); this.sessionService = new Mock(); this.serverConnectionService = new Mock(); + this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); this.sourceList = new SourceList(); this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList); diff --git a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs index 95f84944..2f96cec9 100644 --- a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs @@ -29,6 +29,7 @@ namespace COMET.Web.Common.Tests.Components using COMET.Web.Common.Components; using COMET.Web.Common.Enumerations; + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Model.DTO; using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; @@ -57,7 +58,7 @@ public void Setup() { this.authenticationService = new Mock(); this.serverConnectionService = new Mock(); - this.serverConnectionService.Setup(x => x.ServerAddress).Returns("http://localhost.com"); + this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration { ServerAddress = "http://localhost.com" }); this.context = new TestContext(); this.viewModel = new LoginViewModel(this.authenticationService.Object, this.serverConnectionService.Object); this.context.Services.AddSingleton(this.viewModel); diff --git a/COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs b/COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs index 6da7ebfd..d3cad8cc 100644 --- a/COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs @@ -36,6 +36,7 @@ namespace COMET.Web.Common.Tests.Components using COMET.Web.Common.Components; using COMET.Web.Common.Components.Selectors; using COMET.Web.Common.Extensions; + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Services.StringTableService; @@ -74,9 +75,11 @@ public void Setup() sessionService.Setup(x => x.Session).Returns(session.Object); sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise(){Iid = Guid.NewGuid()}); this.viewModel.Setup(x => x.SessionService).Returns(sessionService.Object); + var mockConfigurationService = new Mock(); + mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); this.context.Services.AddSingleton(this.viewModel.Object); this.context.Services.AddSingleton(); - this.context.Services.AddSingleton(new Mock().Object); + this.context.Services.AddSingleton(mockConfigurationService.Object); this.context.Services.AddSingleton(new Mock().Object); this.context.Services.AddSingleton(sessionService.Object); this.context.ConfigureDevExpressBlazor(); diff --git a/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs b/COMET.Web.Common.Tests/Server/Services/ConfigurationService/ConfigurationServiceTestFixture.cs index 1693317b..3a84a0db 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; - using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Server.Services.ConfigurationService; @@ -34,8 +32,6 @@ namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService using Moq; - using Newtonsoft.Json; - using NUnit.Framework; using JsonSerializer = System.Text.Json.JsonSerializer; @@ -56,13 +52,17 @@ public async Task VerifyInitializeServiceWithEmptyConfiguration() { configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); configuration.Verify(x => x.GetSection(ConfigurationService.BookInputConfigurationSection), Times.Once); - Assert.That(service.ServerAddress, Is.Null); - Assert.That(service.BookInputConfiguration, Is.Null); + Assert.That(service.ServerConfiguration.ServerAddress, Is.Null); + Assert.That(service.ServerConfiguration.BookInputConfiguration, Is.Null); }); await service.InitializeService(); - configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); - configuration.Verify(x => x.GetSection(ConfigurationService.BookInputConfigurationSection), Times.Once); + + Assert.Multiple(() => + { + configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once); + configuration.Verify(x => x.GetSection(ConfigurationService.BookInputConfigurationSection), Times.Once); + }); } [Test] @@ -84,10 +84,10 @@ public async Task VerifyInitializeServiceWithConfiguration() Assert.Multiple(() => { - Assert.That(service.ServerAddress, Is.EqualTo(serverAddressMockConfigurationSection.Object.Value)); - Assert.IsNotNull(service.BookInputConfiguration); - Assert.That(service.BookInputConfiguration.ShowName, Is.EqualTo(bookInputConfiguration.ShowName)); - Assert.That(service.BookInputConfiguration.ShowShortName, Is.EqualTo(bookInputConfiguration.ShowShortName)); + Assert.That(service.ServerConfiguration.ServerAddress, Is.EqualTo(serverAddressMockConfigurationSection.Object.Value)); + 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)); }); } } diff --git a/COMET.Web.Common.Tests/WebAssembly/Services/ConfigurationService/ConfigurationServiceTestFixture.cs b/COMET.Web.Common.Tests/WebAssembly/Services/ConfigurationService/ConfigurationServiceTestFixture.cs index 6a1b7c00..e65a886c 100644 --- a/COMET.Web.Common.Tests/WebAssembly/Services/ConfigurationService/ConfigurationServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/WebAssembly/Services/ConfigurationService/ConfigurationServiceTestFixture.cs @@ -96,7 +96,7 @@ public async Task VerifiyInitialization() httpResponse.StatusCode = HttpStatusCode.OK; httpResponse.Content = new StringContent("{\"ServerAddress\":\"http://localhost\"}"); await this.configurationService.InitializeService(); - Assert.That(this.configurationService.ServerAddress, Is.EqualTo("http://localhost")); + Assert.That(this.configurationService.ServerConfiguration.ServerAddress, Is.EqualTo("http://localhost")); } } } diff --git a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs index f11ef5a5..f0119063 100644 --- a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs @@ -102,7 +102,7 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); this.Disposables.Add(this.ViewModel.ValidationErrors.Connect().Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); - var configurations = this.ConfigurationService.BookInputConfiguration; + var configurations = this.ConfigurationService.ServerConfiguration.BookInputConfiguration; //The fields will be shown by default this.showName = configurations?.ShowName ?? true; diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 86ee9e4b..97588457 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -25,7 +25,7 @@ - @if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerAddress)) + @if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerConfiguration.ServerAddress)) {