Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,38 +1,56 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="ConjugatedPortTypingExtensionsTestFixture.cs" company="Starion Group S.A.">
//
//
// Copyright 2022-2026 Starion Group S.A.
//
//
// 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 SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.Ports;
using SysML2.NET.Extensions;

[TestFixture]
public class ConjugatedPortTypingExtensionsTestFixture
{
[Test]
public void ComputePortDefinition_ThrowsNotSupportedException()
public void VerifyComputePortDefinition()
{
Assert.That(() => ((IConjugatedPortTyping)null).ComputePortDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IConjugatedPortTyping)null).ComputePortDefinition(), Throws.TypeOf<ArgumentNullException>());

// No ConjugatedPortDefinition -> the null-safe navigation short-circuits to null.
var emptyConjugatedPortTyping = new ConjugatedPortTyping();

Assert.That(emptyConjugatedPortTyping.ComputePortDefinition(), Is.Null);

// Positive case: the ConjugatedPortDefinition's originalPortDefinition derives from its
// owningMembership -> membershipOwningNamespace, which must be a PortDefinition. Wire that
// ownership chain so originalPortDefinition (and thus portDefinition) resolves to the original.
var originalPortDefinition = new PortDefinition();
var conjugatedPortDefinition = new ConjugatedPortDefinition();
originalPortDefinition.AssignOwnership(new OwningMembership(), conjugatedPortDefinition);

var conjugatedPortTyping = new ConjugatedPortTyping { ConjugatedPortDefinition = conjugatedPortDefinition };

Assert.That(conjugatedPortTyping.ComputePortDefinition(), Is.SameAs(originalPortDefinition));
}
}
}
82 changes: 82 additions & 0 deletions SysML2.NET.Tests/Extend/ControlNodeExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ControlNodeExtensionsTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2022-2026 Starion Group S.A.
//
// 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 SysML2.NET.Tests.Extend
{
using System;

using Moq;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Kernel.Multiplicities;
using SysML2.NET.Core.POCO.Systems.Actions;

[TestFixture]
public class ControlNodeExtensionsTestFixture
{
[Test]
public void VerifyComputeMultiplicityHasBoundsOperation()
{
// ControlNode is abstract; ForkNode is a concrete IControlNode used as the subject.
var controlNode = new ForkNode();

Assert.That(() => ((IControlNode)null).ComputeMultiplicityHasBoundsOperation(null, 1, "1"), Throws.TypeOf<ArgumentNullException>());

// mult == null -> false (the OCL "mult <> null" guard, not a throw).
Assert.That(controlNode.ComputeMultiplicityHasBoundsOperation(null, 1, "1"), Is.False);

// mult IS a MultiplicityRange -> the direct branch delegates to HasBounds(lower, upper).
var range = new Mock<IMultiplicityRange>();
range.Setup(x => x.HasBounds(1, "5")).Returns(true);

using (Assert.EnterMultipleScope())
{
Assert.That(controlNode.ComputeMultiplicityHasBoundsOperation(range.Object, 1, "5"), Is.True);

// Bounds that were not set up return Moq's default (false).
Assert.That(controlNode.ComputeMultiplicityHasBoundsOperation(range.Object, 0, "5"), Is.False);
}

// mult is a plain Multiplicity (NOT a MultiplicityRange) -> the supertype branch searches
// AllSupertypes() for a MultiplicityRange whose HasBounds(lower, upper) is true.
var rangeSupertype = new Mock<IMultiplicityRange>();
rangeSupertype.Setup(x => x.HasBounds(1, "5")).Returns(true);

var multiplicityWithRangeSupertype = new Mock<IMultiplicity>();
multiplicityWithRangeSupertype.Setup(x => x.AllSupertypes()).Returns([rangeSupertype.Object]);

var multiplicityWithoutRangeSupertype = new Mock<IMultiplicity>();
multiplicityWithoutRangeSupertype.Setup(x => x.AllSupertypes()).Returns([]);

using (Assert.EnterMultipleScope())
{
Assert.That(controlNode.ComputeMultiplicityHasBoundsOperation(multiplicityWithRangeSupertype.Object, 1, "5"), Is.True);

// A matching MultiplicityRange supertype exists, but the requested bounds do not match.
Assert.That(controlNode.ComputeMultiplicityHasBoundsOperation(multiplicityWithRangeSupertype.Object, 0, "5"), Is.False);

// No MultiplicityRange among the supertypes -> false.
Assert.That(controlNode.ComputeMultiplicityHasBoundsOperation(multiplicityWithoutRangeSupertype.Object, 1, "5"), Is.False);
}
}
}
}
39 changes: 29 additions & 10 deletions SysML2.NET.Tests/Extend/FeatureTypingExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="FeatureTypingExtensionsTestFixture.cs" company="Starion Group S.A.">
//
//
// Copyright 2022-2026 Starion Group S.A.
//
//
// 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 SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;

[TestFixture]
public class FeatureTypingExtensionsTestFixture
{
[Test]
public void ComputeOwningFeature_ThrowsNotSupportedException()
public void VerifyComputeOwningFeature()
{
Assert.That(() => ((IFeatureTyping)null).ComputeOwningFeature(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IFeatureTyping)null).ComputeOwningFeature(), Throws.TypeOf<ArgumentNullException>());

var featureTyping = new FeatureTyping();

Assert.That(featureTyping.ComputeOwningFeature(), Is.Null);

var feature = new Feature();

((IContainedRelationship)featureTyping).OwningRelatedElement = feature;

Assert.That(featureTyping.ComputeOwningFeature(), Is.SameAs(feature));

var namespaceOwner = new Namespace();
var nonFeatureFeatureTyping = new FeatureTyping();

((IContainedRelationship)nonFeatureFeatureTyping).OwningRelatedElement = namespaceOwner;

Assert.That(nonFeatureFeatureTyping.ComputeOwningFeature(), Is.Null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ReturnParameterMembershipExtensionsTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2022-2026 Starion Group S.A.
//
// 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 SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.POCO.Kernel.Functions;

[TestFixture]
public class ReturnParameterMembershipExtensionsTestFixture
{
[Test]
public void VerifyComputeRedefinedParameterDirectionOperation()
{
Assert.That(() => ((IReturnParameterMembership)null).ComputeRedefinedParameterDirectionOperation(), Throws.TypeOf<ArgumentNullException>());

var returnParameterMembership = new ReturnParameterMembership();

Assert.That(returnParameterMembership.ComputeRedefinedParameterDirectionOperation(), Is.EqualTo(FeatureDirectionKind.Out));
}
}
}
5 changes: 3 additions & 2 deletions SysML2.NET/Extend/ConjugatedPortTypingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ internal static class ConjugatedPortTypingExtensions
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IPortDefinition ComputePortDefinition(this IConjugatedPortTyping conjugatedPortTypingSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return conjugatedPortTypingSubject == null
? throw new ArgumentNullException(nameof(conjugatedPortTypingSubject))
: conjugatedPortTypingSubject.ConjugatedPortDefinition?.originalPortDefinition;
}

}
Expand Down
13 changes: 11 additions & 2 deletions SysML2.NET/Extend/ControlNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
{
using System;
using System.Collections.Generic;
using System.Linq;

using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
using SysML2.NET.Core.Systems.Occurrences;
using SysML2.NET.Core.POCO.Kernel.Multiplicities;
using SysML2.NET.Core.POCO.Core.Classifiers;
using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Core.Types;
Expand Down Expand Up @@ -95,10 +97,17 @@
/// <returns>
/// The expected <see cref="bool" />
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static bool ComputeMultiplicityHasBoundsOperation(this IControlNode controlNodeSubject, IMultiplicity mult, int lower, string upper)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
if (controlNodeSubject == null)
{
throw new ArgumentNullException(nameof(controlNodeSubject));
}

Check warning on line 105 in SysML2.NET/Extend/ControlNodeExtensions.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=STARIONGROUP_SysML2.NET&issues=AZ-4cVCE9mhqhps4KKMT&open=AZ-4cVCE9mhqhps4KKMT&pullRequest=331

return mult != null
&& (mult is IMultiplicityRange multiplicityRange
? multiplicityRange.HasBounds(lower, upper)
: mult.AllSupertypes().OfType<IMultiplicityRange>().Any(rangeSupertype => rangeSupertype.HasBounds(lower, upper)));
}
}
}
5 changes: 3 additions & 2 deletions SysML2.NET/Extend/FeatureTypingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ internal static class FeatureTypingExtensions
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IFeature ComputeOwningFeature(this IFeatureTyping featureTypingSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return featureTypingSubject == null
? throw new ArgumentNullException(nameof(featureTypingSubject))
: featureTypingSubject.OwningRelatedElement as IFeature;
}

}
Expand Down
5 changes: 3 additions & 2 deletions SysML2.NET/Extend/ReturnParameterMembershipExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ internal static class ReturnParameterMembershipExtensions
/// <returns>
/// The expected <see cref="FeatureDirectionKind" />
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static FeatureDirectionKind ComputeRedefinedParameterDirectionOperation(this IReturnParameterMembership returnParameterMembershipSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return returnParameterMembershipSubject == null
? throw new ArgumentNullException(nameof(returnParameterMembershipSubject))
: FeatureDirectionKind.Out;
}
}
}
Loading