diff --git a/SysML2.NET.Tests/Extend/ConcernUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ConcernUsageExtensionsTestFixture.cs
index a785b216..cf5628ef 100644
--- a/SysML2.NET.Tests/Extend/ConcernUsageExtensionsTestFixture.cs
+++ b/SysML2.NET.Tests/Extend/ConcernUsageExtensionsTestFixture.cs
@@ -1,20 +1,20 @@
// -------------------------------------------------------------------------------------------------
//
-//
-// Copyright 2022-2026 Starion Group S.A.
-//
+//
+// Copyright (C) 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.
-//
+//
//
// ------------------------------------------------------------------------------------------------
@@ -24,15 +24,41 @@ namespace SysML2.NET.Tests.Extend
using NUnit.Framework;
+ using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Systems.Requirements;
+ using SysML2.NET.Exceptions;
+ using SysML2.NET.Extensions;
[TestFixture]
public class ConcernUsageExtensionsTestFixture
{
[Test]
- public void ComputeConcernDefinition_ThrowsNotSupportedException()
+ public void VerifyComputeConcernDefinition()
{
- Assert.That(() => ((IConcernUsage)null).ComputeConcernDefinition(), Throws.TypeOf());
+ // Null subject:
+ Assert.That(() => ((IConcernUsage)null).ComputeConcernDefinition(), Throws.TypeOf());
+
+ // Empty subject: no FeatureTyping relationships, so no ConcernDefinition:
+ var concernUsage = new ConcernUsage();
+ Assert.That(concernUsage.ComputeConcernDefinition(), Is.Null);
+
+ // Typed by FeatureTyping, but not an IConcernDefinition:
+ var requirementDefinition = new RequirementDefinition();
+ var typingToRequirement = new FeatureTyping { Type = requirementDefinition };
+ concernUsage.AssignOwnership(typingToRequirement);
+ Assert.That(concernUsage.ComputeConcernDefinition(), Is.Null);
+
+ // Correct typing: FeatureTyping.Type is a ConcernDefinition:
+ var concernDefinition = new ConcernDefinition();
+ var typingToConcern = new FeatureTyping { Type = concernDefinition };
+ concernUsage.AssignOwnership(typingToConcern);
+ Assert.That(concernUsage.ComputeConcernDefinition(), Is.SameAs(concernDefinition));
+
+ // Multiple matching typings: FirstOrDefault is used so even breaking the multiplicity, it works;
+ var secondConcernDefinition = new ConcernDefinition();
+ var typingToSecondConcern = new FeatureTyping { Type = secondConcernDefinition };
+ concernUsage.AssignOwnership(typingToSecondConcern);
+ Assert.That(() => concernUsage.ComputeConcernDefinition(), Throws.TypeOf());
}
}
}
diff --git a/SysML2.NET/Extend/ConcernUsageExtensions.cs b/SysML2.NET/Extend/ConcernUsageExtensions.cs
index 605d3977..c0be88bb 100644
--- a/SysML2.NET/Extend/ConcernUsageExtensions.cs
+++ b/SysML2.NET/Extend/ConcernUsageExtensions.cs
@@ -1,65 +1,34 @@
// -------------------------------------------------------------------------------------------------
//
-//
-// Copyright (C) 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
-//
+//
+// Copyright (C) 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.Core.POCO.Systems.Requirements
{
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.Core.Classifiers;
using SysML2.NET.Core.POCO.Core.Features;
- using SysML2.NET.Core.POCO.Core.Types;
- using SysML2.NET.Core.POCO.Kernel.Behaviors;
- using SysML2.NET.Core.POCO.Kernel.Classes;
- using SysML2.NET.Core.POCO.Kernel.Functions;
- using SysML2.NET.Core.POCO.Root.Annotations;
- using SysML2.NET.Core.POCO.Root.Elements;
- using SysML2.NET.Core.POCO.Root.Namespaces;
- using SysML2.NET.Core.POCO.Systems.Actions;
- using SysML2.NET.Core.POCO.Systems.Allocations;
- using SysML2.NET.Core.POCO.Systems.AnalysisCases;
- using SysML2.NET.Core.POCO.Systems.Attributes;
- using SysML2.NET.Core.POCO.Systems.Calculations;
- using SysML2.NET.Core.POCO.Systems.Cases;
- using SysML2.NET.Core.POCO.Systems.Connections;
- using SysML2.NET.Core.POCO.Systems.Constraints;
- using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
- using SysML2.NET.Core.POCO.Systems.Enumerations;
- using SysML2.NET.Core.POCO.Systems.Flows;
- using SysML2.NET.Core.POCO.Systems.Interfaces;
- using SysML2.NET.Core.POCO.Systems.Items;
- using SysML2.NET.Core.POCO.Systems.Metadata;
- using SysML2.NET.Core.POCO.Systems.Occurrences;
- using SysML2.NET.Core.POCO.Systems.Parts;
- using SysML2.NET.Core.POCO.Systems.Ports;
- using 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.Extensions;
///
- /// The class provides extensions methods for
- /// the interface
+ /// The class provides extensions methods for
+ /// the interface
///
internal static class ConcernUsageExtensions
{
@@ -67,16 +36,20 @@ internal static class ConcernUsageExtensions
/// Computes the derived property.
///
///
- /// The subject
+ /// The subject
///
///
/// the computed result
///
- [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IConcernDefinition ComputeConcernDefinition(this IConcernUsage concernUsageSubject)
{
- throw new NotSupportedException("Create a GitHub issue when this method is required");
+ return concernUsageSubject == null
+ ? throw new ArgumentNullException(nameof(concernUsageSubject))
+ : concernUsageSubject.OwnedRelationship
+ .OfType()
+ .Select(featureTyping => featureTyping.Type)
+ .OfType()
+ .SingleOrDefaultStrict(nameof(concernUsageSubject));
}
-
}
}