diff --git a/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs index b95e2d79..12eac816 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,64 @@ 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); + + using (Assert.EnterMultipleScope()) + { + 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); + + using (Assert.EnterMultipleScope()) + { + 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()]; } - } }