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
43 changes: 43 additions & 0 deletions SysML2.NET.Tests/Extend/LibraryPackageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="LibraryPackageExtensionsTestFixture.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.Kernel.Packages;

[TestFixture]
public class LibraryPackageExtensionsTestFixture
{
[Test]
public void VerifyComputeRedefinedLibraryNamespaceOperation()
{
Assert.That(() => ((ILibraryPackage)null).ComputeRedefinedLibraryNamespaceOperation(), Throws.TypeOf<ArgumentNullException>());

// The libraryNamespace of a LibraryPackage is itself (OCL: self) -> reference identity.
var subject = new LibraryPackage();

Assert.That(subject.ComputeRedefinedLibraryNamespaceOperation(), Is.SameAs(subject));
}
}
}
96 changes: 96 additions & 0 deletions SysML2.NET.Tests/Extend/MembershipImportExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="MembershipImportExtensionsTestFixture.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.Root.Namespaces;
using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Extensions;

[TestFixture]
public class MembershipImportExtensionsTestFixture
{
[Test]
public void VerifyComputeRedefinedImportedMembershipsOperation()
{
Assert.That(() => ((IMembershipImport)null).ComputeRedefinedImportedMembershipsOperation([]), Throws.TypeOf<ArgumentNullException>());

// Not recursive: importedElement IS a Namespace but recursion is suppressed -> [importedMembership] only.
var notRecursiveMemberNamespace = new Namespace();
var notRecursiveImportedMembership = new Membership { MemberElement = notRecursiveMemberNamespace };
var notRecursiveSubject = new MembershipImport { ImportedMembership = notRecursiveImportedMembership, IsRecursive = false };

var notRecursiveResult = notRecursiveSubject.ComputeRedefinedImportedMembershipsOperation([]);

using (Assert.EnterMultipleScope())
{
Assert.That(notRecursiveResult, Has.Count.EqualTo(1));
Assert.That(notRecursiveResult, Does.Contain(notRecursiveImportedMembership));
}

// Recursive, but importedElement is NOT a Namespace (a Comment) -> [importedMembership] only.
var nonNamespaceImportedMembership = new Membership { MemberElement = new Comment() };
var nonNamespaceSubject = new MembershipImport { ImportedMembership = nonNamespaceImportedMembership, IsRecursive = true };

var nonNamespaceResult = nonNamespaceSubject.ComputeRedefinedImportedMembershipsOperation([]);

using (Assert.EnterMultipleScope())
{
Assert.That(nonNamespaceResult, Has.Count.EqualTo(1));
Assert.That(nonNamespaceResult, Does.Contain(nonNamespaceImportedMembership));
}

// Recursive + importedElement IS a Namespace but that Namespace is in excluded -> [importedMembership] only.
var excludedNamespace = new Namespace();
var excludedImportedMembership = new Membership { MemberElement = excludedNamespace };
var excludedSubject = new MembershipImport { ImportedMembership = excludedImportedMembership, IsRecursive = true };

var excludedResult = excludedSubject.ComputeRedefinedImportedMembershipsOperation([excludedNamespace]);

using (Assert.EnterMultipleScope())
{
Assert.That(excludedResult, Has.Count.EqualTo(1));
Assert.That(excludedResult, Does.Contain(excludedImportedMembership));
}

// Recursive + importedElement IS a Namespace with a public visible membership, not excluded ->
// importedMembership FIRST, then the imported namespace's visibleMemberships appended.
var importedNamespace = new Namespace();
var visibleMembership = new OwningMembership { Visibility = VisibilityKind.Public };
importedNamespace.AssignOwnership(visibleMembership, new Namespace());

var recursiveImportedMembership = new Membership { MemberElement = importedNamespace };
var recursiveSubject = new MembershipImport { ImportedMembership = recursiveImportedMembership, IsRecursive = true, IsImportAll = false };

var recursiveResult = recursiveSubject.ComputeRedefinedImportedMembershipsOperation([]);

using (Assert.EnterMultipleScope())
{
Assert.That(recursiveResult[0], Is.SameAs(recursiveImportedMembership));
Assert.That(recursiveResult, Does.Contain(visibleMembership));
}
}
}
}
14 changes: 11 additions & 3 deletions SysML2.NET.Tests/Extend/PackageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,23 @@ public void VerifyComputeRedefinedImportedMembershipsOperation()

Assert.That(package.ComputeRedefinedImportedMembershipsOperation([]), Is.Empty);

var importMember = new MembershipImport();
// Valid MembershipImport (ImportedMembership wired to a real membership) with no
// filterConditions: MembershipImport.importedMemberships is non-recursive, so it yields
// [importedMembership]; Package.importedMemberships aggregates it and, absent any
// ElementFilterMembership, ComputeRedefinedImportedMembershipsOperation returns it as-is.
var importedMemberNamespace = new Namespace();
var importedMembership = new Membership { MemberElement = importedMemberNamespace };
var importMember = new MembershipImport { ImportedMembership = importedMembership, IsRecursive = false };

package.AssignOwnership(importMember);
Assert.That(() => package.ComputeRedefinedImportedMembershipsOperation([]), Throws.InstanceOf<NotSupportedException>());
Assert.That(package.ComputeRedefinedImportedMembershipsOperation([]), Does.Contain(importedMembership));

// Discrimination: a bare BooleanExpression filterCondition evaluates to [] → CheckCondition
// returns false → the imported membership fails the filter and is excluded → empty result.
var membership = new ElementFilterMembership();
var expression = new BooleanExpression();
package.AssignOwnership(membership, expression);
Assert.That(() => package.ComputeRedefinedImportedMembershipsOperation([]), Throws.InstanceOf<NotSupportedException>());
Assert.That(package.ComputeRedefinedImportedMembershipsOperation([]), Is.Empty);
}
}
}
22 changes: 13 additions & 9 deletions SysML2.NET.Tests/Extend/ViewUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ public void VerifyComputeExposedElement()

Assert.That(viewUsage.ComputeExposedElement(), Is.Empty);

// STUB-BLOCKER: adding a MembershipExpose dispatches ComputeExposedElement to
// MembershipExpose.ImportedMemberships(excluded), which calls
// MembershipImportExtensions.ComputeRedefinedImportedMembershipsOperation — a
// NotSupportedException stub. The populated positive case cannot be tested until that
// upstream stub is implemented.
var membershipExpose = new MembershipExpose();
viewUsage.AssignOwnership(membershipExpose);

Assert.That(viewUsage.ComputeExposedElement, Throws.TypeOf<NotSupportedException>());
// Positive: a valid MembershipExpose (ImportedMembership wired to a real membership whose
// memberElement is exposable) routes through the now-implemented
// MembershipImport.importedMemberships. Non-recursive → [importedMembership]; its
// memberElement surfaces and, with no ElementFilterMembership conditions, passes
// includeAsExposed → the exposed element is returned. Uses a fresh ViewUsage so the
// positive path is not contaminated by the deliberately-minimal discrimination import above.
var positiveViewUsage = new ViewUsage();
var exposedElement = new Feature();
var exposeImportedMembership = new Membership { MemberElement = exposedElement };
var membershipExpose = new MembershipExpose { ImportedMembership = exposeImportedMembership, IsRecursive = false };
positiveViewUsage.AssignOwnership(membershipExpose);

Assert.That(positiveViewUsage.ComputeExposedElement(), Does.Contain(exposedElement));
}

[Test]
Expand Down
8 changes: 6 additions & 2 deletions SysML2.NET/Extend/LibraryPackageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@
/// <returns>
/// The expected <see cref="INamespace" />
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static INamespace ComputeRedefinedLibraryNamespaceOperation(this ILibraryPackage libraryPackageSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
if (libraryPackageSubject == null)
{
throw new ArgumentNullException(nameof(libraryPackageSubject));
}

Check warning on line 58 in SysML2.NET/Extend/LibraryPackageExtensions.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-4ngycYuAVA4MGlB9O&open=AZ-4ngycYuAVA4MGlB9O&pullRequest=332

return libraryPackageSubject;
}
}
}
17 changes: 15 additions & 2 deletions SysML2.NET/Extend/MembershipImportExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@
/// <returns>
/// The expected collection of <see cref="IMembership" />
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List<IMembership> ComputeRedefinedImportedMembershipsOperation(this IMembershipImport membershipImportSubject, List<INamespace> excluded)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
if (membershipImportSubject == null)
{
throw new ArgumentNullException(nameof(membershipImportSubject));
}

Check warning on line 68 in SysML2.NET/Extend/MembershipImportExtensions.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-4ngxwYuAVA4MGlB9N&open=AZ-4ngxwYuAVA4MGlB9N&pullRequest=332

if (!membershipImportSubject.IsRecursive
|| membershipImportSubject.importedElement is not INamespace importedNamespace
|| excluded.Contains(importedNamespace))
{
return [membershipImportSubject.ImportedMembership];
}

var visibleMemberships = importedNamespace.VisibleMemberships(excluded, true, membershipImportSubject.IsImportAll);

return [membershipImportSubject.ImportedMembership, .. visibleMemberships];
}
}
}
Loading