Skip to content

Commit

Permalink
Merge branch 'development' into bug/GL181-login-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all authored Oct 6, 2023
2 parents 5a4084b + 29f2a48 commit 3318248
Show file tree
Hide file tree
Showing 30 changed files with 265 additions and 126 deletions.
4 changes: 4 additions & 0 deletions COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<None Remove="Data\server_configuration_tests.json" />
<Content Include="Data\server_configuration_tests.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ 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;

using DevExpress.Blazor;
using DevExpress.Blazor.Popup.Internal;

using DynamicData;

Expand All @@ -47,6 +48,8 @@ namespace COMET.Web.Common.Tests.Components.BookEditor

using NUnit.Framework;

using RichardSzalay.MockHttp;

using TestContext = Bunit.TestContext;

[TestFixture]
Expand All @@ -61,15 +64,18 @@ public class EditotPopupTestFixture
private bool onCancelCalled;
private bool onAcceptCalled;
private Mock<ISessionService> sessionService;
private Mock<IConfigurationService> configurationService;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();
this.sessionService = new Mock<ISessionService>();
this.configurationService = new Mock<IConfigurationService>();
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();

this.activeDomains = new List<DomainOfExpertise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace COMET.Web.Common.Tests.Components.BookEditor
{
using System.Text.Json;

using Bunit;

using CDP4Common.ReportingData;
Expand All @@ -44,8 +42,6 @@ namespace COMET.Web.Common.Tests.Components.BookEditor

using NUnit.Framework;

using RichardSzalay.MockHttp;

using TestContext = Bunit.TestContext;

[TestFixture]
Expand All @@ -57,8 +53,6 @@ public class InputEditorTestFixture
private List<DomainOfExpertise> activeDomains;
private List<Category> availableCategories;
private Mock<ISessionService> sessionService;
private MockHttpMessageHandler mockHttpMessageHandler;
private HttpClient httpClient;
private const string BookName = "Book Example";
private const string BookShortName = "bookExample";

Expand All @@ -69,13 +63,6 @@ public void Setup()
this.context.ConfigureDevExpressBlazor();
this.sessionService = new Mock<ISessionService>();
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<DomainOfExpertise>
{
Expand All @@ -100,6 +87,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);
});
}

Expand All @@ -119,6 +108,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void Setup()
this.versionService = new Mock<IVersionService>();
this.sessionService = new Mock<ISessionService>();
this.serverConnectionService = new Mock<IConfigurationService>();
this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());
this.sourceList = new SourceList<Iteration>();
this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList);

Expand Down
3 changes: 2 additions & 1 deletion COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void Setup()
{
this.authenticationService = new Mock<IAuthenticationService>();
this.serverConnectionService = new Mock<IConfigurationService>();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,9 +75,11 @@ public void Setup()
sessionService.Setup(x => x.Session).Returns(session.Object);
sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny<Iteration>())).Returns(new DomainOfExpertise(){Iid = Guid.NewGuid()});
this.viewModel.Setup(x => x.SessionService).Returns(sessionService.Object);
var mockConfigurationService = new Mock<IConfigurationService>();
mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());
this.context.Services.AddSingleton(this.viewModel.Object);
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton(new Mock<IConfigurationService>().Object);
this.context.Services.AddSingleton(mockConfigurationService.Object);
this.context.Services.AddSingleton(new Mock<IStringTableService>().Object);
this.context.Services.AddSingleton(sessionService.Object);
this.context.ConfigureDevExpressBlazor();
Expand Down
9 changes: 9 additions & 0 deletions COMET.Web.Common.Tests/Data/server_configuration_tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ServerConfiguration": {
"ServerAddress": "https://a.b.c",
"BookInputConfiguration": {
"ShowName": true,
"ShowShortName": true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"ServerAddress": ""
"ServerAddress": "",
"BookInputConfiguration": {
"ShowName": true,
"ShowShortName": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,66 @@

namespace COMET.Web.Common.Tests.Server.Services.ConfigurationService
{
using COMET.Web.Common.Model.Configuration;
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);
configuration.Setup(x => x.GetSection(ConfigurationService.ServerConfigurationSection)).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);
configuration.Verify(x => x.GetSection(ConfigurationService.ServerConfigurationSection), Times.Once);
Assert.That(service.ServerConfiguration, 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<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);
var serverConfiguration = new ServerConfiguration
{
ServerAddress = "https://a.b.c",
BookInputConfiguration = new BookInputConfiguration()
{
ShowName = true,
ShowShortName = true
}
};

var config = new ConfigurationBuilder()
.AddJsonFile("Data/server_configuration_tests.json")
.Build();

var service = new ConfigurationService(config);
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));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
}
8 changes: 3 additions & 5 deletions COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<Version>1.0.23</Version>
<Version>1.0.26</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<Title>CDP4 WEB Common</Title>
Expand All @@ -21,7 +21,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>cdp4-icon.png</PackageIcon>
<PackageReleaseNotes>
[ADD] support of Blazor Server
[FIX] Reading of ConfigurationFile
</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
Expand All @@ -30,6 +30,7 @@
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="ReactiveUI" Version="18.4.26" />
</ItemGroup>
<ItemGroup>
Expand All @@ -47,9 +48,6 @@
<Content Update="wwwroot\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\BookInputConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\server_configuration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/Components/BookEditor/EditorPopup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<DxPopup @bind-Visible="@this.ViewModel.IsVisible" CloseOnOutsideClick="false" ShowCloseButton="true" ShowFooter="true" HeaderText="@this.ViewModel.HeaderText" Closed="@(()=> this.ViewModel.OnCancelClick.InvokeAsync())">
<Content>
<InputEditor Item="@this.ViewModel.Item" ActiveDomains="@this.ViewModel.ActiveDomains" AvailableCategories="@this.ViewModel.AvailableCategories" />
<InputEditor Item="@this.ViewModel.Item" ActiveDomains="@this.ViewModel.ActiveDomains" AvailableCategories="@this.ViewModel.AvailableCategories" ShowName="@this.showName" ShowShortName="@this.showShortName" />
<div style="display:flex; flex-direction:column">
@foreach (var validationError in this.ViewModel.ValidationErrors.Items)
{
Expand Down
Loading

0 comments on commit 3318248

Please sign in to comment.