Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 62 additions & 15 deletions SysML2.NET.Tests/Extend/AcceptActionUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,97 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="AcceptActionUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
//
//
// 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.
//
//
// </copyright>
// ------------------------------------------------------------------------------------------------

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<ArgumentNullException>());

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<NotSupportedException>());
}

[Test]
public void VerifyComputePayloadParameter()
{
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadParameter(), Throws.TypeOf<ArgumentNullException>());

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<NotSupportedException>());
}

[Test]
public void ComputePayloadParameter_ThrowsNotSupportedException()
public void VerifyComputeReceiverArgument()
{
Assert.That(() => ((IAcceptActionUsage)null).ComputePayloadParameter(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAcceptActionUsage)null).ComputeReceiverArgument(), Throws.TypeOf<ArgumentNullException>());

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<NotSupportedException>());
}

[Test]
public void ComputeReceiverArgument_ThrowsNotSupportedException()
public void VerifyComputeIsTriggerActionOperation()
{
Assert.That(() => ((IAcceptActionUsage)null).ComputeReceiverArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAcceptActionUsage)null).ComputeIsTriggerActionOperation(), Throws.TypeOf<ArgumentNullException>());

// 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<NotSupportedException>());
}
}
}
28 changes: 20 additions & 8 deletions SysML2.NET/Extend/AcceptActionUsageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@
/// <returns>
/// the computed result
/// </returns>
[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);
}

/// <summary>
Expand All @@ -101,10 +102,18 @@
/// <returns>
/// the computed result
/// </returns>
[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));
}

Check warning on line 110 in SysML2.NET/Extend/AcceptActionUsageExtensions.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=STARIONGROUP_SysML2.NET&issues=AZ465O_vGtJnIfb6YZu7&open=AZ465O_vGtJnIfb6YZu7&pullRequest=243

var parameters = acceptActionUsageSubject.parameter;

return parameters.Count == 0
? null
: parameters[0] as IReferenceUsage;
}

/// <summary>
Expand All @@ -122,10 +131,11 @@
/// <returns>
/// the computed result
/// </returns>
[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);
}

/// <summary>
Expand All @@ -145,10 +155,12 @@
/// <returns>
/// The expected <see cref="bool" />
/// </returns>
[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);
}
}
}
Loading