-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix #477- ApplicationTemplate can be used as is * Unit tests
- Loading branch information
1 parent
f5ebd45
commit 2bb2c85
Showing
8 changed files
with
793 additions
and
613 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
COMET.Web.Common.Tests/Components/Applications/ApplicationTemplateTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="ApplicationTemplateTestFixture.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.Components.Applications | ||
{ | ||
using CDP4Dal; | ||
using CDP4Dal.DAL; | ||
|
||
using COMET.Web.Common.Components.Applications; | ||
using COMET.Web.Common.Model.Configuration; | ||
using COMET.Web.Common.Services.ConfigurationService; | ||
using COMET.Web.Common.Services.SessionManagement; | ||
using COMET.Web.Common.Utilities; | ||
using COMET.Web.Common.ViewModels.Components.Applications; | ||
|
||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using Moq; | ||
|
||
using NUnit.Framework; | ||
|
||
using TestContext = Bunit.TestContext; | ||
|
||
[TestFixture] | ||
public class ApplicationTemplateTestFixture | ||
{ | ||
private TestContext context; | ||
private Mock<IApplicationTemplateViewModel> viewModel; | ||
private Mock<ISessionService> sessionService; | ||
private Mock<IConfigurationService> configurationService; | ||
private ServerConfiguration configuration; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.context = new TestContext(); | ||
this.viewModel = new Mock<IApplicationTemplateViewModel>(); | ||
this.sessionService = new Mock<ISessionService>(); | ||
this.configurationService = new Mock<IConfigurationService>(); | ||
this.configuration = new ServerConfiguration(); | ||
this.configurationService.Setup(x => x.ServerConfiguration).Returns(this.configuration); | ||
this.viewModel.Setup(x => x.SessionService).Returns(this.sessionService.Object); | ||
var session = new Mock<ISession>(); | ||
session.Setup(x => x.DataSourceUri).Returns("abc"); | ||
this.sessionService.Setup(x => x.Session).Returns(session.Object); | ||
this.context.Services.AddSingleton(this.configurationService.Object); | ||
this.context.Services.AddSingleton(this.viewModel.Object); | ||
} | ||
|
||
[Test] | ||
public void VerifyApplicationTemplateWithoutDefinedAddress() | ||
{ | ||
this.context.RenderComponent<ApplicationTemplate>(); | ||
var navigationManager = this.context.Services.GetService<NavigationManager>(); | ||
Assert.That(navigationManager.Uri, Does.Contain($"{QueryKeys.ServerKey}=abc")); | ||
} | ||
|
||
[Test] | ||
public void VerifyApplicationTemplateWithDefinedAddress() | ||
{ | ||
this.configuration.ServerAddress = "abc"; | ||
this.context.RenderComponent<ApplicationTemplate>(); | ||
var navigationManager = this.context.Services.GetService<NavigationManager>(); | ||
Assert.That(navigationManager.Uri, Does.Not.Contain($"{QueryKeys.ServerKey}=abc")); | ||
} | ||
} | ||
} |
29 changes: 14 additions & 15 deletions
29
COMET.Web.Common/Components/Applications/ApplicationTemplate.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
<!------------------------------------------------------------------------------ | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// 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. | ||
// 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 | ||
// 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. | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// 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. | ||
// | ||
// 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. | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
-------------------------------------------------------------------------------> | ||
@namespace COMET.Web.Common.Components.Applications | ||
@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.IApplicationTemplateViewModel | ||
@inherits DisposableComponent | ||
@inherits GenericApplicationTemplate<COMET.Web.Common.ViewModels.Components.Applications.IApplicationTemplateViewModel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
COMET.Web.Common/Components/Applications/GenericApplicationTemplate.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!------------------------------------------------------------------------------ | ||
// 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. | ||
-------------------------------------------------------------------------------> | ||
@namespace COMET.Web.Common.Components.Applications | ||
@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.IApplicationTemplateViewModel | ||
@inherits DisposableComponent |
76 changes: 76 additions & 0 deletions
76
COMET.Web.Common/Components/Applications/GenericApplicationTemplate.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="GenericApplicationTemplate.razor.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.Components.Applications | ||
{ | ||
using COMET.Web.Common.Services.ConfigurationService; | ||
using COMET.Web.Common.Utilities; | ||
using COMET.Web.Common.ViewModels.Components.Applications; | ||
|
||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Shared component that will englobe all applications | ||
/// </summary> | ||
/// <typeparam name="TViewModel">Any <see cref="IApplicationTemplateViewModel"/></typeparam> | ||
public abstract partial class GenericApplicationTemplate<TViewModel> | ||
{ | ||
/// <summary> | ||
/// Body of the application | ||
/// </summary> | ||
[Parameter] | ||
public RenderFragment Body { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or Sets the <typeparamref name="TViewModel" /> | ||
/// </summary> | ||
[Inject] | ||
public TViewModel ViewModel { get; set; } | ||
|
||
/// <summary> | ||
/// The <see cref="NavigationManager" /> | ||
/// </summary> | ||
[Inject] | ||
public NavigationManager NavigationManager { get; set; } | ||
|
||
/// <summary> | ||
/// The <see cref="IConfigurationService" /> | ||
/// </summary> | ||
[Inject] | ||
public IConfigurationService ConfigurationService { get; set; } | ||
|
||
/// <summary> | ||
/// Set URL parameters based on the current context | ||
/// </summary> | ||
/// <param name="currentOptions">A <see cref="Dictionary{TKey,TValue}" /> of URL parameters</param> | ||
protected virtual void SetUrlParameters(Dictionary<string, string> currentOptions) | ||
{ | ||
if (string.IsNullOrEmpty(this.ConfigurationService.ServerConfiguration.ServerAddress)) | ||
{ | ||
currentOptions[QueryKeys.ServerKey] = this.ViewModel.SessionService.Session.DataSourceUri; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.