Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common static server address : Fix #424 #425

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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.VersionService;
using COMET.Web.Common.Test.Helpers;
Expand All @@ -66,6 +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.sourceList = new SourceList<Iteration>();
this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList);

Expand All @@ -79,6 +81,7 @@ public void Setup()
this.context.Services.AddSingleton(this.authenticationService.Object);
this.context.Services.AddSingleton(this.sessionService.Object);
this.context.Services.AddSingleton(this.versionService.Object);
this.context.Services.AddSingleton(this.serverConnectionService.Object);
this.context.Services.AddSingleton<ILoginViewModel, LoginViewModel>();
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton(this.registrationService.Object);
Expand All @@ -100,6 +103,7 @@ public void Teardown()
private TestContext context;
private Mock<IVersionService> versionService;
private Mock<ISessionService> sessionService;
private Mock<IServerConnectionService> serverConnectionService;
private Mock<IAuthenticationService> authenticationService;
private TestAuthorizationContext authorization;
private SourceList<Iteration> sourceList;
Expand Down
6 changes: 5 additions & 1 deletion COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +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.SessionManagement;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;
Expand All @@ -49,13 +50,16 @@ public class LoginTestFixture
private ILoginViewModel viewModel;
private TestContext context;
private Mock<IAuthenticationService> authenticationService;
private Mock<IServerConnectionService> serverConnectionService;

[SetUp]
public void Setup()
{
this.authenticationService = new Mock<IAuthenticationService>();
this.serverConnectionService = new Mock<IServerConnectionService>();
this.serverConnectionService.Setup(x => x.ServerAddress).Returns("http://localhost.com");
this.context = new TestContext();
this.viewModel = new LoginViewModel(this.authenticationService.Object);
this.viewModel = new LoginViewModel(this.authenticationService.Object, this.serverConnectionService.Object);
this.context.Services.AddSingleton(this.viewModel);
this.context.ConfigureDevExpressBlazor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +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.SessionManagement;
using COMET.Web.Common.Services.ServerConnectionService;
nabilatrhea marked this conversation as resolved.
Show resolved Hide resolved
nabilatrhea marked this conversation as resolved.
Show resolved Hide resolved
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.Selectors;
Expand Down Expand Up @@ -75,6 +76,7 @@ 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(sessionService.Object);
this.context.ConfigureDevExpressBlazor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServerConnectionServiceTestFixture.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, Nabil Abbar
//
// 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.Services.ServerConnectionService
{
using System.Net;

using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ServerConnectionService;

using Microsoft.Extensions.Options;

using Moq;
using Moq.Protected;

using NUnit.Framework;

[TestFixture]
public class ServerConnectionServiceTestFixture
{
private IServerConnectionService serverConnectionService;

[Test]
public async Task VerifyService()
{
var globalOptions = new GlobalOptions
{
ServerConfigurationFile = null,
};

var options = new Mock<IOptions<GlobalOptions>>();
options.Setup(x => x.Value).Returns(globalOptions);

var handlerMock = new Mock<HttpMessageHandler>();

var json = """
{
"ServerAddress": "http://localhost:5000/"
}
""";

handlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(json)
})
.Verifiable();

var httpClient = new HttpClient(handlerMock.Object)
{
BaseAddress = new Uri("http://localhost")
};

this.serverConnectionService = new ServerConnectionService(options.Object, httpClient);

Assert.That(this.serverConnectionService, Is.Not.Null);

await this.serverConnectionService.InitializeService();

Assert.Multiple(() =>
{
Assert.That(this.serverConnectionService.ServerAddress, Is.Not.Null);
Assert.That(this.serverConnectionService.ServerAddress, Is.EqualTo("http://localhost:5000/"));
});

handlerMock
nabilatrhea marked this conversation as resolved.
Show resolved Hide resolved
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage
{
StatusCode = HttpStatusCode.NotFound,
})
.Verifiable();

httpClient = new HttpClient(handlerMock.Object)
{
BaseAddress = new Uri("http://localhost")
};

serverConnectionService = new ServerConnectionService(options.Object, httpClient);

await this.serverConnectionService.InitializeService();

Assert.That(this.serverConnectionService.ServerAddress, Is.Null);

handlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage
{
StatusCode = HttpStatusCode.BadRequest,
})
.Verifiable();

httpClient = new HttpClient(handlerMock.Object)
{
BaseAddress = new Uri("http://localhost")
};

serverConnectionService = new ServerConnectionService(options.Object, httpClient);

await this.serverConnectionService.InitializeService();

Assert.That(this.serverConnectionService.ServerAddress, Is.Null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
namespace COMET.Web.Common.Tests.ViewModels.Components
{
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.Selectors;

Expand Down Expand Up @@ -98,9 +98,9 @@ public void VerifySelectIteration()
Iid = Guid.NewGuid(),
IterationSetup = new IterationSetup(Guid.NewGuid(), null, null)
{
IterationNumber = 1,
IterationNumber = 1,
Container = new EngineeringModelSetup(Guid.NewGuid(), null, null)
}
}
},
new ()
{
Expand Down
3 changes: 3 additions & 0 deletions COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
<Content Update="wwwroot\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\server_configuration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
19 changes: 11 additions & 8 deletions COMET.Web.Common/Components/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
<EditForm Context="editFormContext" Model="@(this.ViewModel.AuthenticationDto)" OnValidSubmit="this.ExecuteLogin">
<DataAnnotationsValidator/>
<DxFormLayout CaptionPosition="CaptionPosition.Vertical">
<DxFormLayoutItem Caption="Source Address:" ColSpanLg="12">
<Template>
<DxTextBox Id="sourceaddress" @bind-Text="@(this.ViewModel.AuthenticationDto.SourceAddress)"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
NullText="Enter the url for the server"
Enabled="@string.IsNullOrEmpty(this.RequestedServer)"/>
</Template>
</DxFormLayoutItem>
@if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerAddress))
{
<DxFormLayoutItem Caption="Source Address:" ColSpanLg="12">
<Template>
<DxTextBox Id="sourceaddress" @bind-Text="@(this.ViewModel.AuthenticationDto.SourceAddress)"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
NullText="Enter the url for the server"
Enabled="@string.IsNullOrEmpty(this.RequestedServer)" />
</Template>
</DxFormLayoutItem>
}
<DxFormLayoutItem Caption="UserName:" BeginRow="true" ColSpanLg="12">
<Template>
<DxTextBox Id="username" @bind-Text="@(this.ViewModel.AuthenticationDto.UserName)"
Expand Down
1 change: 1 addition & 0 deletions COMET.Web.Common/Components/Login.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace COMET.Web.Common.Components
{
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Services.ServerConnectionService;
using COMET.Web.Common.ViewModels.Components;

using Microsoft.AspNetCore.Components;
Expand Down
Loading
Loading