diff --git a/COMET.Web.Common.Tests/Extensions/SessionServiceExtensionsTestFixture.cs b/COMET.Web.Common.Tests/Extensions/SessionServiceExtensionsTestFixture.cs new file mode 100644 index 00000000..c946fbec --- /dev/null +++ b/COMET.Web.Common.Tests/Extensions/SessionServiceExtensionsTestFixture.cs @@ -0,0 +1,91 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// 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. +// +// 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. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Extensions +{ + using CDP4Common.EngineeringModelData; + using CDP4Common.SiteDirectoryData; + + using CDP4Dal; + using CDP4Dal.Operations; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.Services.SessionManagement; + using Microsoft.Extensions.Logging; + using Moq; + using NUnit.Framework; + + [TestFixture] + public class SessionServiceExtensionsTestFixture + { + private Mock session; + private ISessionService sessionService; + + [SetUp] + public void Setup() + { + var logger = new Mock>(); + + this.session = new Mock(); + this.sessionService = new SessionService(logger.Object) + { + Session = this.session.Object + }; + } + + [Test] + public void VerifyAddParameter() + { + var model = new EngineeringModel(); + var iterationSetup = new IterationSetup(); + var iteration = new Iteration() + { + IterationSetup = iterationSetup, + Container = model + }; + model.Iteration.Add(iteration); + + var elementDefinition = new ElementDefinition(); + iteration.Element.Add(elementDefinition); + + var textParameterType = new TextParameterType(); + + var doe = new DomainOfExpertise() + { + Name = "doe", + ShortName = "doe" + }; + + Assert.Multiple(() => + { + Assert.That(() => this.sessionService.AddParameter(null, null, null, null, null), Throws.ArgumentNullException); + Assert.That(() => this.sessionService.AddParameter(elementDefinition, null, null, null, null), Throws.ArgumentNullException); + Assert.That(() => this.sessionService.AddParameter(elementDefinition, null, textParameterType, null, null), Throws.ArgumentNullException); + Assert.That(() => this.sessionService.AddParameter(elementDefinition, null, textParameterType, null, doe), Throws.Nothing); + }); + + this.session.Verify(x => x.Write(It.IsAny()), Times.Once); + } + } +} diff --git a/COMET.Web.Common/Extensions/SessionServiceExtensions.cs b/COMET.Web.Common/Extensions/SessionServiceExtensions.cs index b08eedd1..821d0f4c 100644 --- a/COMET.Web.Common/Extensions/SessionServiceExtensions.cs +++ b/COMET.Web.Common/Extensions/SessionServiceExtensions.cs @@ -36,27 +36,6 @@ namespace COMET.Web.Common.Extensions /// public static class SessionServiceExtensions { - /// - /// Marks a top element for a given iteration - /// - /// The in which the iteration will be updated - /// The to be updated - /// The to be marked as top element - /// A - /// Throws an - public static async Task MarkTopElement(this ISessionService sessionService, Iteration iteration, ElementDefinition element) - { - if (iteration == null) - { - throw new ArgumentNullException(nameof(iteration)); - } - - var iterationClone = iteration.Clone(false); - iterationClone.TopElement = element; - - return await sessionService.UpdateThing(iteration.Container, iterationClone); - } - /// /// Adds a new parameter for a given element definition ///