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
66 changes: 56 additions & 10 deletions SysML2.NET.Tests/Extend/ActorMembershipExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,84 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="ActorMembershipExtensionsTestFixture.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.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.Parts;
using SysML2.NET.Core.POCO.Systems.Requirements;
using SysML2.NET.Exceptions;
using SysML2.NET.Extensions;

[TestFixture]
public class ActorMembershipExtensionsTestFixture
{
[Test]
public void ComputeOwnedActorParameter_ThrowsNotSupportedException()
public void VerifyComputeOwnedActorParameter()
{
Assert.That(() => ((IActorMembership)null).ComputeOwnedActorParameter(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IActorMembership)null).ComputeOwnedActorParameter(), Throws.TypeOf<ArgumentNullException>());

// Empty OwnedRelatedElement → [1..1] violation: throws IncompleteModelException.
var emptyMembership = new ActorMembership();

Assert.That(() => emptyMembership.ComputeOwnedActorParameter(), Throws.TypeOf<IncompleteModelException>());

// Single non-IPartUsage in OwnedRelatedElement → [1..1] violation: throws IncompleteModelException.
var nonPartMembership = new ActorMembership();
var nonPartElement = new Namespace();
((IContainedRelationship)nonPartMembership).OwnedRelatedElement.Add(nonPartElement);

Assert.That(() => nonPartMembership.ComputeOwnedActorParameter(), Throws.TypeOf<IncompleteModelException>());

// Single IPartUsage wired via the public API → returned.
// ActorMembership is a FeatureMembership and requires an IType source per AssignOwnership;
// RequirementDefinition is the natural Requirements-namespace IType for an actor parameter.
var owningDefinition = new RequirementDefinition();
var actorMembership = new ActorMembership();
var partUsage = new PartUsage();
owningDefinition.AssignOwnership(actorMembership, partUsage);

Assert.That(actorMembership.ComputeOwnedActorParameter(), Is.SameAs(partUsage));

// Two IPartUsage in OwnedRelatedElement → [1..1] violation: throws IncompleteModelException.
var twoPartMembership = new ActorMembership();
var firstPart = new PartUsage();
var secondPart = new PartUsage();
((IContainedRelationship)twoPartMembership).OwnedRelatedElement.Add(firstPart);
((IContainedRelationship)twoPartMembership).OwnedRelatedElement.Add(secondPart);

Assert.That(() => twoPartMembership.ComputeOwnedActorParameter(), Throws.TypeOf<IncompleteModelException>());

// Mixed: non-IPartUsage (Namespace) alongside a single IPartUsage — the type filter picks
// out the PartUsage regardless of its position.
var mixedMembership = new ActorMembership();
var siblingNamespace = new Namespace();
var mixedPart = new PartUsage();
((IContainedRelationship)mixedMembership).OwnedRelatedElement.Add(siblingNamespace);
((IContainedRelationship)mixedMembership).OwnedRelatedElement.Add(mixedPart);

Assert.That(mixedMembership.ComputeOwnedActorParameter(), Is.SameAs(mixedPart));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,65 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="AssertConstraintUsageExtensionsTestFixture.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.Systems.Constraints ;
using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Systems.Constraints;
using SysML2.NET.Core.POCO.Systems.Parts;
using SysML2.NET.Extensions;

[TestFixture]
public class AssertConstraintUsageExtensionsTestFixture
{
[Test]
public void ComputeAssertedConstraint_ThrowsNotSupportedException()
public void VerifyComputeAssertedConstraint()
{
Assert.That(() => ((IAssertConstraintUsage)null).ComputeAssertedConstraint(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAssertConstraintUsage)null).ComputeAssertedConstraint(), Throws.TypeOf<ArgumentNullException>());

// No ownedReferenceSubsetting → ReferencedFeatureTarget() returns null →
// self-fallback branch: returns the subject itself (which IS-A IConstraintUsage).
var selfFallbackUsage = new AssertConstraintUsage();

Assert.That(selfFallbackUsage.ComputeAssertedConstraint(), Is.SameAs(selfFallbackUsage));

// ownedReferenceSubsetting points to a ConstraintUsage → that ConstraintUsage is returned
// (since the referenced feature's featureTarget is itself when it has no chainingFeatures).
var withConstraintRefUsage = new AssertConstraintUsage();
var targetConstraint = new ConstraintUsage();
var referenceSubsetting = new ReferenceSubsetting { ReferencedFeature = targetConstraint };
withConstraintRefUsage.AssignOwnership(referenceSubsetting);

Assert.That(withConstraintRefUsage.ComputeAssertedConstraint(), Is.SameAs(targetConstraint));

// ownedReferenceSubsetting points to a non-ConstraintUsage feature → the "as IConstraintUsage"
// cast yields null (the OCL "else null" branch).
var withNonConstraintRefUsage = new AssertConstraintUsage();
var nonConstraintTarget = new PartUsage();
var nonConstraintRefSubsetting = new ReferenceSubsetting { ReferencedFeature = nonConstraintTarget };
withNonConstraintRefUsage.AssignOwnership(nonConstraintRefSubsetting);

Assert.That(withNonConstraintRefUsage.ComputeAssertedConstraint(), Is.Null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public void VerifyComputeActorParameter()

Assert.That(caseDefinition.ComputeActorParameter(), Is.Empty);

// For Later: populated case depends on IActorMembership.ComputeOwnedActorParameter, which is still a stub.
// Populated: an ActorMembership carrying a PartUsage → that PartUsage appears in the result.
var actorMembership = new ActorMembership();
var actorPartUsage = new PartUsage();
caseDefinition.AssignOwnership(actorMembership, actorPartUsage);

Assert.That(() => caseDefinition.ComputeActorParameter(), Throws.TypeOf<NotSupportedException>());
Assert.That(caseDefinition.ComputeActorParameter(), Is.EqualTo([actorPartUsage]));
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions SysML2.NET.Tests/Extend/CaseUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void VerifyComputeActorParameter()

Assert.That(caseUsage.ComputeActorParameter(), Is.Empty);

// For Later: populated case depends on IActorMembership.ComputeOwnedActorParameter, which is still a stub.
// Populated: an ActorMembership carrying a PartUsage → that PartUsage appears in the result.
var actorMembership = new ActorMembership();
var actorPartUsage = new PartUsage();
caseUsage.AssignOwnership(actorMembership, actorPartUsage);

Assert.That(() => caseUsage.ComputeActorParameter(), Throws.TypeOf<NotSupportedException>());
Assert.That(caseUsage.ComputeActorParameter(), Is.EqualTo([actorPartUsage]));
}

[Test]
Expand Down
105 changes: 95 additions & 10 deletions SysML2.NET.Tests/Extend/ConstraintUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,123 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="ConstraintUsageExtensionsTestFixture.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.Kernel.Functions;
using SysML2.NET.Core.POCO.Systems.Constraints;
using SysML2.NET.Core.POCO.Systems.Parts;
using SysML2.NET.Core.POCO.Systems.Requirements;
using SysML2.NET.Extensions;

[TestFixture]
public class ConstraintUsageExtensionsTestFixture
{
[Test]
public void ComputeConstraintDefinition_ThrowsNotSupportedException()
public void VerifyComputeConstraintDefinition()
{
Assert.That(() => ((IConstraintUsage)null).ComputeConstraintDefinition(), Throws.TypeOf<ArgumentNullException>());

// Empty OwnedRelationship → no FeatureTyping → null.
var emptyUsage = new ConstraintUsage();

Assert.That(emptyUsage.ComputeConstraintDefinition(), Is.Null);

// FeatureTyping whose Type is a non-Predicate → returns null (no IPredicate match).
var nonPredicateUsage = new ConstraintUsage();
var partDefinition = new PartDefinition();
var nonPredicateTyping = new FeatureTyping { Type = partDefinition };
nonPredicateUsage.AssignOwnership(nonPredicateTyping);

Assert.That(nonPredicateUsage.ComputeConstraintDefinition(), Is.Null);

// FeatureTyping whose Type is a Predicate → returns it.
var predicateUsage = new ConstraintUsage();
var predicate = new Predicate();
var predicateTyping = new FeatureTyping { Type = predicate };
predicateUsage.AssignOwnership(predicateTyping);

Assert.That(predicateUsage.ComputeConstraintDefinition(), Is.SameAs(predicate));

// FeatureTyping whose Type is a ConstraintDefinition (which IS-A Predicate) → returns it.
var constraintDefUsage = new ConstraintUsage();
var constraintDefinition = new ConstraintDefinition();
var constraintDefTyping = new FeatureTyping { Type = constraintDefinition };
constraintDefUsage.AssignOwnership(constraintDefTyping);

Assert.That(constraintDefUsage.ComputeConstraintDefinition(), Is.SameAs(constraintDefinition));
}

[Test]
public void VerifyComputeRedefinedNamingFeatureOperation()
{
Assert.That(() => ((IConstraintUsage)null).ComputeConstraintDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IConstraintUsage)null).ComputeRedefinedNamingFeatureOperation(), Throws.TypeOf<ArgumentNullException>());

// No owningFeatureMembership → else branch delegates to UsageExtensions.ComputeRedefinedNamingFeatureOperation.
// With no OwnedRelationship (no Redefinition) and not a VariantMembership → null.
var elseFallbackUsage = new ConstraintUsage();

Assert.That(elseFallbackUsage.ComputeRedefinedNamingFeatureOperation(), Is.Null);

// owningFeatureMembership IS a RequirementConstraintMembership AND ownedReferenceSubsetting present →
// returns ownedReferenceSubsetting.ReferencedFeature.featureTarget (which is itself for a feature
// with no chainingFeatures).
var owningRequirementUsage = new RequirementUsage();
var requirementConstraintMembership = new RequirementConstraintMembership();
var usageInBranch1 = new ConstraintUsage();
owningRequirementUsage.AssignOwnership(requirementConstraintMembership, usageInBranch1);

var refTarget = new Feature();
var referenceSubsetting = new ReferenceSubsetting { ReferencedFeature = refTarget };
usageInBranch1.AssignOwnership(referenceSubsetting);

Assert.That(usageInBranch1.ComputeRedefinedNamingFeatureOperation(), Is.SameAs(refTarget));

// owningFeatureMembership is RequirementConstraintMembership but NO ownedReferenceSubsetting →
// condition fails → else branch → returns null (no Redefinition).
var owningRequirementUsage2 = new RequirementUsage();
var rcmNoRef = new RequirementConstraintMembership();
var usageNoRef = new ConstraintUsage();
owningRequirementUsage2.AssignOwnership(rcmNoRef, usageNoRef);

Assert.That(usageNoRef.ComputeRedefinedNamingFeatureOperation(), Is.Null);
}

[Test]
public void VerifyComputeRedefinedModelLevelEvaluableOperation()
{
Assert.That(() => ((IConstraintUsage)null).ComputeRedefinedModelLevelEvaluableOperation([]), Throws.TypeOf<ArgumentNullException>());

// OCL body is literally `false` — independent of subject state and of the visited list.
var usage = new ConstraintUsage();

using (Assert.EnterMultipleScope())
{
Assert.That(usage.ComputeRedefinedModelLevelEvaluableOperation([]), Is.False);
Assert.That(usage.ComputeRedefinedModelLevelEvaluableOperation(null), Is.False);
Assert.That(usage.ComputeRedefinedModelLevelEvaluableOperation([new Feature()]), Is.False);
}
}
}
}
Loading
Loading