From 967dddc0bcc9af47e44dbc51af650951982c2dac Mon Sep 17 00:00:00 2001 From: atheate Date: Wed, 27 May 2026 14:12:16 +0200 Subject: [PATCH] Fix #149 #164 #193 #194 --- .../Extend/ExpressionExtensionsTestFixture.cs | 2 +- .../IntersectingExtensionsTestFixture.cs | 37 ++++++++++++++--- ...bjectiveMembershipExtensionsTestFixture.cs | 2 +- .../PortConjugationExtensionsTestFixture.cs | 34 ++++++++++++--- ...pressionMembershipExtensionsTestFixture.cs | 2 +- ...keholderMembershipExtensionsTestFixture.cs | 2 +- ...ubactionMembershipExtensionsTestFixture.cs | 2 +- .../Extend/StateUsageExtensionsTestFixture.cs | 2 +- .../TypeFeaturingExtensionsTestFixture.cs | 28 ++++++++++--- .../Extend/UnioningExtensionsTestFixture.cs | 37 ++++++++++++++--- SysML2.NET/Extend/IntersectingExtensions.cs | 40 +++++++++--------- .../Extend/ObjectiveMembershipExtensions.cs | 2 +- .../Extend/PortConjugationExtensions.cs | 41 ++++++++++--------- .../ResultExpressionMembershipExtensions.cs | 2 +- .../Extend/StakeholderMembershipExtensions.cs | 2 +- .../StateSubactionMembershipExtensions.cs | 2 +- SysML2.NET/Extend/TypeFeaturingExtensions.cs | 36 +++++++--------- SysML2.NET/Extend/UnioningExtensions.cs | 40 +++++++++--------- 18 files changed, 204 insertions(+), 109 deletions(-) diff --git a/SysML2.NET.Tests/Extend/ExpressionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ExpressionExtensionsTestFixture.cs index 47fccad3..d6ec9ab2 100644 --- a/SysML2.NET.Tests/Extend/ExpressionExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/ExpressionExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET.Tests/Extend/IntersectingExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/IntersectingExtensionsTestFixture.cs index 640e5d10..db52f83e 100644 --- a/SysML2.NET.Tests/Extend/IntersectingExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/IntersectingExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. @@ -21,18 +21,45 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + using SysML2.NET.Core.POCO.Core.Types; + using SysML2.NET.Core.POCO.Root.Elements; + using SysML2.NET.Core.POCO.Root.Namespaces; + using SysML2.NET.Exceptions; + + using Type = SysML2.NET.Core.POCO.Core.Types.Type; [TestFixture] public class IntersectingExtensionsTestFixture { [Test] - public void ComputeTypeIntersected_ThrowsNotSupportedException() + public void VerifyComputeTypeIntersected() { - Assert.That(() => ((IIntersecting)null).ComputeTypeIntersected(), Throws.TypeOf()); + // Null subject → ArgumentNullException. + Assert.That(() => ((IIntersecting)null).ComputeTypeIntersected(), Throws.TypeOf()); + + // Empty Intersecting (OwningRelatedElement is null) → [1..1] violation: IncompleteModelException. + var emptyIntersecting = new Intersecting(); + + Assert.That(() => emptyIntersecting.ComputeTypeIntersected(), Throws.TypeOf()); + + // OwningRelatedElement is an IType → returns the same instance. + var type = new Type(); + var intersectingWithType = new Intersecting(); + + ((IContainedRelationship)intersectingWithType).OwningRelatedElement = type; + + Assert.That(intersectingWithType.ComputeTypeIntersected(), Is.SameAs(type)); + + // OwningRelatedElement is a non-IType (Namespace) → [1..1] type violation: IncompleteModelException. + var namespaceObj = new Namespace(); + var intersectingWithNamespace = new Intersecting(); + + ((IContainedRelationship)intersectingWithNamespace).OwningRelatedElement = namespaceObj; + + Assert.That(() => intersectingWithNamespace.ComputeTypeIntersected(), Throws.TypeOf()); } } } diff --git a/SysML2.NET.Tests/Extend/ObjectiveMembershipExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ObjectiveMembershipExtensionsTestFixture.cs index b64d3632..b893d0ff 100644 --- a/SysML2.NET.Tests/Extend/ObjectiveMembershipExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/ObjectiveMembershipExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET.Tests/Extend/PortConjugationExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/PortConjugationExtensionsTestFixture.cs index ec5b5d9f..8bf0f700 100644 --- a/SysML2.NET.Tests/Extend/PortConjugationExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/PortConjugationExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. @@ -21,18 +21,42 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + + using SysML2.NET.Core.POCO.Root.Elements; using SysML2.NET.Core.POCO.Systems.Ports; + using SysML2.NET.Exceptions; [TestFixture] public class PortConjugationExtensionsTestFixture { [Test] - public void ComputeConjugatedPortDefinition_ThrowsNotSupportedException() + public void VerifyComputeConjugatedPortDefinition() { - Assert.That(() => ((IPortConjugation)null).ComputeConjugatedPortDefinition(), Throws.TypeOf()); + // Null subject → ArgumentNullException. + Assert.That(() => ((IPortConjugation)null).ComputeConjugatedPortDefinition(), Throws.TypeOf()); + + // Empty PortConjugation (OwningRelatedElement is null) → [1..1] violation: IncompleteModelException. + var emptyPortConj = new PortConjugation(); + + Assert.That(() => emptyPortConj.ComputeConjugatedPortDefinition(), Throws.TypeOf()); + + // OwningRelatedElement is an IConjugatedPortDefinition → returns the same instance. + var conjugated = new ConjugatedPortDefinition(); + var portConjWithConjugated = new PortConjugation(); + + ((IContainedRelationship)portConjWithConjugated).OwningRelatedElement = conjugated; + + Assert.That(portConjWithConjugated.ComputeConjugatedPortDefinition(), Is.SameAs(conjugated)); + + // OwningRelatedElement is a PortDefinition (IPortDefinition but NOT IConjugatedPortDefinition) → [1..1] type violation: IncompleteModelException. + var portDefinition = new PortDefinition(); + var portConjWithPortDefinition = new PortConjugation(); + + ((IContainedRelationship)portConjWithPortDefinition).OwningRelatedElement = portDefinition; + + Assert.That(() => portConjWithPortDefinition.ComputeConjugatedPortDefinition(), Throws.TypeOf()); } } } diff --git a/SysML2.NET.Tests/Extend/ResultExpressionMembershipExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ResultExpressionMembershipExtensionsTestFixture.cs index 56ef6824..f00c6235 100644 --- a/SysML2.NET.Tests/Extend/ResultExpressionMembershipExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/ResultExpressionMembershipExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET.Tests/Extend/StakeholderMembershipExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/StakeholderMembershipExtensionsTestFixture.cs index e9788431..d4aa7842 100644 --- a/SysML2.NET.Tests/Extend/StakeholderMembershipExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/StakeholderMembershipExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET.Tests/Extend/StateSubactionMembershipExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/StateSubactionMembershipExtensionsTestFixture.cs index 2479b80f..3b750f99 100644 --- a/SysML2.NET.Tests/Extend/StateSubactionMembershipExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/StateSubactionMembershipExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET.Tests/Extend/StateUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/StateUsageExtensionsTestFixture.cs index 1aec56a8..5fc44120 100644 --- a/SysML2.NET.Tests/Extend/StateUsageExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/StateUsageExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET.Tests/Extend/TypeFeaturingExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/TypeFeaturingExtensionsTestFixture.cs index df7d5e5b..815478ca 100644 --- a/SysML2.NET.Tests/Extend/TypeFeaturingExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/TypeFeaturingExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. @@ -21,18 +21,36 @@ 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 TypeFeaturingExtensionsTestFixture { [Test] - public void ComputeOwningFeatureOfType_ThrowsNotSupportedException() + public void VerifyComputeOwningFeatureOfType() { - Assert.That(() => ((ITypeFeaturing)null).ComputeOwningFeatureOfType(), Throws.TypeOf()); + Assert.That(() => ((ITypeFeaturing)null).ComputeOwningFeatureOfType(), Throws.TypeOf()); + + var typeFeaturing = new TypeFeaturing(); + + Assert.That(typeFeaturing.ComputeOwningFeatureOfType(), Is.Null); + + var feature = new Feature(); + + ((IContainedRelationship)typeFeaturing).OwningRelatedElement = feature; + + Assert.That(typeFeaturing.ComputeOwningFeatureOfType(), Is.SameAs(feature)); + + var nonFeatureTypeFeaturing = new TypeFeaturing(); + + ((IContainedRelationship)nonFeatureTypeFeaturing).OwningRelatedElement = new Namespace(); + + Assert.That(nonFeatureTypeFeaturing.ComputeOwningFeatureOfType(), Is.Null); } } } diff --git a/SysML2.NET.Tests/Extend/UnioningExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/UnioningExtensionsTestFixture.cs index 4e2ce3bd..e6c1f743 100644 --- a/SysML2.NET.Tests/Extend/UnioningExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/UnioningExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. @@ -21,18 +21,45 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + using SysML2.NET.Core.POCO.Core.Types; + using SysML2.NET.Core.POCO.Root.Annotations; + using SysML2.NET.Core.POCO.Root.Elements; + using SysML2.NET.Exceptions; + + using SysMLType = SysML2.NET.Core.POCO.Core.Types.Type; [TestFixture] public class UnioningExtensionsTestFixture { [Test] - public void ComputeTypeUnioned_ThrowsNotSupportedException() + public void VerifyComputeTypeUnioned() { - Assert.That(() => ((IUnioning)null).ComputeTypeUnioned(), Throws.TypeOf()); + // Null subject → ArgumentNullException. + Assert.That(() => ((IUnioning)null).ComputeTypeUnioned(), Throws.TypeOf()); + + // Empty Unioning (OwningRelatedElement is null) → [1..1] violation: IncompleteModelException. + var emptyUnioning = new Unioning(); + + Assert.That(() => emptyUnioning.ComputeTypeUnioned(), Throws.TypeOf()); + + // OwningRelatedElement is an IType → returns the same instance. + var type = new SysMLType(); + var unioningWithType = new Unioning(); + + ((IContainedRelationship)unioningWithType).OwningRelatedElement = type; + + Assert.That(unioningWithType.ComputeTypeUnioned(), Is.SameAs(type)); + + // OwningRelatedElement is a non-IType element (Annotation) → [1..1] type violation: IncompleteModelException. + var annotation = new Annotation(); + var unioningWithAnnotation = new Unioning(); + + ((IContainedRelationship)unioningWithAnnotation).OwningRelatedElement = annotation; + + Assert.That(() => unioningWithAnnotation.ComputeTypeUnioned(), Throws.TypeOf()); } } } diff --git a/SysML2.NET/Extend/IntersectingExtensions.cs b/SysML2.NET/Extend/IntersectingExtensions.cs index 935938b0..c0c762b8 100644 --- a/SysML2.NET/Extend/IntersectingExtensions.cs +++ b/SysML2.NET/Extend/IntersectingExtensions.cs @@ -1,35 +1,32 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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.Core.Types { using System; - using System.Collections.Generic; - using SysML2.NET.Core.POCO.Root.Annotations; - using SysML2.NET.Core.POCO.Root.Elements; - using SysML2.NET.Core.POCO.Root.Namespaces; + using SysML2.NET.Exceptions; /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class IntersectingExtensions { @@ -37,16 +34,21 @@ internal static class IntersectingExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IType ComputeTypeIntersected(this IIntersecting intersectingSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); - } + if (intersectingSubject == null) + { + throw new ArgumentNullException(nameof(intersectingSubject)); + } + return intersectingSubject.OwningRelatedElement as IType + ?? throw new IncompleteModelException( + $"{nameof(intersectingSubject)} must have an owning related element of type {nameof(IType)}"); + } } } diff --git a/SysML2.NET/Extend/ObjectiveMembershipExtensions.cs b/SysML2.NET/Extend/ObjectiveMembershipExtensions.cs index 0ed53358..5869ac2f 100644 --- a/SysML2.NET/Extend/ObjectiveMembershipExtensions.cs +++ b/SysML2.NET/Extend/ObjectiveMembershipExtensions.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET/Extend/PortConjugationExtensions.cs b/SysML2.NET/Extend/PortConjugationExtensions.cs index eef8d077..1482a78a 100644 --- a/SysML2.NET/Extend/PortConjugationExtensions.cs +++ b/SysML2.NET/Extend/PortConjugationExtensions.cs @@ -1,36 +1,32 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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.Ports { using System; - using System.Collections.Generic; - using SysML2.NET.Core.POCO.Core.Types; - using SysML2.NET.Core.POCO.Root.Annotations; - using SysML2.NET.Core.POCO.Root.Elements; - using SysML2.NET.Core.POCO.Root.Namespaces; + using SysML2.NET.Exceptions; /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class PortConjugationExtensions { @@ -38,16 +34,21 @@ internal static class PortConjugationExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IConjugatedPortDefinition ComputeConjugatedPortDefinition(this IPortConjugation portConjugationSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); - } + if (portConjugationSubject == null) + { + throw new ArgumentNullException(nameof(portConjugationSubject)); + } + return portConjugationSubject.OwningRelatedElement as IConjugatedPortDefinition + ?? throw new IncompleteModelException( + $"{nameof(portConjugationSubject)} must have an owning related element of type {nameof(IConjugatedPortDefinition)}"); + } } } diff --git a/SysML2.NET/Extend/ResultExpressionMembershipExtensions.cs b/SysML2.NET/Extend/ResultExpressionMembershipExtensions.cs index 48f49e71..21e55f1b 100644 --- a/SysML2.NET/Extend/ResultExpressionMembershipExtensions.cs +++ b/SysML2.NET/Extend/ResultExpressionMembershipExtensions.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET/Extend/StakeholderMembershipExtensions.cs b/SysML2.NET/Extend/StakeholderMembershipExtensions.cs index 09e1c44f..41809411 100644 --- a/SysML2.NET/Extend/StakeholderMembershipExtensions.cs +++ b/SysML2.NET/Extend/StakeholderMembershipExtensions.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET/Extend/StateSubactionMembershipExtensions.cs b/SysML2.NET/Extend/StateSubactionMembershipExtensions.cs index eabdb191..585b5027 100644 --- a/SysML2.NET/Extend/StateSubactionMembershipExtensions.cs +++ b/SysML2.NET/Extend/StateSubactionMembershipExtensions.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// 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. diff --git a/SysML2.NET/Extend/TypeFeaturingExtensions.cs b/SysML2.NET/Extend/TypeFeaturingExtensions.cs index 885b9ca9..c24de54a 100644 --- a/SysML2.NET/Extend/TypeFeaturingExtensions.cs +++ b/SysML2.NET/Extend/TypeFeaturingExtensions.cs @@ -1,36 +1,30 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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.Core.Features { using System; - using System.Collections.Generic; - - using SysML2.NET.Core.POCO.Core.Types; - using SysML2.NET.Core.POCO.Root.Annotations; - using SysML2.NET.Core.POCO.Root.Elements; - using SysML2.NET.Core.POCO.Root.Namespaces; /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class TypeFeaturingExtensions { @@ -38,16 +32,16 @@ internal static class TypeFeaturingExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IFeature ComputeOwningFeatureOfType(this ITypeFeaturing typeFeaturingSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return typeFeaturingSubject == null + ? throw new ArgumentNullException(nameof(typeFeaturingSubject)) + : typeFeaturingSubject.OwningRelatedElement as IFeature; } - } } diff --git a/SysML2.NET/Extend/UnioningExtensions.cs b/SysML2.NET/Extend/UnioningExtensions.cs index 893354dd..fde283b2 100644 --- a/SysML2.NET/Extend/UnioningExtensions.cs +++ b/SysML2.NET/Extend/UnioningExtensions.cs @@ -1,35 +1,32 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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.Core.Types { using System; - using System.Collections.Generic; - using SysML2.NET.Core.POCO.Root.Annotations; - using SysML2.NET.Core.POCO.Root.Elements; - using SysML2.NET.Core.POCO.Root.Namespaces; + using SysML2.NET.Exceptions; /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class UnioningExtensions { @@ -37,16 +34,21 @@ internal static class UnioningExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IType ComputeTypeUnioned(this IUnioning unioningSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); - } + if (unioningSubject == null) + { + throw new ArgumentNullException(nameof(unioningSubject)); + } + return unioningSubject.OwningRelatedElement as IType + ?? throw new IncompleteModelException( + $"{nameof(unioningSubject)} must have an owning related element of type {nameof(IType)}"); + } } }