diff --git a/SysML2.NET.Tests/Extend/ExhibitStateUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ExhibitStateUsageExtensionsTestFixture.cs
index e1979b8a..d7a8f342 100644
--- a/SysML2.NET.Tests/Extend/ExhibitStateUsageExtensionsTestFixture.cs
+++ b/SysML2.NET.Tests/Extend/ExhibitStateUsageExtensionsTestFixture.cs
@@ -1,38 +1,60 @@
-// -------------------------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-//
+//
// 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.
-//
+//
//
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Tests.Extend
{
using System;
-
+
using NUnit.Framework;
-
+
+ using SysML2.NET.Core.POCO.Core.Features;
+ using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.States;
+ using SysML2.NET.Extensions;
[TestFixture]
public class ExhibitStateUsageExtensionsTestFixture
{
[Test]
- public void ComputeExhibitedState_ThrowsNotSupportedException()
+ public void VerifyComputeExhibitedState()
{
- Assert.That(() => ((IExhibitStateUsage)null).ComputeExhibitedState(), Throws.TypeOf());
+ Assert.That(() => ((IExhibitStateUsage)null).ComputeExhibitedState(), Throws.TypeOf());
+
+ // No ownedReferenceSubsetting → returns the subject itself (ExhibitStateUsage IS a StateUsage).
+ var subjectNoSubsetting = new ExhibitStateUsage();
+
+ Assert.That(subjectNoSubsetting.ComputeExhibitedState(), Is.SameAs(subjectNoSubsetting));
+
+ // ReferenceSubsetting whose ReferencedFeature is a StateUsage → returns that usage.
+ var subjectWithStateTarget = new ExhibitStateUsage();
+ var targetState = new StateUsage();
+ subjectWithStateTarget.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = targetState });
+
+ Assert.That(subjectWithStateTarget.ComputeExhibitedState(), Is.SameAs(targetState));
+
+ // ReferenceSubsetting whose ReferencedFeature is NOT a StateUsage → null (invalid-model branch, per validateExhibitStateUsageReference).
+ var subjectWithNonStateTarget = new ExhibitStateUsage();
+ var nonStateTarget = new ActionUsage();
+ subjectWithNonStateTarget.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = nonStateTarget });
+
+ Assert.That(subjectWithNonStateTarget.ComputeExhibitedState(), Is.Null);
}
}
}
diff --git a/SysML2.NET.Tests/Extend/IncludeUseCaseUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/IncludeUseCaseUsageExtensionsTestFixture.cs
index 0e2fb42a..eddce9e8 100644
--- a/SysML2.NET.Tests/Extend/IncludeUseCaseUsageExtensionsTestFixture.cs
+++ b/SysML2.NET.Tests/Extend/IncludeUseCaseUsageExtensionsTestFixture.cs
@@ -1,38 +1,60 @@
-// -------------------------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-//
+//
// 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.
-//
+//
//
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Tests.Extend
{
using System;
-
+
using NUnit.Framework;
-
+
+ using SysML2.NET.Core.POCO.Core.Features;
+ using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.UseCases;
+ using SysML2.NET.Extensions;
[TestFixture]
public class IncludeUseCaseUsageExtensionsTestFixture
{
[Test]
- public void ComputeUseCaseIncluded_ThrowsNotSupportedException()
+ public void VerifyComputeUseCaseIncluded()
{
- Assert.That(() => ((IIncludeUseCaseUsage)null).ComputeUseCaseIncluded(), Throws.TypeOf());
+ Assert.That(() => ((IIncludeUseCaseUsage)null).ComputeUseCaseIncluded(), Throws.TypeOf());
+
+ // No ownedReferenceSubsetting → returns the subject itself (IncludeUseCaseUsage IS a UseCaseUsage).
+ var subjectNoSubsetting = new IncludeUseCaseUsage();
+
+ Assert.That(subjectNoSubsetting.ComputeUseCaseIncluded(), Is.SameAs(subjectNoSubsetting));
+
+ // ReferenceSubsetting whose ReferencedFeature is a UseCaseUsage → returns that usage.
+ var subjectWithUseCaseTarget = new IncludeUseCaseUsage();
+ var targetUseCase = new UseCaseUsage();
+ subjectWithUseCaseTarget.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = targetUseCase });
+
+ Assert.That(subjectWithUseCaseTarget.ComputeUseCaseIncluded(), Is.SameAs(targetUseCase));
+
+ // ReferenceSubsetting whose ReferencedFeature is NOT a UseCaseUsage → null (invalid-model branch, per validateIncludeUseCaseUsageReference).
+ var subjectWithNonUseCaseTarget = new IncludeUseCaseUsage();
+ var nonUseCaseTarget = new ActionUsage();
+ subjectWithNonUseCaseTarget.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = nonUseCaseTarget });
+
+ Assert.That(subjectWithNonUseCaseTarget.ComputeUseCaseIncluded(), Is.Null);
}
}
}
diff --git a/SysML2.NET.Tests/Extend/StateDefinitionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/StateDefinitionExtensionsTestFixture.cs
index fd8e08ea..cd6de0d9 100644
--- a/SysML2.NET.Tests/Extend/StateDefinitionExtensionsTestFixture.cs
+++ b/SysML2.NET.Tests/Extend/StateDefinitionExtensionsTestFixture.cs
@@ -1,56 +1,174 @@
-// -------------------------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-//
+//
// 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.
-//
+//
//
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Tests.Extend
{
using System;
-
+
using NUnit.Framework;
-
+
+ using SysML2.NET.Core.POCO.Core.Types;
+ using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.States;
+ using SysML2.NET.Core.Systems.States;
+ using SysML2.NET.Extensions;
[TestFixture]
public class StateDefinitionExtensionsTestFixture
{
[Test]
- public void ComputeDoAction_ThrowsNotSupportedException()
+ public void VerifyComputeDoAction()
{
- Assert.That(() => ((IStateDefinition)null).ComputeDoAction(), Throws.TypeOf());
+ Assert.That(() => ((IStateDefinition)null).ComputeDoAction(), Throws.TypeOf());
+
+ // Empty: no StateSubactionMembership at all → null.
+ var emptyStateDefinition = new StateDefinition();
+
+ Assert.That(emptyStateDefinition.ComputeDoAction(), Is.Null);
+
+ // Wrong kind: one StateSubactionMembership of kind Entry only → null (action is never accessed).
+ var stateDefinitionWithEntry = new StateDefinition();
+ var entryAction = new ActionUsage();
+ stateDefinitionWithEntry.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Entry }, entryAction);
+
+ Assert.That(stateDefinitionWithEntry.ComputeDoAction(), Is.Null);
+
+ // Matching kind: one StateSubactionMembership of kind Do → returns the wired ActionUsage.
+ var stateDefinitionWithDo = new StateDefinition();
+ var doAction = new ActionUsage();
+ stateDefinitionWithDo.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Do }, doAction);
+
+ Assert.That(stateDefinitionWithDo.ComputeDoAction(), Is.SameAs(doAction));
+
+ // All three kinds present → the Kind filter picks the Do membership's action; Entry and Exit excluded.
+ var stateDefinitionAllKinds = new StateDefinition();
+ var allKindsEntry = new ActionUsage();
+ var allKindsDo = new ActionUsage();
+ var allKindsExit = new ActionUsage();
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Entry }, allKindsEntry);
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Do }, allKindsDo);
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Exit }, allKindsExit);
+
+ Assert.That(stateDefinitionAllKinds.ComputeDoAction(), Is.SameAs(allKindsDo));
}
-
+
[Test]
- public void ComputeEntryAction_ThrowsNotSupportedException()
+ public void VerifyComputeEntryAction()
{
- Assert.That(() => ((IStateDefinition)null).ComputeEntryAction(), Throws.TypeOf());
+ Assert.That(() => ((IStateDefinition)null).ComputeEntryAction(), Throws.TypeOf());
+
+ // Empty: no StateSubactionMembership at all → null.
+ var emptyStateDefinition = new StateDefinition();
+
+ Assert.That(emptyStateDefinition.ComputeEntryAction(), Is.Null);
+
+ // Wrong kind: one StateSubactionMembership of kind Do only → null (action is never accessed).
+ var stateDefinitionWithDo = new StateDefinition();
+ var doAction = new ActionUsage();
+ stateDefinitionWithDo.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Do }, doAction);
+
+ Assert.That(stateDefinitionWithDo.ComputeEntryAction(), Is.Null);
+
+ // Matching kind: one StateSubactionMembership of kind Entry → returns the wired ActionUsage.
+ var stateDefinitionWithEntry = new StateDefinition();
+ var entryAction = new ActionUsage();
+ stateDefinitionWithEntry.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Entry }, entryAction);
+
+ Assert.That(stateDefinitionWithEntry.ComputeEntryAction(), Is.SameAs(entryAction));
+
+ // All three kinds present → the Kind filter picks the Entry membership's action; Do and Exit excluded.
+ var stateDefinitionAllKinds = new StateDefinition();
+ var allKindsEntry = new ActionUsage();
+ var allKindsDo = new ActionUsage();
+ var allKindsExit = new ActionUsage();
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Entry }, allKindsEntry);
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Do }, allKindsDo);
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Exit }, allKindsExit);
+
+ Assert.That(stateDefinitionAllKinds.ComputeEntryAction(), Is.SameAs(allKindsEntry));
}
-
+
[Test]
- public void ComputeExitAction_ThrowsNotSupportedException()
+ public void VerifyComputeExitAction()
{
- Assert.That(() => ((IStateDefinition)null).ComputeExitAction(), Throws.TypeOf());
+ Assert.That(() => ((IStateDefinition)null).ComputeExitAction(), Throws.TypeOf());
+
+ // Empty: no StateSubactionMembership at all → null.
+ var emptyStateDefinition = new StateDefinition();
+
+ Assert.That(emptyStateDefinition.ComputeExitAction(), Is.Null);
+
+ // Wrong kind: one StateSubactionMembership of kind Do only → null (action is never accessed).
+ var stateDefinitionWithDo = new StateDefinition();
+ var doAction = new ActionUsage();
+ stateDefinitionWithDo.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Do }, doAction);
+
+ Assert.That(stateDefinitionWithDo.ComputeExitAction(), Is.Null);
+
+ // Matching kind: one StateSubactionMembership of kind Exit → returns the wired ActionUsage.
+ var stateDefinitionWithExit = new StateDefinition();
+ var exitAction = new ActionUsage();
+ stateDefinitionWithExit.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Exit }, exitAction);
+
+ Assert.That(stateDefinitionWithExit.ComputeExitAction(), Is.SameAs(exitAction));
+
+ // All three kinds present → the Kind filter picks the Exit membership's action; Entry and Do excluded.
+ var stateDefinitionAllKinds = new StateDefinition();
+ var allKindsEntry = new ActionUsage();
+ var allKindsDo = new ActionUsage();
+ var allKindsExit = new ActionUsage();
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Entry }, allKindsEntry);
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Do }, allKindsDo);
+ stateDefinitionAllKinds.AssignOwnership(new StateSubactionMembership { Kind = StateSubactionKind.Exit }, allKindsExit);
+
+ Assert.That(stateDefinitionAllKinds.ComputeExitAction(), Is.SameAs(allKindsExit));
}
-
+
[Test]
- public void ComputeState_ThrowsNotSupportedException()
+ public void VerifyComputeState()
{
- Assert.That(() => ((IStateDefinition)null).ComputeState(), Throws.TypeOf());
+ Assert.That(() => ((IStateDefinition)null).ComputeState(), Throws.TypeOf());
+
+ // Empty: no owned actions at all → empty list.
+ var emptySubject = new StateDefinition();
+
+ Assert.That(emptySubject.ComputeState(), Is.Empty);
+
+ // A plain ActionUsage (not a StateUsage) is filtered out by the selectByKind(StateUsage).
+ var subjectWithPlainActionOnly = new StateDefinition();
+ var plainAction = new ActionUsage();
+ subjectWithPlainActionOnly.AssignOwnership(new FeatureMembership(), plainAction);
+
+ Assert.That(subjectWithPlainActionOnly.ComputeState(), Is.Empty);
+
+ // Populated: mix of a plain ActionUsage (excluded) and two StateUsages (included, in action order).
+ var subject = new StateDefinition();
+ var otherPlainAction = new ActionUsage();
+ var stateUsage1 = new StateUsage();
+ var stateUsage2 = new StateUsage();
+
+ subject.AssignOwnership(new FeatureMembership(), otherPlainAction);
+ subject.AssignOwnership(new FeatureMembership(), stateUsage1);
+ subject.AssignOwnership(new FeatureMembership(), stateUsage2);
+
+ Assert.That(subject.ComputeState(), Is.EqualTo([stateUsage1, stateUsage2]));
}
}
}
diff --git a/SysML2.NET.Tests/Extend/UseCaseDefinitionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/UseCaseDefinitionExtensionsTestFixture.cs
index 58362494..82fb7046 100644
--- a/SysML2.NET.Tests/Extend/UseCaseDefinitionExtensionsTestFixture.cs
+++ b/SysML2.NET.Tests/Extend/UseCaseDefinitionExtensionsTestFixture.cs
@@ -1,38 +1,68 @@
-// -------------------------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-//
+//
// 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.
-//
+//
//
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Tests.Extend
{
using System;
-
+
using NUnit.Framework;
-
+
+ using SysML2.NET.Core.POCO.Core.Features;
+ using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Systems.UseCases;
+ using SysML2.NET.Extensions;
[TestFixture]
public class UseCaseDefinitionExtensionsTestFixture
{
[Test]
- public void ComputeIncludedUseCase_ThrowsNotSupportedException()
+ public void VerifyComputeIncludedUseCase()
{
- Assert.That(() => ((IUseCaseDefinition)null).ComputeIncludedUseCase(), Throws.TypeOf());
+ Assert.That(() => ((IUseCaseDefinition)null).ComputeIncludedUseCase(), Throws.TypeOf());
+
+ // Empty: no owned usages at all → empty list.
+ var emptySubject = new UseCaseDefinition();
+
+ Assert.That(emptySubject.ComputeIncludedUseCase(), Is.Empty);
+
+ // A plain UseCaseUsage (not an IncludeUseCaseUsage) is filtered out by the selectByKind(IncludeUseCaseUsage).
+ var subjectWithPlainUseCaseOnly = new UseCaseDefinition();
+ var plainUseCase = new UseCaseUsage();
+ subjectWithPlainUseCaseOnly.AssignOwnership(new FeatureMembership(), plainUseCase);
+
+ Assert.That(subjectWithPlainUseCaseOnly.ComputeIncludedUseCase(), Is.Empty);
+
+ // Populated: plain UseCaseUsage (excluded) + IncludeUseCaseUsage with no ReferenceSubsetting (contributes itself)
+ // + IncludeUseCaseUsage referencing a target UseCaseUsage (contributes the target), in ownership order.
+ var subject = new UseCaseDefinition();
+ var otherPlainUseCase = new UseCaseUsage();
+ var selfInclude = new IncludeUseCaseUsage();
+ var referencedTarget = new UseCaseUsage();
+ var referencingInclude = new IncludeUseCaseUsage();
+ referencingInclude.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = referencedTarget });
+
+ subject.AssignOwnership(new FeatureMembership(), otherPlainUseCase);
+ subject.AssignOwnership(new FeatureMembership(), selfInclude);
+ subject.AssignOwnership(new FeatureMembership(), referencingInclude);
+
+ Assert.That(subject.ComputeIncludedUseCase(), Is.EqualTo(new IUseCaseUsage[] { selfInclude, referencedTarget }));
}
}
}
diff --git a/SysML2.NET.Tests/Extend/UseCaseUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/UseCaseUsageExtensionsTestFixture.cs
index 7878c0aa..0f99584f 100644
--- a/SysML2.NET.Tests/Extend/UseCaseUsageExtensionsTestFixture.cs
+++ b/SysML2.NET.Tests/Extend/UseCaseUsageExtensionsTestFixture.cs
@@ -1,43 +1,95 @@
-// -------------------------------------------------------------------------------------------------
+// -------------------------------------------------------------------------------------------------
//
-//
+//
// 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.
-//
+//
//
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Tests.Extend
{
using System;
-
+
using NUnit.Framework;
-
+
+ using SysML2.NET.Core.POCO.Core.Features;
+ using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Systems.UseCases;
+ using SysML2.NET.Exceptions;
+ using SysML2.NET.Extensions;
[TestFixture]
public class UseCaseUsageExtensionsTestFixture
{
[Test]
- public void ComputeIncludedUseCase_ThrowsNotSupportedException()
+ public void VerifyComputeIncludedUseCase()
{
- Assert.That(() => ((IUseCaseUsage)null).ComputeIncludedUseCase(), Throws.TypeOf());
+ Assert.That(() => ((IUseCaseUsage)null).ComputeIncludedUseCase(), Throws.TypeOf());
+
+ // Empty: no nested usages at all → empty list.
+ var emptySubject = new UseCaseUsage();
+
+ Assert.That(emptySubject.ComputeIncludedUseCase(), Is.Empty);
+
+ // A plain nested UseCaseUsage (not an IncludeUseCaseUsage) is filtered out by the selectByKind(IncludeUseCaseUsage).
+ var subjectWithPlainNestedOnly = new UseCaseUsage();
+ var plainNested = new UseCaseUsage();
+ subjectWithPlainNestedOnly.AssignOwnership(new FeatureMembership(), plainNested);
+
+ Assert.That(subjectWithPlainNestedOnly.ComputeIncludedUseCase(), Is.Empty);
+
+ // Populated: nested IncludeUseCaseUsage with no ReferenceSubsetting (contributes itself, self-referencing)
+ // + nested IncludeUseCaseUsage referencing a target UseCaseUsage (contributes the target), in nesting order.
+ // Navigates nestedUseCase (Usage-side), NOT ownedUseCase (which does not exist on IUseCaseUsage).
+ var subject = new UseCaseUsage();
+ var selfInclude = new IncludeUseCaseUsage();
+ var referencedTarget = new UseCaseUsage();
+ var referencingInclude = new IncludeUseCaseUsage();
+ referencingInclude.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = referencedTarget });
+
+ subject.AssignOwnership(new FeatureMembership(), selfInclude);
+ subject.AssignOwnership(new FeatureMembership(), referencingInclude);
+
+ Assert.That(subject.ComputeIncludedUseCase(), Is.EqualTo(new IUseCaseUsage[] { selfInclude, referencedTarget }));
}
+
[Test]
- public void ComputeUseCaseDefinition_ThrowsNotSupportedException()
+ public void VerifyComputeUseCaseDefinition()
{
- Assert.That(() => ((IUseCaseUsage)null).ComputeUseCaseDefinition(), Throws.TypeOf());
+ Assert.That(() => ((IUseCaseUsage)null).ComputeUseCaseDefinition(), Throws.TypeOf());
+
+ // Empty case: no FeatureTyping whose Type is a UseCaseDefinition → null.
+ var subjectNoTyping = new UseCaseUsage();
+
+ Assert.That(subjectNoTyping.ComputeUseCaseDefinition(), Is.Null);
+
+ // Populated case: one FeatureTyping whose Type is a UseCaseDefinition → returned.
+ var subjectOneTyping = new UseCaseUsage();
+ var useCaseDefinition = new UseCaseDefinition();
+ subjectOneTyping.AssignOwnership(new FeatureTyping { Type = useCaseDefinition });
+
+ Assert.That(subjectOneTyping.ComputeUseCaseDefinition(), Is.SameAs(useCaseDefinition));
+
+ // [0..1] upper-bound violation: two typings both resolving to UseCaseDefinition → MultiplicityViolationException.
+ var subjectTwoTypings = new UseCaseUsage();
+ var firstUseCaseDefinition = new UseCaseDefinition();
+ var secondUseCaseDefinition = new UseCaseDefinition();
+ subjectTwoTypings.AssignOwnership(new FeatureTyping { Type = firstUseCaseDefinition });
+ subjectTwoTypings.AssignOwnership(new FeatureTyping { Type = secondUseCaseDefinition });
+
+ Assert.That(() => subjectTwoTypings.ComputeUseCaseDefinition(), Throws.TypeOf());
}
}
}
diff --git a/SysML2.NET/Extend/ExhibitStateUsageExtensions.cs b/SysML2.NET/Extend/ExhibitStateUsageExtensions.cs
index 93304124..5f765e0a 100644
--- a/SysML2.NET/Extend/ExhibitStateUsageExtensions.cs
+++ b/SysML2.NET/Extend/ExhibitStateUsageExtensions.cs
@@ -72,10 +72,18 @@ internal static class ExhibitStateUsageExtensions
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IStateUsage ComputeExhibitedState(this IExhibitStateUsage exhibitStateUsageSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ if (exhibitStateUsageSubject == null)
+ {
+ throw new ArgumentNullException(nameof(exhibitStateUsageSubject));
+ }
+
+ var referencedFeatureTarget = exhibitStateUsageSubject.ReferencedFeatureTarget();
+
+ return referencedFeatureTarget == null
+ ? exhibitStateUsageSubject
+ : referencedFeatureTarget as IStateUsage;
}
}
diff --git a/SysML2.NET/Extend/IncludeUseCaseUsageExtensions.cs b/SysML2.NET/Extend/IncludeUseCaseUsageExtensions.cs
index 5397ae28..96b0843d 100644
--- a/SysML2.NET/Extend/IncludeUseCaseUsageExtensions.cs
+++ b/SysML2.NET/Extend/IncludeUseCaseUsageExtensions.cs
@@ -72,10 +72,18 @@ internal static class IncludeUseCaseUsageExtensions
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IUseCaseUsage ComputeUseCaseIncluded(this IIncludeUseCaseUsage includeUseCaseUsageSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ if (includeUseCaseUsageSubject == null)
+ {
+ throw new ArgumentNullException(nameof(includeUseCaseUsageSubject));
+ }
+
+ var referencedFeatureTarget = includeUseCaseUsageSubject.ReferencedFeatureTarget();
+
+ return referencedFeatureTarget == null
+ ? includeUseCaseUsageSubject
+ : referencedFeatureTarget as IUseCaseUsage;
}
}
diff --git a/SysML2.NET/Extend/StateDefinitionExtensions.cs b/SysML2.NET/Extend/StateDefinitionExtensions.cs
index 2239cbb5..47412edb 100644
--- a/SysML2.NET/Extend/StateDefinitionExtensions.cs
+++ b/SysML2.NET/Extend/StateDefinitionExtensions.cs
@@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Systems.States
{
using System;
using System.Collections.Generic;
+ using System.Linq;
using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
@@ -53,6 +54,7 @@ namespace SysML2.NET.Core.POCO.Systems.States
using SysML2.NET.Core.POCO.Systems.UseCases;
using SysML2.NET.Core.POCO.Systems.VerificationCases;
using SysML2.NET.Core.POCO.Systems.Views;
+ using SysML2.NET.Core.Systems.States;
///
/// The class provides extensions methods for
@@ -82,10 +84,17 @@ internal static class StateDefinitionExtensions
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IActionUsage ComputeDoAction(this IStateDefinition stateDefinitionSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ if (stateDefinitionSubject == null)
+ {
+ throw new ArgumentNullException(nameof(stateDefinitionSubject));
+ }
+
+ return stateDefinitionSubject.ownedMembership
+ .OfType()
+ .FirstOrDefault(membership => membership.Kind == StateSubactionKind.Do)
+ ?.action;
}
///
@@ -110,10 +119,17 @@ internal static IActionUsage ComputeDoAction(this IStateDefinition stateDefiniti
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IActionUsage ComputeEntryAction(this IStateDefinition stateDefinitionSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ if (stateDefinitionSubject == null)
+ {
+ throw new ArgumentNullException(nameof(stateDefinitionSubject));
+ }
+
+ return stateDefinitionSubject.ownedMembership
+ .OfType()
+ .FirstOrDefault(membership => membership.Kind == StateSubactionKind.Entry)
+ ?.action;
}
///
@@ -138,10 +154,17 @@ internal static IActionUsage ComputeEntryAction(this IStateDefinition stateDefin
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IActionUsage ComputeExitAction(this IStateDefinition stateDefinitionSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ if (stateDefinitionSubject == null)
+ {
+ throw new ArgumentNullException(nameof(stateDefinitionSubject));
+ }
+
+ return stateDefinitionSubject.ownedMembership
+ .OfType()
+ .FirstOrDefault(membership => membership.Kind == StateSubactionKind.Exit)
+ ?.action;
}
///
@@ -159,10 +182,11 @@ internal static IActionUsage ComputeExitAction(this IStateDefinition stateDefini
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List ComputeState(this IStateDefinition stateDefinitionSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ return stateDefinitionSubject == null
+ ? throw new ArgumentNullException(nameof(stateDefinitionSubject))
+ : [.. stateDefinitionSubject.action.OfType()];
}
}
diff --git a/SysML2.NET/Extend/UseCaseDefinitionExtensions.cs b/SysML2.NET/Extend/UseCaseDefinitionExtensions.cs
index 602ff567..ceb5102c 100644
--- a/SysML2.NET/Extend/UseCaseDefinitionExtensions.cs
+++ b/SysML2.NET/Extend/UseCaseDefinitionExtensions.cs
@@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Systems.UseCases
{
using System;
using System.Collections.Generic;
+ using System.Linq;
using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
@@ -78,10 +79,13 @@ internal static class UseCaseDefinitionExtensions
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List ComputeIncludedUseCase(this IUseCaseDefinition useCaseDefinitionSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ return useCaseDefinitionSubject == null
+ ? throw new ArgumentNullException(nameof(useCaseDefinitionSubject))
+ : [.. useCaseDefinitionSubject.ownedUseCase
+ .OfType()
+ .Select(includeUseCaseUsage => includeUseCaseUsage.useCaseIncluded)];
}
}
diff --git a/SysML2.NET/Extend/UseCaseUsageExtensions.cs b/SysML2.NET/Extend/UseCaseUsageExtensions.cs
index f4416a46..716ac37c 100644
--- a/SysML2.NET/Extend/UseCaseUsageExtensions.cs
+++ b/SysML2.NET/Extend/UseCaseUsageExtensions.cs
@@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Systems.UseCases
{
using System;
using System.Collections.Generic;
+ using System.Linq;
using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
@@ -56,6 +57,7 @@ namespace SysML2.NET.Core.POCO.Systems.UseCases
using SysML2.NET.Core.POCO.Systems.States;
using SysML2.NET.Core.POCO.Systems.VerificationCases;
using SysML2.NET.Core.POCO.Systems.Views;
+ using SysML2.NET.Extensions;
///
/// The class provides extensions methods for
@@ -80,10 +82,13 @@ internal static class UseCaseUsageExtensions
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List ComputeIncludedUseCase(this IUseCaseUsage useCaseUsageSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ return useCaseUsageSubject == null
+ ? throw new ArgumentNullException(nameof(useCaseUsageSubject))
+ : [.. useCaseUsageSubject.nestedUseCase
+ .OfType()
+ .Select(includeUseCaseUsage => includeUseCaseUsage.useCaseIncluded)];
}
///
@@ -95,10 +100,11 @@ internal static List ComputeIncludedUseCase(this IUseCaseUsage us
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IUseCaseDefinition ComputeUseCaseDefinition(this IUseCaseUsage useCaseUsageSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ return useCaseUsageSubject == null
+ ? throw new ArgumentNullException(nameof(useCaseUsageSubject))
+ : FeatureExtensions.ComputeType(useCaseUsageSubject).SingleOrDefaultStrict(nameof(useCaseUsageSubject));
}
}