From 124868304b792d7bac6dfae769231c857262030b Mon Sep 17 00:00:00 2001 From: Robbware Date: Wed, 4 Oct 2023 13:26:50 +0100 Subject: [PATCH 01/13] Refactor the ShowName/ShowShortName configuration so that it's done on the parent component first (where the validations are made) and set to the child component. --- .../BookEditor/InputEditorTestFixture.cs | 4 + .../Components/BookEditor/EditorPopup.razor | 2 +- .../BookEditor/EditorPopup.razor.cs | 85 +++++++++++++++++-- .../Components/BookEditor/InputEditor.razor | 4 +- .../BookEditor/InputEditor.razor.cs | 73 +++++----------- .../wwwroot/BookInputConfiguration.json | 4 +- COMETwebapp/COMETwebapp.csproj | 6 ++ .../wwwroot/BookInputConfiguration.json | 4 + 8 files changed, 118 insertions(+), 64 deletions(-) create mode 100644 COMETwebapp/wwwroot/BookInputConfiguration.json diff --git a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs index bd9de519..1eddac4b 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs @@ -100,6 +100,8 @@ public void Setup() parameters.Add(p => p.Item, this.book); parameters.Add(p => p.ActiveDomains, this.activeDomains); parameters.Add(p => p.AvailableCategories, this.availableCategories); + parameters.Add(p => p.ShowName, true); + parameters.Add(p => p.ShowShortName, true); }); } @@ -119,6 +121,8 @@ public void VerifyComponent() Assert.IsNotNull(shortNameTextbox); Assert.That(combobox.Instance.Value, Is.EqualTo(this.activeDomains.First())); Assert.That(categoryComboBox.Instance, Is.Not.Null); + Assert.IsTrue(this.component.Instance.ShowName); + Assert.IsTrue(this.component.Instance.ShowShortName); }); this.component.Render(); diff --git a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor index 4d3482fc..994f736e 100644 --- a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor +++ b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor @@ -24,7 +24,7 @@ - +
@foreach (var validationError in this.ViewModel.ValidationErrors.Items) { diff --git a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs index 46434852..34745ef2 100644 --- a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs @@ -24,13 +24,19 @@ // -------------------------------------------------------------------------------------------------------------------- namespace COMET.Web.Common.Components.BookEditor -{ - using CDP4Common.ReportingData; - +{ + using System.Text.Json; + + using CDP4Common.ReportingData; + + using COMET.Web.Common.Model; using COMET.Web.Common.Services; + using COMET.Web.Common.Utilities; using COMET.Web.Common.ViewModels.Components.BookEditor; using Microsoft.AspNetCore.Components; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; using INamedThing = CDP4Common.CommonData.INamedThing; using IOwnedThing = CDP4Common.EngineeringModelData.IOwnedThing; @@ -47,6 +53,41 @@ public partial class EditorPopup [Parameter] public IEditorPopupViewModel ViewModel { get; set; } + /// + /// Gets or sets the + /// + [Inject] + public HttpClient HttpClient { get; set; } + + /// + /// Gets or sets the + /// + [Inject] + public IOptions Options { get; set; } + + [Inject] + public ILogger Logger { get; set; } + + /// + /// Sets if the component should show the name field + /// + private bool showName; + + /// + /// The name of the ShowName property on the configuration file + /// + private const string showNameConfigurationProperty = "ShowName"; + + /// + /// Sets if the component should show the shorname field + /// + private bool showShortName; + + /// + /// The name of the ShowShortName property on the configuration file + /// + private const string showShortNameConfigurationProperty = "ShowShortName"; + /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. @@ -59,6 +100,40 @@ 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"; + + 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; } /// @@ -68,13 +143,13 @@ private async Task OnConfirmClick() { var validationErrors = new List(); - if (this.ViewModel.Item is INamedThing namedThing) + if (this.ViewModel.Item is INamedThing namedThing && this.showName) { var error = ValidationService.ValidateProperty(nameof(namedThing.Name), namedThing.Name); validationErrors.Add(error); } - if (this.ViewModel.Item is IShortNamedThing shortNamedThing) + if (this.ViewModel.Item is IShortNamedThing shortNamedThing && this.showShortName) { var error = ValidationService.ValidateProperty(nameof(shortNamedThing.ShortName), shortNamedThing.ShortName); validationErrors.Add(error); diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor b/COMET.Web.Common/Components/BookEditor/InputEditor.razor index 37eda25a..c5c67448 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor @@ -28,7 +28,7 @@ @typeparam TItem
- @if (this.Item is INamedThing namedThing && this.showName) + @if (this.Item is INamedThing namedThing && this.ShowName) {

Name:

@@ -36,7 +36,7 @@
} - @if (this.Item is IShortNamedThing shortNamedThing && this.showShortName) + @if (this.Item is IShortNamedThing shortNamedThing && this.ShowShortName) {

ShortName:

diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs index 4021b281..5fb6dd0c 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs @@ -27,6 +27,7 @@ namespace COMET.Web.Common.Components.BookEditor { using System.Text.Json; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; @@ -49,18 +50,6 @@ public partial class InputEditor [Inject] public ILogger> Logger { get; set; } - /// - /// Gets or sets the - /// - [Inject] - public HttpClient HttpClient { get; set; } - - /// - /// Gets or sets the - /// - [Inject] - public IOptions Options { get; set; } - /// /// Gets or sets the /// @@ -84,27 +73,19 @@ public partial class InputEditor ///
[Parameter] public IEnumerable AvailableCategories { get; set; } - - /// - /// Sets if the component should show the name field - /// - private bool showName; - - /// - /// The name of the ShowName property on the configuration file - /// - private const string showNameConfigurationProperty = "ShowName"; - + /// - /// Sets if the component should show the shorname field + /// Gets or sets if the InputEditor should display the Name field /// - private bool showShortName; - + [Parameter] + public bool ShowName { get; set; } + /// - /// The name of the ShowShortName property on the configuration file + /// Gets or sets if the InputEditor should display the ShortName field /// - private const string showShortNameConfigurationProperty = "ShowShortName"; - + [Parameter] + public bool ShowShortName { get; set; } + /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. @@ -117,46 +98,30 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - var jsonFile = this.Options.Value.JsonConfigurationFile ?? "BookInputConfiguration.json"; - try { - var configurations = await this.GetBookInputConfigurationAsync(jsonFile); - - if (configurations.TryGetValue(showNameConfigurationProperty, out var showNameValue)) + if (this.Item is IOwnedThing ownedThing) { - this.showName = showNameValue; + ownedThing.Owner = this.SessionService.Session.ActivePerson.DefaultDomain; } - if (configurations.TryGetValue(showShortNameConfigurationProperty, out var showShortNameValue)) + //Name and ShortName are required fields on the SDK - setting these to - as default, as per request on the ticket. + if (this.Item is INamedThing namedThing && !this.ShowName) { - this.showShortName = showShortNameValue; + namedThing.Name = "-"; } - if (this.Item is IOwnedThing ownedThing) + if (this.Item is IShortNamedThing shortNamedThing && !this.ShowShortName) { - ownedThing.Owner = this.SessionService.Session.ActivePerson.DefaultDomain; + shortNamedThing.ShortName = "-"; } } - catch (Exception e) + catch (Exception ex) { - this.Logger.LogError(e, "Error while getting the configuration file."); + this.Logger.LogError(ex, "Exception while setting default values of the InputEditor."); } } - /// - /// 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; - } - /// /// Handler for when the selected categories changed /// diff --git a/COMET.Web.Common/wwwroot/BookInputConfiguration.json b/COMET.Web.Common/wwwroot/BookInputConfiguration.json index a0c6a76d..e4781159 100644 --- a/COMET.Web.Common/wwwroot/BookInputConfiguration.json +++ b/COMET.Web.Common/wwwroot/BookInputConfiguration.json @@ -1,4 +1,4 @@ { - "ShowName": true, - "ShowShortName" : true + "ShowName": false, + "ShowShortName" : false } diff --git a/COMETwebapp/COMETwebapp.csproj b/COMETwebapp/COMETwebapp.csproj index 5c09b3c2..a77fd4e2 100644 --- a/COMETwebapp/COMETwebapp.csproj +++ b/COMETwebapp/COMETwebapp.csproj @@ -30,4 +30,10 @@ + + + Always + + + diff --git a/COMETwebapp/wwwroot/BookInputConfiguration.json b/COMETwebapp/wwwroot/BookInputConfiguration.json new file mode 100644 index 00000000..e4781159 --- /dev/null +++ b/COMETwebapp/wwwroot/BookInputConfiguration.json @@ -0,0 +1,4 @@ +{ + "ShowName": false, + "ShowShortName" : false +} From 39368b035723f996b09caedade6a2a798267b2cf Mon Sep 17 00:00:00 2001 From: Robbware Date: Wed, 4 Oct 2023 13:31:31 +0100 Subject: [PATCH 02/13] Cover the HttpClient mocking on the EditorPopup test instead of the InputEditor test --- .../Components/BookEditor/EditotPopupTestFixture.cs | 12 +++++++++++- .../Components/BookEditor/InputEditorTestFixture.cs | 9 --------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs index a0ff55e9..a69ee163 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs @@ -47,6 +47,8 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using NUnit.Framework; + using RichardSzalay.MockHttp; + using TestContext = Bunit.TestContext; [TestFixture] @@ -61,6 +63,8 @@ public class EditotPopupTestFixture private bool onCancelCalled; private bool onAcceptCalled; private Mock sessionService; + private MockHttpMessageHandler mockHttpMessageHandler; + private HttpClient httpClient; [SetUp] public void Setup() @@ -69,7 +73,13 @@ public void Setup() this.context.ConfigureDevExpressBlazor(); this.sessionService = 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.book = new Book(); this.activeDomains = new List diff --git a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs index 1eddac4b..34d64547 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs @@ -57,8 +57,6 @@ public class InputEditorTestFixture private List activeDomains; private List availableCategories; private Mock sessionService; - private MockHttpMessageHandler mockHttpMessageHandler; - private HttpClient httpClient; private const string BookName = "Book Example"; private const string BookShortName = "bookExample"; @@ -69,13 +67,6 @@ public void Setup() this.context.ConfigureDevExpressBlazor(); this.sessionService = 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.activeDomains = new List { From 48436c725bc689e3a9b849590e0bb376e2ad1506 Mon Sep 17 00:00:00 2001 From: Robbware Date: Thu, 5 Oct 2023 11:29:22 +0100 Subject: [PATCH 03/13] Remove unecessary usings and update the default BookInputConfiguration.json --- .../Components/BookEditor/EditotPopupTestFixture.cs | 1 - .../Components/BookEditor/InputEditorTestFixture.cs | 4 ---- COMET.Web.Common/wwwroot/BookInputConfiguration.json | 6 +++--- COMETwebapp/COMETwebapp.csproj | 6 ------ COMETwebapp/wwwroot/BookInputConfiguration.json | 4 ---- 5 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 COMETwebapp/wwwroot/BookInputConfiguration.json diff --git a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs index a69ee163..35d27aa0 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs @@ -36,7 +36,6 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using COMET.Web.Common.ViewModels.Components.BookEditor; using DevExpress.Blazor; - using DevExpress.Blazor.Popup.Internal; using DynamicData; diff --git a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs index 34d64547..8d13aa7d 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs @@ -24,8 +24,6 @@ namespace COMET.Web.Common.Tests.Components.BookEditor { - using System.Text.Json; - using Bunit; using CDP4Common.ReportingData; @@ -44,8 +42,6 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using NUnit.Framework; - using RichardSzalay.MockHttp; - using TestContext = Bunit.TestContext; [TestFixture] diff --git a/COMET.Web.Common/wwwroot/BookInputConfiguration.json b/COMET.Web.Common/wwwroot/BookInputConfiguration.json index e4781159..cd465b2a 100644 --- a/COMET.Web.Common/wwwroot/BookInputConfiguration.json +++ b/COMET.Web.Common/wwwroot/BookInputConfiguration.json @@ -1,4 +1,4 @@ { - "ShowName": false, - "ShowShortName" : false -} + "ShowName": true, + "ShowShortName" : true +} \ No newline at end of file diff --git a/COMETwebapp/COMETwebapp.csproj b/COMETwebapp/COMETwebapp.csproj index a77fd4e2..5c09b3c2 100644 --- a/COMETwebapp/COMETwebapp.csproj +++ b/COMETwebapp/COMETwebapp.csproj @@ -30,10 +30,4 @@ - - - Always - - - diff --git a/COMETwebapp/wwwroot/BookInputConfiguration.json b/COMETwebapp/wwwroot/BookInputConfiguration.json deleted file mode 100644 index e4781159..00000000 --- a/COMETwebapp/wwwroot/BookInputConfiguration.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "ShowName": false, - "ShowShortName" : false -} From 285ea7215cd9740f6559314ec8e7cf9a168d117e Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 5 Oct 2023 13:52:34 +0200 Subject: [PATCH 04/13] version 1.0.24 --- COMET.Web.Common/COMET.Web.Common.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 7bc6e9a0..3377b3f0 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -3,7 +3,7 @@ net7.0 Latest - 1.0.23 + 1.0.24 1.0.0 1.0.0 CDP4 WEB Common @@ -21,7 +21,7 @@ README.md cdp4-icon.png - [ADD] support of Blazor Server + [FIX] Book Input Configuration failure From c324e438422f5f6d6dbd949be44c92de5d54216d Mon Sep 17 00:00:00 2001 From: Robbware Date: Fri, 6 Oct 2023 11:53:26 +0100 Subject: [PATCH 05/13] 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 06/13] 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 07/13] 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)) {