Skip to content

Commit f9696c8

Browse files
Fix #88
1 parent c8d5dce commit f9696c8

2 files changed

Lines changed: 82 additions & 23 deletions

File tree

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,97 @@
11
// -------------------------------------------------------------------------------------------------
22
// <copyright file="AcceptActionUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
3-
//
3+
//
44
// Copyright 2022-2026 Starion Group S.A.
5-
//
5+
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
88
// You may obtain a copy of the License at
9-
//
9+
//
1010
// http://www.apache.org/licenses/LICENSE-2.0
11-
//
11+
//
1212
// Unless required by applicable law or agreed to in writing, software
1313
// distributed under the License is distributed on an "AS IS" BASIS,
1414
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
17-
//
17+
//
1818
// </copyright>
1919
// ------------------------------------------------------------------------------------------------
2020

2121
namespace SysML2.NET.Tests.Extend
2222
{
2323
using System;
24-
24+
2525
using NUnit.Framework;
26-
26+
27+
using SysML2.NET.Core.POCO.Core.Types;
2728
using SysML2.NET.Core.POCO.Systems.Actions;
29+
using SysML2.NET.Core.POCO.Systems.States;
30+
using SysML2.NET.Extensions;
2831

2932
[TestFixture]
3033
public class AcceptActionUsageExtensionsTestFixture
3134
{
3235
[Test]
33-
public void ComputePayloadArgument_ThrowsNotSupportedException()
36+
public void VerifyComputePayloadArgument()
37+
{
38+
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadArgument(), Throws.TypeOf<ArgumentNullException>());
39+
40+
var accept = new AcceptActionUsage();
41+
42+
// For Later: populated case depends on ActionUsageExtensions.ComputeArgumentOperation at SysML2.NET/Extend/ActionUsageExtensions.cs:157, which is still a stub.
43+
Assert.That(() => accept.ComputePayloadArgument(), Throws.TypeOf<NotSupportedException>());
44+
}
45+
46+
[Test]
47+
public void VerifyComputePayloadParameter()
3448
{
35-
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadArgument(), Throws.TypeOf<NotSupportedException>());
49+
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadParameter(), Throws.TypeOf<ArgumentNullException>());
50+
51+
var accept = new AcceptActionUsage();
52+
53+
// For Later: populated case depends on StepExtensions.ComputeParameter at SysML2.NET/Extend/StepExtensions.cs:71, which is still a stub.
54+
Assert.That(() => accept.ComputePayloadParameter(), Throws.TypeOf<NotSupportedException>());
3655
}
37-
56+
3857
[Test]
39-
public void ComputePayloadParameter_ThrowsNotSupportedException()
58+
public void VerifyComputeReceiverArgument()
4059
{
41-
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadParameter(), Throws.TypeOf<NotSupportedException>());
60+
Assert.That(() => ((IAcceptActionUsage)null).ComputeReceiverArgument(), Throws.TypeOf<ArgumentNullException>());
61+
62+
var accept = new AcceptActionUsage();
63+
64+
// For Later: populated case depends on ActionUsageExtensions.ComputeArgumentOperation at SysML2.NET/Extend/ActionUsageExtensions.cs:157, which is still a stub.
65+
Assert.That(() => accept.ComputeReceiverArgument(), Throws.TypeOf<NotSupportedException>());
4266
}
43-
67+
4468
[Test]
45-
public void ComputeReceiverArgument_ThrowsNotSupportedException()
69+
public void VerifyComputeIsTriggerActionOperation()
4670
{
47-
Assert.That(() => ((IAcceptActionUsage)null).ComputeReceiverArgument(), Throws.TypeOf<NotSupportedException>());
71+
Assert.That(() => ((IAcceptActionUsage)null).ComputeIsTriggerActionOperation(), Throws.TypeOf<ArgumentNullException>());
72+
73+
// Branch A — null owningType: no OwningRelationship set, so owningType is null → false.
74+
var acceptNoOwner = new AcceptActionUsage();
75+
76+
Assert.That(acceptNoOwner.ComputeIsTriggerActionOperation(), Is.False);
77+
78+
// Branch B — non-null owningType, not ITransitionUsage: owner is ActionDefinition → false.
79+
var actionDefinitionOwner = new ActionDefinition();
80+
var featureMembershipB = new FeatureMembership();
81+
actionDefinitionOwner.AssignOwnership(featureMembershipB, new AcceptActionUsage());
82+
var acceptNotTransition = new AcceptActionUsage();
83+
actionDefinitionOwner.AssignOwnership(new FeatureMembership(), acceptNotTransition);
84+
85+
Assert.That(acceptNotTransition.ComputeIsTriggerActionOperation(), Is.False);
86+
87+
// Branch C — owningType IS ITransitionUsage: triggerAction dispatch hits the ComputeTriggerAction stub.
88+
var transitionOwner = new TransitionUsage();
89+
var featureMembershipC = new FeatureMembership();
90+
var acceptInTransition = new AcceptActionUsage();
91+
transitionOwner.AssignOwnership(featureMembershipC, acceptInTransition);
92+
93+
// For Later: populated case depends on TransitionUsageExtensions.ComputeTriggerAction at SysML2.NET/Extend/TransitionUsageExtensions.cs:208, which is still a stub.
94+
Assert.That(() => acceptInTransition.ComputeIsTriggerActionOperation(), Throws.TypeOf<NotSupportedException>());
4895
}
4996
}
5097
}

SysML2.NET/Extend/AcceptActionUsageExtensions.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ internal static class AcceptActionUsageExtensions
7878
/// <returns>
7979
/// the computed result
8080
/// </returns>
81-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
8281
internal static IExpression ComputePayloadArgument(this IAcceptActionUsage acceptActionUsageSubject)
8382
{
84-
throw new NotSupportedException("Create a GitHub issue when this method is required");
83+
return acceptActionUsageSubject == null
84+
? throw new ArgumentNullException(nameof(acceptActionUsageSubject))
85+
: acceptActionUsageSubject.Argument(1);
8586
}
8687

8788
/// <summary>
@@ -101,10 +102,18 @@ internal static IExpression ComputePayloadArgument(this IAcceptActionUsage accep
101102
/// <returns>
102103
/// the computed result
103104
/// </returns>
104-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
105105
internal static IReferenceUsage ComputePayloadParameter(this IAcceptActionUsage acceptActionUsageSubject)
106106
{
107-
throw new NotSupportedException("Create a GitHub issue when this method is required");
107+
if (acceptActionUsageSubject == null)
108+
{
109+
throw new ArgumentNullException(nameof(acceptActionUsageSubject));
110+
}
111+
112+
var parameters = acceptActionUsageSubject.parameter;
113+
114+
return parameters.Count == 0
115+
? null
116+
: parameters[0] as IReferenceUsage;
108117
}
109118

110119
/// <summary>
@@ -122,10 +131,11 @@ internal static IReferenceUsage ComputePayloadParameter(this IAcceptActionUsage
122131
/// <returns>
123132
/// the computed result
124133
/// </returns>
125-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
126134
internal static IExpression ComputeReceiverArgument(this IAcceptActionUsage acceptActionUsageSubject)
127135
{
128-
throw new NotSupportedException("Create a GitHub issue when this method is required");
136+
return acceptActionUsageSubject == null
137+
? throw new ArgumentNullException(nameof(acceptActionUsageSubject))
138+
: acceptActionUsageSubject.Argument(2);
129139
}
130140

131141
/// <summary>
@@ -145,10 +155,12 @@ internal static IExpression ComputeReceiverArgument(this IAcceptActionUsage acce
145155
/// <returns>
146156
/// The expected <see cref="bool" />
147157
/// </returns>
148-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
149158
internal static bool ComputeIsTriggerActionOperation(this IAcceptActionUsage acceptActionUsageSubject)
150159
{
151-
throw new NotSupportedException("Create a GitHub issue when this method is required");
160+
return acceptActionUsageSubject == null
161+
? throw new ArgumentNullException(nameof(acceptActionUsageSubject))
162+
: acceptActionUsageSubject.owningType is ITransitionUsage transitionUsage
163+
&& transitionUsage.triggerAction.Contains(acceptActionUsageSubject);
152164
}
153165
}
154166
}

0 commit comments

Comments
 (0)