Skip to content

Commit

Permalink
Add small test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeatstariongroup committed Dec 6, 2023
1 parent 9ccd3ae commit 97e8039
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SessionServiceExtensionsTestFixture.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.
//
// 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

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<ISession> session;
private ISessionService sessionService;

[SetUp]
public void Setup()
{
var logger = new Mock<ILogger<SessionService>>();

this.session = new Mock<ISession>();
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<OperationContainer>()), Times.Once);
}
}
}
21 changes: 0 additions & 21 deletions COMET.Web.Common/Extensions/SessionServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,6 @@ namespace COMET.Web.Common.Extensions
/// </summary>
public static class SessionServiceExtensions
{
/// <summary>
/// Marks a top element for a given iteration
/// </summary>
/// <param name="sessionService">The <see cref="ISessionService"/> in which the iteration will be updated</param>
/// <param name="iteration">The <see cref="Iteration"/> to be updated</param>
/// <param name="element">The <see cref="ElementDefinition"/> to be marked as top element</param>
/// <returns>A <see cref="Task"/></returns>
/// <exception cref="ArgumentNullException">Throws an <see cref="ArgumentException"/></exception>
public static async Task<Result> 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);
}

/// <summary>
/// Adds a new parameter for a given element definition
/// </summary>
Expand Down

0 comments on commit 97e8039

Please sign in to comment.