diff --git a/SysML2.NET.Tests/Extend/AcceptActionUsageExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/AcceptActionUsageExtensionsTestFixture.cs index 58028a42..520487f5 100644 --- a/SysML2.NET.Tests/Extend/AcceptActionUsageExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/AcceptActionUsageExtensionsTestFixture.cs @@ -1,50 +1,97 @@ // ------------------------------------------------------------------------------------------------- // -// +// // Copyright 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.Tests.Extend { using System; - + using NUnit.Framework; - + + using SysML2.NET.Core.POCO.Core.Types; using SysML2.NET.Core.POCO.Systems.Actions; + using SysML2.NET.Core.POCO.Systems.States; + using SysML2.NET.Extensions; [TestFixture] public class AcceptActionUsageExtensionsTestFixture { [Test] - public void ComputePayloadArgument_ThrowsNotSupportedException() + public void VerifyComputePayloadArgument() + { + Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadArgument(), Throws.TypeOf()); + + var accept = new AcceptActionUsage(); + + // For Later: populated case depends on ActionUsageExtensions.ComputeArgumentOperation at SysML2.NET/Extend/ActionUsageExtensions.cs:157, which is still a stub. + Assert.That(() => accept.ComputePayloadArgument(), Throws.TypeOf()); + } + + [Test] + public void VerifyComputePayloadParameter() { - Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadArgument(), Throws.TypeOf()); + Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadParameter(), Throws.TypeOf()); + + var accept = new AcceptActionUsage(); + + // For Later: populated case depends on StepExtensions.ComputeParameter at SysML2.NET/Extend/StepExtensions.cs:71, which is still a stub. + Assert.That(() => accept.ComputePayloadParameter(), Throws.TypeOf()); } - + [Test] - public void ComputePayloadParameter_ThrowsNotSupportedException() + public void VerifyComputeReceiverArgument() { - Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadParameter(), Throws.TypeOf()); + Assert.That(() => ((IAcceptActionUsage)null).ComputeReceiverArgument(), Throws.TypeOf()); + + var accept = new AcceptActionUsage(); + + // For Later: populated case depends on ActionUsageExtensions.ComputeArgumentOperation at SysML2.NET/Extend/ActionUsageExtensions.cs:157, which is still a stub. + Assert.That(() => accept.ComputeReceiverArgument(), Throws.TypeOf()); } - + [Test] - public void ComputeReceiverArgument_ThrowsNotSupportedException() + public void VerifyComputeIsTriggerActionOperation() { - Assert.That(() => ((IAcceptActionUsage)null).ComputeReceiverArgument(), Throws.TypeOf()); + Assert.That(() => ((IAcceptActionUsage)null).ComputeIsTriggerActionOperation(), Throws.TypeOf()); + + // Branch A — null owningType: no OwningRelationship set, so owningType is null → false. + var acceptNoOwner = new AcceptActionUsage(); + + Assert.That(acceptNoOwner.ComputeIsTriggerActionOperation(), Is.False); + + // Branch B — non-null owningType, not ITransitionUsage: owner is ActionDefinition → false. + var actionDefinitionOwner = new ActionDefinition(); + var featureMembershipB = new FeatureMembership(); + actionDefinitionOwner.AssignOwnership(featureMembershipB, new AcceptActionUsage()); + var acceptNotTransition = new AcceptActionUsage(); + actionDefinitionOwner.AssignOwnership(new FeatureMembership(), acceptNotTransition); + + Assert.That(acceptNotTransition.ComputeIsTriggerActionOperation(), Is.False); + + // Branch C — owningType IS ITransitionUsage: triggerAction dispatch hits the ComputeTriggerAction stub. + var transitionOwner = new TransitionUsage(); + var featureMembershipC = new FeatureMembership(); + var acceptInTransition = new AcceptActionUsage(); + transitionOwner.AssignOwnership(featureMembershipC, acceptInTransition); + + // For Later: populated case depends on TransitionUsageExtensions.ComputeTriggerAction at SysML2.NET/Extend/TransitionUsageExtensions.cs:208, which is still a stub. + Assert.That(() => acceptInTransition.ComputeIsTriggerActionOperation(), Throws.TypeOf()); } } } diff --git a/SysML2.NET/Extend/AcceptActionUsageExtensions.cs b/SysML2.NET/Extend/AcceptActionUsageExtensions.cs index d569c554..b970aaa8 100644 --- a/SysML2.NET/Extend/AcceptActionUsageExtensions.cs +++ b/SysML2.NET/Extend/AcceptActionUsageExtensions.cs @@ -78,10 +78,11 @@ internal static class AcceptActionUsageExtensions /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IExpression ComputePayloadArgument(this IAcceptActionUsage acceptActionUsageSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return acceptActionUsageSubject == null + ? throw new ArgumentNullException(nameof(acceptActionUsageSubject)) + : acceptActionUsageSubject.Argument(1); } /// @@ -101,10 +102,18 @@ internal static IExpression ComputePayloadArgument(this IAcceptActionUsage accep /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IReferenceUsage ComputePayloadParameter(this IAcceptActionUsage acceptActionUsageSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + if (acceptActionUsageSubject == null) + { + throw new ArgumentNullException(nameof(acceptActionUsageSubject)); + } + + var parameters = acceptActionUsageSubject.parameter; + + return parameters.Count == 0 + ? null + : parameters[0] as IReferenceUsage; } /// @@ -122,10 +131,11 @@ internal static IReferenceUsage ComputePayloadParameter(this IAcceptActionUsage /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static IExpression ComputeReceiverArgument(this IAcceptActionUsage acceptActionUsageSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return acceptActionUsageSubject == null + ? throw new ArgumentNullException(nameof(acceptActionUsageSubject)) + : acceptActionUsageSubject.Argument(2); } /// @@ -145,10 +155,12 @@ internal static IExpression ComputeReceiverArgument(this IAcceptActionUsage acce /// /// The expected /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal static bool ComputeIsTriggerActionOperation(this IAcceptActionUsage acceptActionUsageSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return acceptActionUsageSubject == null + ? throw new ArgumentNullException(nameof(acceptActionUsageSubject)) + : acceptActionUsageSubject.owningType is ITransitionUsage transitionUsage + && transitionUsage.triggerAction.Contains(acceptActionUsageSubject); } } }