Skip to content

Commit

Permalink
Fix #457: Supports of Blazor Server
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatrhea committed Oct 3, 2023
1 parent 71a4c6d commit ec1b77e
Show file tree
Hide file tree
Showing 44 changed files with 1,594 additions and 1,155 deletions.
23 changes: 23 additions & 0 deletions COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="Data\DefaultTextConfiguration.json" />
<None Remove="Resources\configuration\DefaultTextConfiguration.json" />
</ItemGroup>

<ItemGroup>
<Content Include="Data\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="Resources\configuration\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.14.4" />
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
Expand All @@ -35,4 +53,9 @@
<ProjectReference Include="..\COMET.Web.Common\COMET.Web.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Server\Services\ConfigurationService\" />
<Folder Include="Server\Services\StringTableService\" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions COMET.Web.Common.Tests/Components/DashboardTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Components;
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.RegistrationService;
using COMET.Web.Common.Services.StringTableService;

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -51,7 +51,7 @@ public class DashboardTestFixture
{
private List<Application> applications;
private Mock<IRegistrationService> registrationService;
private Mock<IConfigurationService> configurationService;
private Mock<IStringTableService> configurationService;
private TestContext context;

[SetUp]
Expand Down Expand Up @@ -83,7 +83,7 @@ public void Setup()
this.registrationService.Setup(x => x.RegisteredApplications)
.Returns(this.applications);

this.configurationService = new Mock<IConfigurationService>();
this.configurationService = new Mock<IStringTableService>();
this.configurationService.Setup(x => x.GetText(TextConfigurationKind.LandingPageTitle)).Returns(string.Empty);

this.context = new TestContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.RegistrationService;
using COMET.Web.Common.Services.ServerConnectionService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.StringTableService;
using COMET.Web.Common.Services.VersionService;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.Utilities;
Expand All @@ -67,7 +67,7 @@ public void Setup()
this.context = new TestContext();
this.versionService = new Mock<IVersionService>();
this.sessionService = new Mock<ISessionService>();
this.serverConnectionService = new Mock<IServerConnectionService>();
this.serverConnectionService = new Mock<IConfigurationService>();
this.sourceList = new SourceList<Iteration>();
this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList);

Expand All @@ -88,7 +88,7 @@ public void Setup()
this.context.ConfigureDevExpressBlazor();
this.authorization = this.context.AddTestAuthorization();

var configurationService = new Mock<IConfigurationService>();
var configurationService = new Mock<IStringTableService>();
configurationService.Setup(x => x.GetText(It.IsAny<string>())).Returns("something");
this.context.Services.AddSingleton(configurationService.Object);
}
Expand All @@ -103,7 +103,7 @@ public void Teardown()
private TestContext context;
private Mock<IVersionService> versionService;
private Mock<ISessionService> sessionService;
private Mock<IServerConnectionService> serverConnectionService;
private Mock<IConfigurationService> serverConnectionService;
private Mock<IAuthenticationService> authenticationService;
private TestAuthorizationContext authorization;
private SourceList<Iteration> sourceList;
Expand Down
6 changes: 3 additions & 3 deletions COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Components;
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Model.DTO;
using COMET.Web.Common.Services.ServerConnectionService;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;
Expand All @@ -50,13 +50,13 @@ public class LoginTestFixture
private ILoginViewModel viewModel;
private TestContext context;
private Mock<IAuthenticationService> authenticationService;
private Mock<IServerConnectionService> serverConnectionService;
private Mock<IConfigurationService> serverConnectionService;

[SetUp]
public void Setup()
{
this.authenticationService = new Mock<IAuthenticationService>();
this.serverConnectionService = new Mock<IServerConnectionService>();
this.serverConnectionService = new Mock<IConfigurationService>();
this.serverConnectionService.Setup(x => x.ServerAddress).Returns("http://localhost.com");
this.context = new TestContext();
this.viewModel = new LoginViewModel(this.authenticationService.Object, this.serverConnectionService.Object);
Expand Down
4 changes: 2 additions & 2 deletions COMET.Web.Common.Tests/Components/OpenModelTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace COMET.Web.Common.Tests.Components
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Components;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.StringTableService;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;

Expand Down Expand Up @@ -65,7 +65,7 @@ public void Setup()
this.context.ConfigureDevExpressBlazor();
this.context.Services.AddSingleton(this.viewModel);

var configurationService = new Mock<IConfigurationService>();
var configurationService = new Mock<IStringTableService>();
this.context.Services.AddSingleton(configurationService.Object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Components.Selectors;
using COMET.Web.Common.Extensions;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.ServerConnectionService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.StringTableService;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.Selectors;
Expand Down Expand Up @@ -76,8 +76,8 @@ public void Setup()
this.viewModel.Setup(x => x.SessionService).Returns(sessionService.Object);
this.context.Services.AddSingleton(this.viewModel.Object);
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton<IServerConnectionService, ServerConnectionService>();
this.context.Services.AddSingleton(new Mock<IConfigurationService>().Object);
this.context.Services.AddSingleton(new Mock<IStringTableService>().Object);
this.context.Services.AddSingleton(sessionService.Object);
this.context.ConfigureDevExpressBlazor();
}
Expand Down
12 changes: 12 additions & 0 deletions COMET.Web.Common.Tests/Data/DefaultTextConfiguration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"OpenEngineeringModelPlaceholder": "Select an Engineering Model",
"OpenIterationPlaceholder": "Select an Iteration",
"OpenDomainOfExpertisePlaceholder": "Select a Domain of Expertise",
"ModelTitleCaption": "Model",
"IterationTitleCaption": "Iteration",
"DomainTitleCaption": "Domain",
"LandingPageTitle": "",
"NavigationApplicationSelectorTitle": "Application",
"NavigationModelSelectorTitle": "Models",
"ModelOpenButtonCaption": "Open Model"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"OpenEngineeringModelPlaceholder": "Select an Engineering Model",
"OpenIterationPlaceholder": "Select an Iteration",
"OpenDomainOfExpertisePlaceholder": "Select a Domain of Expertise",
"ModelTitleCaption": "Model",
"IterationTitleCaption": "Iteration",
"DomainTitleCaption": "Domain",
"LandingPageTitle": "",
"NavigationApplicationSelectorTitle": "Application",
"NavigationModelSelectorTitle": "Models",
"ModelOpenButtonCaption": "Open Model"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ConfigurationServiceTestFixture.cs" company="RHEA System S.A.">
// 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.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService
{
using COMET.Web.Common.Server.Services.ConfigurationService;

using Microsoft.Extensions.Configuration;

using Moq;

using NUnit.Framework;

[TestFixture]
public class ConfigurationServiceTestFixture
{
[Test]
public async Task VerifyInitializeServiceWithEmptyConfiguration()
{
var configuration = new Mock<IConfiguration>();
configuration.Setup(x => x.GetSection(ConfigurationService.AddressSection)).Returns(new Mock<IConfigurationSection>().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);
});

await service.InitializeService();
configuration.Verify(x => x.GetSection(ConfigurationService.AddressSection), Times.Once);
}

[Test]
public async Task VerifyInitializeServiceWithConfiguration()
{
var configurationSection = new Mock<IConfigurationSection>();
configurationSection.Setup(x => x.Value).Returns("https://a.b.c");
var configuration = new Mock<IConfiguration>();
configuration.Setup(x => x.GetSection(ConfigurationService.AddressSection)).Returns(configurationSection.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));
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StringTableServiceTestFixture.cs" company="RHEA System S.A.">
// 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.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Tests.Server.Services.StringTableService
{
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Server.Services.StringTableService;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Abstractions;

using Moq;

using NUnit.Framework;

[TestFixture]
public class StringTableServiceTestFixture
{
[Test]
public async Task VerifyServiceInitialization()
{
var configuration = new Mock<IConfiguration>();
configuration.Setup(x => x["StringTablePath"]).Returns("");

var service = new StringTableService(configuration.Object, NullLogger<StringTableService>.Instance);
await service.InitializeService();
Assert.That(() => service.GetText(TextConfigurationKind.DomainTitleCaption), Throws.Exception);

configuration.Setup(x => x["StringTablePath"]).Returns(Path.Combine("Resources", "configuration", "DefaultTextConfiguration.json"));

service = new StringTableService(configuration.Object, NullLogger<StringTableService>.Instance);
await service.InitializeService();
Assert.That(() => service.GetText(TextConfigurationKind.DomainTitleCaption), Throws.Nothing);
}
}
}
Loading

0 comments on commit ec1b77e

Please sign in to comment.