From abc9b75a11aca89f3dcb8bc86d4c02b37f71387a Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Thu, 25 Jun 2026 20:58:44 +0200 Subject: [PATCH 1/3] implemented computeownedportconjugated in conjugatedportdefinitionextensions --- .../ConjugatedPortDefinitionExtensions.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs b/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs index 880e3014..b2b7212a 100644 --- a/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs +++ b/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs @@ -22,6 +22,8 @@ namespace SysML2.NET.Core.POCO.Systems.Ports { using System; using System.Collections.Generic; + using SysML2.NET.Exceptions; + using SysML2.NET.Extensions; using SysML2.NET.Core.Core.Types; using SysML2.NET.Core.Root.Namespaces; @@ -68,10 +70,16 @@ internal static class ConjugatedPortDefinitionExtensions /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IPortDefinition ComputeOriginalPortDefinition(this IConjugatedPortDefinition conjugatedPortDefinitionSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + if (conjugatedPortDefinitionSubject == null) + { + throw new ArgumentNullException(nameof(conjugatedPortDefinitionSubject)); + } + + return conjugatedPortDefinitionSubject.owningMembership?.membershipOwningNamespace as IPortDefinition + ?? throw new IncompleteModelException( + $"{nameof(conjugatedPortDefinitionSubject)} must have an owning namespace of type {nameof(IPortDefinition)}"); } /// @@ -83,10 +91,15 @@ internal static IPortDefinition ComputeOriginalPortDefinition(this IConjugatedPo /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IPortConjugation ComputeOwnedPortConjugator(this IConjugatedPortDefinition conjugatedPortDefinitionSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + if (conjugatedPortDefinitionSubject == null) + { + throw new ArgumentNullException(nameof(conjugatedPortDefinitionSubject)); + } + + return conjugatedPortDefinitionSubject.OwnedRelationship + .RequireSingleOfType(nameof(conjugatedPortDefinitionSubject)); } /// From 603c173c85888d04032837b5b583c955cddffc26 Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Tue, 30 Jun 2026 23:03:20 +0200 Subject: [PATCH 2/3] implemented ConjugatedPortDefinitionExtensions and corresponding tests --- ...atedPortDefinitionExtensionsTestFixture.cs | 54 ++++++++++++--- .../ConjugatedPortDefinitionExtensions.cs | 65 +++++-------------- 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs index 67bfec2e..7b1eb3cc 100644 --- a/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.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,24 +21,62 @@ 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.Ports; + using SysML2.NET.Exceptions; + using SysML2.NET.Extensions; [TestFixture] public class ConjugatedPortDefinitionExtensionsTestFixture { [Test] - public void ComputeOriginalPortDefinition_ThrowsNotSupportedException() + public void VerifyComputeOriginalPortDefinition() { - Assert.That(() => ((IConjugatedPortDefinition)null).ComputeOriginalPortDefinition(), Throws.TypeOf()); + // Null Subject: + Assert.That(() => ((IConjugatedPortDefinition)null).ComputeOriginalPortDefinition(), Throws.TypeOf()); + + // Missing Owning Membership: + var emptyConjugatedPortDefinition = new ConjugatedPortDefinition(); + Assert.That(() => emptyConjugatedPortDefinition.ComputeOriginalPortDefinition(), Throws.TypeOf()); + + // With Original Port Definition: + var originalPortDefinition = new PortDefinition(); + var conjugatedPortDefinition = new ConjugatedPortDefinition(); + originalPortDefinition.AssignOwnership(new OwningMembership(), conjugatedPortDefinition); + Assert.That(conjugatedPortDefinition.ComputeOriginalPortDefinition(), Is.SameAs(originalPortDefinition)); + + // Wrong Owner Type: + var nonPortDefinitionOwner = new Namespace(); + var conjugatedWithNonPortDefinitionOwner = new ConjugatedPortDefinition(); + nonPortDefinitionOwner.AssignOwnership(new OwningMembership(), conjugatedWithNonPortDefinitionOwner); + Assert.That(() => conjugatedWithNonPortDefinitionOwner.ComputeOriginalPortDefinition(), Throws.TypeOf()); } - + [Test] - public void ComputeOwnedPortConjugator_ThrowsNotSupportedException() + public void VerifyComputeOwnedPortConjugator() { - Assert.That(() => ((IConjugatedPortDefinition)null).ComputeOwnedPortConjugator(), Throws.TypeOf()); + // Null Subject: + Assert.That(() => ((IConjugatedPortDefinition)null).ComputeOwnedPortConjugator(), Throws.TypeOf()); + + // Missing Port Conjugation: + var emptyConjugatedPortDefinition = new ConjugatedPortDefinition(); + Assert.That(() => emptyConjugatedPortDefinition.ComputeOwnedPortConjugator(), Throws.TypeOf()); + + // With Owned Port Conjugator: + var conjugatedPortDefinition = new ConjugatedPortDefinition(); + var portConjugation = new PortConjugation(); + ((IContainedElement)conjugatedPortDefinition).OwnedRelationship.Add(portConjugation); + Assert.That(conjugatedPortDefinition.ComputeOwnedPortConjugator(), Is.SameAs(portConjugation)); + + // Multiple Port Conjugations: + var conjugatedWithMultiplePortConjugations = new ConjugatedPortDefinition(); + ((IContainedElement)conjugatedWithMultiplePortConjugations).OwnedRelationship.Add(new PortConjugation()); + ((IContainedElement)conjugatedWithMultiplePortConjugations).OwnedRelationship.Add(new PortConjugation()); + Assert.That(() => conjugatedWithMultiplePortConjugations.ComputeOwnedPortConjugator(), Throws.TypeOf()); } } } diff --git a/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs b/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs index b2b7212a..672c844f 100644 --- a/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs +++ b/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs @@ -1,63 +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.Ports { using System; - using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; + using SysML2.NET.Exceptions; using SysML2.NET.Extensions; - using SysML2.NET.Core.Core.Types; - using SysML2.NET.Core.Root.Namespaces; - 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.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.Requirements; - 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; - /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class ConjugatedPortDefinitionExtensions { @@ -65,7 +36,7 @@ internal static class ConjugatedPortDefinitionExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result @@ -86,7 +57,7 @@ internal static IPortDefinition ComputeOriginalPortDefinition(this IConjugatedPo /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result @@ -99,7 +70,7 @@ internal static IPortConjugation ComputeOwnedPortConjugator(this IConjugatedPort } return conjugatedPortDefinitionSubject.OwnedRelationship - .RequireSingleOfType(nameof(conjugatedPortDefinitionSubject)); + .SingleStrict(nameof(conjugatedPortDefinitionSubject)); } /// @@ -116,12 +87,12 @@ internal static IPortConjugation ComputeOwnedPortConjugator(this IConjugatedPort /// /// /// - /// The subject + /// The subject /// /// /// The expected /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [ExcludeFromCodeCoverage] internal static string ComputeRedefinedEffectiveNameOperation(this IConjugatedPortDefinition conjugatedPortDefinitionSubject) { throw new NotSupportedException("Create a GitHub issue when this method is required"); From bfc13d1b344ccc43560cde57b34d7ed18adc636d Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Thu, 2 Jul 2026 18:46:47 +0200 Subject: [PATCH 3/3] implemented third method of ConjugatedPortDefinitionExtensions with corresponding test --- ...atedPortDefinitionExtensionsTestFixture.cs | 24 +++++++++++++++++++ .../ConjugatedPortDefinitionExtensions.cs | 13 +++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs index 7b1eb3cc..c6878487 100644 --- a/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/ConjugatedPortDefinitionExtensionsTestFixture.cs @@ -78,5 +78,29 @@ public void VerifyComputeOwnedPortConjugator() ((IContainedElement)conjugatedWithMultiplePortConjugations).OwnedRelationship.Add(new PortConjugation()); Assert.That(() => conjugatedWithMultiplePortConjugations.ComputeOwnedPortConjugator(), Throws.TypeOf()); } + + [Test] + public void VerifyComputeRedefinedEffectiveNameOperation() + { + // Null subject: + Assert.That(() => ((IConjugatedPortDefinition)null).ComputeRedefinedEffectiveNameOperation(), Throws.TypeOf()); + + // Missing original port definition: + var emptyConjugatedPortDefinition = new ConjugatedPortDefinition(); + Assert.That(() => emptyConjugatedPortDefinition.ComputeRedefinedEffectiveNameOperation(), Throws.TypeOf()); + + // Original name is null: + var originalPortDefinitionWithoutName = new PortDefinition(); + var conjugatedPortDefinitionWithoutOriginalName = new ConjugatedPortDefinition(); + originalPortDefinitionWithoutName.AssignOwnership(new OwningMembership(), conjugatedPortDefinitionWithoutOriginalName); + Assert.That(conjugatedPortDefinitionWithoutOriginalName.ComputeRedefinedEffectiveNameOperation(), Is.Null); + + // Original name exists: + var originalPortDefinition = new PortDefinition { DeclaredName = "port" }; + var conjugatedPortDefinition = new ConjugatedPortDefinition(); + originalPortDefinition.AssignOwnership(new OwningMembership(), conjugatedPortDefinition); + Assert.That(conjugatedPortDefinition.ComputeRedefinedEffectiveNameOperation(), Is.EqualTo("~port")); + } + } } diff --git a/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs b/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs index 672c844f..1a76832a 100644 --- a/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs +++ b/SysML2.NET/Extend/ConjugatedPortDefinitionExtensions.cs @@ -21,7 +21,6 @@ namespace SysML2.NET.Core.POCO.Systems.Ports { using System; - using System.Diagnostics.CodeAnalysis; using SysML2.NET.Exceptions; using SysML2.NET.Extensions; @@ -92,10 +91,18 @@ internal static IPortConjugation ComputeOwnedPortConjugator(this IConjugatedPort /// /// The expected /// - [ExcludeFromCodeCoverage] internal static string ComputeRedefinedEffectiveNameOperation(this IConjugatedPortDefinition conjugatedPortDefinitionSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + if (conjugatedPortDefinitionSubject == null) + { + throw new ArgumentNullException(nameof(conjugatedPortDefinitionSubject)); + } + + var originalName = conjugatedPortDefinitionSubject.originalPortDefinition.name; + + return originalName is null + ? null + : $"~{originalName}"; } } }