diff --git a/COMET.Web.Common.Tests/Components/Applications/ApplicationTemplateTestFixture.cs b/COMET.Web.Common.Tests/Components/Applications/ApplicationTemplateTestFixture.cs new file mode 100644 index 00000000..270e8678 --- /dev/null +++ b/COMET.Web.Common.Tests/Components/Applications/ApplicationTemplateTestFixture.cs @@ -0,0 +1,90 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +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 viewModel; + private Mock sessionService; + private Mock configurationService; + private ServerConfiguration configuration; + + [SetUp] + public void Setup() + { + this.context = new TestContext(); + this.viewModel = new Mock(); + this.sessionService = new Mock(); + this.configurationService = new Mock(); + 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(); + 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(); + var navigationManager = this.context.Services.GetService(); + Assert.That(navigationManager.Uri, Does.Contain($"{QueryKeys.ServerKey}=abc")); + } + + [Test] + public void VerifyApplicationTemplateWithDefinedAddress() + { + this.configuration.ServerAddress = "abc"; + this.context.RenderComponent(); + var navigationManager = this.context.Services.GetService(); + Assert.That(navigationManager.Uri, Does.Not.Contain($"{QueryKeys.ServerKey}=abc")); + } + } +}