From 66139880b74638928fe869fc83494a75b3f38417 Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Wed, 24 Jun 2026 14:47:55 +0200 Subject: [PATCH 1/2] BehaviorExtension implementation (extensions+tests) --- .../Extend/BehaviorExtensionsTestFixture.cs | 50 ++++++++++++++++--- SysML2.NET/Extend/BehaviorExtensions.cs | 46 ++++++++--------- 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs index b95e2d79..d683d378 100644 --- a/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.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,58 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - + + using SysML2.NET.Core.Core.Types; + using SysML2.NET.Core.POCO.Core.Features; + using SysML2.NET.Core.POCO.Core.Types; using SysML2.NET.Core.POCO.Kernel.Behaviors; + using SysML2.NET.Extensions; [TestFixture] public class BehaviorExtensionsTestFixture { [Test] - public void ComputeParameter_ThrowsNotSupportedException() + public void VerifyComputeParameter() { - Assert.That(() => ((IBehavior)null).ComputeParameter(), Throws.TypeOf()); + // Null subject: + Assert.That(() => ((IBehavior)null).ComputeParameter(), Throws.TypeOf()); + + // Empty Behavior Parameter list: + var emptySubject = new Behavior(); + Assert.That(emptySubject.ComputeParameter(), Has.Count.EqualTo(0)); + + // Typed by DirectedFeature: + var subject = new Behavior(); + var parameter = new Feature { Direction = FeatureDirectionKind.In }; + var plainFeature = new Feature(); + + subject.AssignOwnership(new FeatureMembership(), parameter); + subject.AssignOwnership(new FeatureMembership(), plainFeature); + Assert.That(subject.ComputeParameter(), Does.Contain(parameter)); + Assert.That(subject.ComputeParameter(), Does.Not.Contain(plainFeature)); } - + [Test] - public void ComputeStep_ThrowsNotSupportedException() + public void VerifyComputeStep() { - Assert.That(() => ((IBehavior)null).ComputeStep(), Throws.TypeOf()); + // Null subject: + Assert.That(() => ((IBehavior)null).ComputeStep(), Throws.TypeOf()); + + // Empty Behavior Step list: + var emptySubject = new Behavior(); + Assert.That(emptySubject.ComputeStep(), Has.Count.EqualTo(0)); + + // Typed by Step: + var subject = new Behavior(); + var step = new Step(); + var plainFeature = new Feature(); + + subject.AssignOwnership(new FeatureMembership(), step); + subject.AssignOwnership(new FeatureMembership(), plainFeature); + Assert.That(subject.ComputeStep(), Does.Contain(step)); + Assert.That(subject.ComputeStep(), Does.Not.Contain(plainFeature)); } } } diff --git a/SysML2.NET/Extend/BehaviorExtensions.cs b/SysML2.NET/Extend/BehaviorExtensions.cs index 3a9f2531..89fa5968 100644 --- a/SysML2.NET/Extend/BehaviorExtensions.cs +++ b/SysML2.NET/Extend/BehaviorExtensions.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,20 +22,13 @@ namespace SysML2.NET.Core.POCO.Kernel.Behaviors { 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.Classes; - 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 BehaviorExtensions { @@ -43,15 +36,16 @@ internal static class BehaviorExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static List ComputeParameter(this IBehavior behaviorSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return behaviorSubject == null + ? throw new ArgumentNullException(nameof(behaviorSubject)) + : [..behaviorSubject.feature.Where(memberFeature => behaviorSubject.DirectionOf(memberFeature) != null)]; } /// @@ -64,16 +58,16 @@ internal static List ComputeParameter(this IBehavior behaviorSubject) /// /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static List ComputeStep(this IBehavior behaviorSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return behaviorSubject == null + ? throw new ArgumentNullException(nameof(behaviorSubject)) + : [..behaviorSubject.feature.OfType()]; } - } } From 6a71207b0f0b6c9e1aed83f22f6ee471073d6aef Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Wed, 24 Jun 2026 16:25:22 +0200 Subject: [PATCH 2/2] correction of multiple assertions in BehaviorExtensionsTestFixture.cs --- .../Extend/BehaviorExtensionsTestFixture.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs index d683d378..12eac816 100644 --- a/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs @@ -47,11 +47,14 @@ public void VerifyComputeParameter() var subject = new Behavior(); var parameter = new Feature { Direction = FeatureDirectionKind.In }; var plainFeature = new Feature(); - subject.AssignOwnership(new FeatureMembership(), parameter); subject.AssignOwnership(new FeatureMembership(), plainFeature); - Assert.That(subject.ComputeParameter(), Does.Contain(parameter)); - Assert.That(subject.ComputeParameter(), Does.Not.Contain(plainFeature)); + + using (Assert.EnterMultipleScope()) + { + Assert.That(subject.ComputeParameter(), Does.Contain(parameter)); + Assert.That(subject.ComputeParameter(), Does.Not.Contain(plainFeature)); + } } [Test] @@ -68,11 +71,14 @@ public void VerifyComputeStep() var subject = new Behavior(); var step = new Step(); var plainFeature = new Feature(); - subject.AssignOwnership(new FeatureMembership(), step); subject.AssignOwnership(new FeatureMembership(), plainFeature); - Assert.That(subject.ComputeStep(), Does.Contain(step)); - Assert.That(subject.ComputeStep(), Does.Not.Contain(plainFeature)); + + using (Assert.EnterMultipleScope()) + { + Assert.That(subject.ComputeStep(), Does.Contain(step)); + Assert.That(subject.ComputeStep(), Does.Not.Contain(plainFeature)); + } } } }