diff --git a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs index 35d27aa0..5b7063cb 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs @@ -31,6 +31,8 @@ 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; using COMET.Web.Common.ViewModels.Components.BookEditor; @@ -62,8 +64,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 +72,10 @@ public void Setup() this.context = new TestContext(); 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.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/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/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..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,9 @@ 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; using Microsoft.Extensions.Configuration; @@ -32,7 +35,7 @@ namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService using Moq; using NUnit.Framework; - + [TestFixture] public class ConfigurationServiceTestFixture { @@ -40,34 +43,54 @@ 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.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); - Assert.That(service.ServerAddress, Is.Null); + configuration.Verify(x => x.GetSection(ConfigurationService.ServerConfigurationSection), Times.Once); + 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); + + Assert.Multiple(() => + { + configuration.Verify(x => x.GetSection(ConfigurationService.ServerConfigurationSection), 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(); + + 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(configurationSection.Object); + configuration.Setup(x => x.GetSection(ConfigurationService.ServerConfigurationSection)).Returns(serverAddressMockConfigurationSection.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.ServerConfiguration.ServerAddress, Is.EqualTo(serverConfiguration.ServerAddress)); + Assert.That(service.ServerConfiguration.BookInputConfiguration, Is.Not.Null); + 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.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/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 3377b3f0..57eddb38 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -47,9 +47,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..fecfd28a 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 @@ -73,21 +75,11 @@ public partial class EditorPopup /// 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. @@ -100,40 +92,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"; - - try - { - var configurations = await this.GetBookInputConfigurationAsync(jsonFile); - - if (configurations.TryGetValue(showNameConfigurationProperty, out var showNameValue)) - { - this.showName = showNameValue; - } + var configurations = this.ConfigurationService.ServerConfiguration.BookInputConfiguration; - 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/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)) {