diff --git a/SysML2.NET.Tests/Extend/InterfaceDefinitionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/InterfaceDefinitionExtensionsTestFixture.cs index bf4b455a..b6ce1d3a 100644 --- a/SysML2.NET.Tests/Extend/InterfaceDefinitionExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/InterfaceDefinitionExtensionsTestFixture.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,50 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + + using SysML2.NET.Core.POCO.Core.Types; + using SysML2.NET.Core.POCO.Systems.Attributes; using SysML2.NET.Core.POCO.Systems.Interfaces; + using SysML2.NET.Core.POCO.Systems.Ports; + using SysML2.NET.Extensions; [TestFixture] public class InterfaceDefinitionExtensionsTestFixture { [Test] - public void ComputeInterfaceEnd_ThrowsNotSupportedException() + public void Verify_ComputeInterfaceEnd() { - Assert.That(() => ((IInterfaceDefinition)null).ComputeInterfaceEnd(), Throws.TypeOf()); + Assert.That( + () => ((IInterfaceDefinition)null).ComputeInterfaceEnd(), + Throws.TypeOf().With.Property("ParamName").EqualTo("interfaceDefinitionSubject")); + + var emptyInterfaceDefinition = new InterfaceDefinition(); + + Assert.That(emptyInterfaceDefinition.ComputeInterfaceEnd(), Is.Empty); + + var singleEndInterfaceDefinition = new InterfaceDefinition(); + var singleEndPort = new PortUsage { IsEnd = true }; + singleEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), singleEndPort); + + Assert.That(singleEndInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([singleEndPort])); + + var mixedIsEndInterfaceDefinition = new InterfaceDefinition(); + var nonEndPort = new PortUsage { IsEnd = false }; + var endPort = new PortUsage { IsEnd = true }; + mixedIsEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), nonEndPort); + mixedIsEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), endPort); + + Assert.That(mixedIsEndInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([endPort])); + + var typeFilteringInterfaceDefinition = new InterfaceDefinition(); + var endPortUsage = new PortUsage { IsEnd = true }; + var endAttributeUsage = new AttributeUsage { IsEnd = true }; + typeFilteringInterfaceDefinition.AssignOwnership(new FeatureMembership(), endPortUsage); + typeFilteringInterfaceDefinition.AssignOwnership(new FeatureMembership(), endAttributeUsage); + + Assert.That(typeFilteringInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([endPortUsage])); } } } diff --git a/SysML2.NET.Tests/Extend/InterfaceUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/InterfaceUsageExtensionsTestFixture.cs index 34c760dd..003bde51 100644 --- a/SysML2.NET.Tests/Extend/InterfaceUsageExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/InterfaceUsageExtensionsTestFixture.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,56 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + + using SysML2.NET.Core.POCO.Core.Features; + using SysML2.NET.Core.POCO.Systems.Connections; using SysML2.NET.Core.POCO.Systems.Interfaces; + using SysML2.NET.Extensions; [TestFixture] public class InterfaceUsageExtensionsTestFixture { [Test] - public void ComputeInterfaceDefinition_ThrowsNotSupportedException() + public void Verify_ComputeInterfaceDefinition() { - Assert.That(() => ((IInterfaceUsage)null).ComputeInterfaceDefinition(), Throws.TypeOf()); + Assert.That(() => ((IInterfaceUsage)null).ComputeInterfaceDefinition(), Throws.TypeOf().With.Property("ParamName").EqualTo("interfaceUsageSubject")); + + // Empty InterfaceUsage: no FeatureTyping in OwnedRelationship -> empty list. + var emptyInterfaceUsage = new InterfaceUsage(); + + Assert.That(emptyInterfaceUsage.ComputeInterfaceDefinition(), Is.Empty); + + // Single FeatureTyping typed by an InterfaceDefinition -> single-element list. + var singleInterfaceUsage = new InterfaceUsage(); + var soleInterfaceDefinition = new InterfaceDefinition(); + singleInterfaceUsage.AssignOwnership(new FeatureTyping { Type = soleInterfaceDefinition }); + + Assert.That(singleInterfaceUsage.ComputeInterfaceDefinition(), Is.EqualTo([soleInterfaceDefinition])); + + // Filter discrimination: one FeatureTyping typed by InterfaceDefinition, one typed by a non-InterfaceDefinition ConnectionDefinition. + var filteringInterfaceUsage = new InterfaceUsage(); + var keptInterfaceDefinition = new InterfaceDefinition(); + var droppedConnectionDefinition = new ConnectionDefinition(); + filteringInterfaceUsage.AssignOwnership(new FeatureTyping { Type = keptInterfaceDefinition }); + filteringInterfaceUsage.AssignOwnership(new FeatureTyping { Type = droppedConnectionDefinition }); + + using (Assert.EnterMultipleScope()) + { + Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Has.Count.EqualTo(1)); + Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Does.Contain(keptInterfaceDefinition)); + Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Does.Not.Contain(droppedConnectionDefinition)); + } + + // Multiple matches: two FeatureTypings, both typed by distinct InterfaceDefinitions -> both, in order. + var multiInterfaceUsage = new InterfaceUsage(); + var firstInterfaceDefinition = new InterfaceDefinition(); + var secondInterfaceDefinition = new InterfaceDefinition(); + multiInterfaceUsage.AssignOwnership(new FeatureTyping { Type = firstInterfaceDefinition }); + multiInterfaceUsage.AssignOwnership(new FeatureTyping { Type = secondInterfaceDefinition }); + + Assert.That(multiInterfaceUsage.ComputeInterfaceDefinition(), Is.EqualTo([firstInterfaceDefinition, secondInterfaceDefinition])); } } } diff --git a/SysML2.NET.Tests/Extend/PortDefinitionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/PortDefinitionExtensionsTestFixture.cs index 44f83415..f35d4222 100644 --- a/SysML2.NET.Tests/Extend/PortDefinitionExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/PortDefinitionExtensionsTestFixture.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.Root.Namespaces; + using SysML2.NET.Core.POCO.Systems.Parts; using SysML2.NET.Core.POCO.Systems.Ports; + using SysML2.NET.Extensions; [TestFixture] public class PortDefinitionExtensionsTestFixture { [Test] - public void ComputeConjugatedPortDefinition_ThrowsNotSupportedException() + public void Verify_ComputeConjugatedPortDefinition() { - Assert.That(() => ((IPortDefinition)null).ComputeConjugatedPortDefinition(), Throws.TypeOf()); + Assert.That( + () => ((IPortDefinition)null).ComputeConjugatedPortDefinition(), + Throws.TypeOf().With.Property("ParamName").EqualTo("portDefinitionSubject")); + + var emptyPortDefinition = new PortDefinition(); + Assert.That(emptyPortDefinition.ComputeConjugatedPortDefinition(), Is.Null); + + var portDefinitionWithConjugated = new PortDefinition(); + var conjugated = new ConjugatedPortDefinition(); + portDefinitionWithConjugated.AssignOwnership(new OwningMembership(), conjugated); + Assert.That(portDefinitionWithConjugated.ComputeConjugatedPortDefinition(), Is.SameAs(conjugated)); + + var portDefinitionWithOtherMember = new PortDefinition(); + var partUsage = new PartUsage(); + portDefinitionWithOtherMember.AssignOwnership(new OwningMembership(), partUsage); + Assert.That(portDefinitionWithOtherMember.ComputeConjugatedPortDefinition(), Is.Null); } } } diff --git a/SysML2.NET.Tests/Extend/PortUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/PortUsageExtensionsTestFixture.cs index 81176c41..d590c69f 100644 --- a/SysML2.NET.Tests/Extend/PortUsageExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/PortUsageExtensionsTestFixture.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,49 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + + using SysML2.NET.Core.POCO.Core.Features; + using SysML2.NET.Core.POCO.Systems.Occurrences; using SysML2.NET.Core.POCO.Systems.Ports; + using SysML2.NET.Extensions; [TestFixture] public class PortUsageExtensionsTestFixture { [Test] - public void ComputePortDefinition_ThrowsNotSupportedException() + public void Verify_ComputePortDefinition() { - Assert.That(() => ((IPortUsage)null).ComputePortDefinition(), Throws.TypeOf()); + Assert.That( + () => ((IPortUsage)null).ComputePortDefinition(), + Throws.TypeOf().With.Property("ParamName").EqualTo("portUsageSubject")); + + var emptySubject = new PortUsage(); + + Assert.That(emptySubject.ComputePortDefinition(), Is.Empty); + + var singleSubject = new PortUsage(); + var portDefinition = new PortDefinition(); + singleSubject.AssignOwnership(new FeatureTyping { Type = portDefinition }); + + Assert.That(singleSubject.ComputePortDefinition(), Is.EqualTo([portDefinition])); + + var filterSubject = new PortUsage(); + var filteredPortDefinition = new PortDefinition(); + var nonPortOccurrenceDefinition = new OccurrenceDefinition(); + filterSubject.AssignOwnership(new FeatureTyping { Type = filteredPortDefinition }); + filterSubject.AssignOwnership(new FeatureTyping { Type = nonPortOccurrenceDefinition }); + + Assert.That(filterSubject.ComputePortDefinition(), Is.EqualTo([filteredPortDefinition])); + + var multiSubject = new PortUsage(); + var firstPortDefinition = new PortDefinition(); + var secondPortDefinition = new PortDefinition(); + multiSubject.AssignOwnership(new FeatureTyping { Type = firstPortDefinition }); + multiSubject.AssignOwnership(new FeatureTyping { Type = secondPortDefinition }); + + Assert.That(multiSubject.ComputePortDefinition(), Is.EqualTo([firstPortDefinition, secondPortDefinition])); } } } diff --git a/SysML2.NET/Extend/InterfaceDefinitionExtensions.cs b/SysML2.NET/Extend/InterfaceDefinitionExtensions.cs index e3bbc880..a8673466 100644 --- a/SysML2.NET/Extend/InterfaceDefinitionExtensions.cs +++ b/SysML2.NET/Extend/InterfaceDefinitionExtensions.cs @@ -1,20 +1,20 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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. -// +// // // ------------------------------------------------------------------------------------------------ @@ -22,41 +22,13 @@ namespace SysML2.NET.Core.POCO.Systems.Interfaces { 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.POCO.Core.Classifiers; - using SysML2.NET.Core.POCO.Core.Features; - using SysML2.NET.Core.POCO.Core.Types; - using SysML2.NET.Core.POCO.Kernel.Associations; - 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.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.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 InterfaceDefinitionExtensions { @@ -64,16 +36,16 @@ internal static class InterfaceDefinitionExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static List ComputeInterfaceEnd(this IInterfaceDefinition interfaceDefinitionSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return interfaceDefinitionSubject == null + ? throw new ArgumentNullException(nameof(interfaceDefinitionSubject)) + : [..interfaceDefinitionSubject.feature.Where(feature => feature.IsEnd).OfType()]; } - } } diff --git a/SysML2.NET/Extend/InterfaceUsageExtensions.cs b/SysML2.NET/Extend/InterfaceUsageExtensions.cs index 588ca374..277c91f2 100644 --- a/SysML2.NET/Extend/InterfaceUsageExtensions.cs +++ b/SysML2.NET/Extend/InterfaceUsageExtensions.cs @@ -1,20 +1,20 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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. -// +// // // ------------------------------------------------------------------------------------------------ @@ -22,45 +22,13 @@ namespace SysML2.NET.Core.POCO.Systems.Interfaces { 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.Associations; - using SysML2.NET.Core.POCO.Kernel.Classes; - using SysML2.NET.Core.POCO.Kernel.Connectors; - using SysML2.NET.Core.POCO.Kernel.Structures; - 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.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.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 InterfaceUsageExtensions { @@ -68,16 +36,22 @@ internal static class InterfaceUsageExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static List ComputeInterfaceDefinition(this IInterfaceUsage interfaceUsageSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return interfaceUsageSubject == null + ? throw new ArgumentNullException(nameof(interfaceUsageSubject)) + : + [ + ..interfaceUsageSubject.OwnedRelationship + .OfType() + .Select(featureTyping => featureTyping.Type) + .OfType() + ]; } - } } diff --git a/SysML2.NET/Extend/PortDefinitionExtensions.cs b/SysML2.NET/Extend/PortDefinitionExtensions.cs index a430239b..281ec09d 100644 --- a/SysML2.NET/Extend/PortDefinitionExtensions.cs +++ b/SysML2.NET/Extend/PortDefinitionExtensions.cs @@ -1,62 +1,31 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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.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.Kernel.Structures; - 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; + using System.Linq; /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class PortDefinitionExtensions { @@ -75,16 +44,16 @@ internal static class PortDefinitionExtensions /// /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IConjugatedPortDefinition ComputeConjugatedPortDefinition(this IPortDefinition portDefinitionSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return portDefinitionSubject == null + ? throw new ArgumentNullException(nameof(portDefinitionSubject)) + : portDefinitionSubject.ownedMember.OfType().FirstOrDefault(); } - } } diff --git a/SysML2.NET/Extend/PortUsageExtensions.cs b/SysML2.NET/Extend/PortUsageExtensions.cs index 03e6d0a2..0afedf15 100644 --- a/SysML2.NET/Extend/PortUsageExtensions.cs +++ b/SysML2.NET/Extend/PortUsageExtensions.cs @@ -1,20 +1,20 @@ // ------------------------------------------------------------------------------------------------- // -// -// 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. -// +// // // ------------------------------------------------------------------------------------------------ @@ -22,42 +22,13 @@ namespace SysML2.NET.Core.POCO.Systems.Ports { 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.Classes; - 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 PortUsageExtensions { @@ -65,16 +36,22 @@ internal static class PortUsageExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static List ComputePortDefinition(this IPortUsage portUsageSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return portUsageSubject == null + ? throw new ArgumentNullException(nameof(portUsageSubject)) + : + [ + ..portUsageSubject.OwnedRelationship + .OfType() + .Select(featureTyping => featureTyping.Type) + .OfType() + ]; } - } }