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
125 changes: 113 additions & 12 deletions SysML2.NET.Tests/Extend/AssignmentActionUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="AssignmentActionUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
//
// 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.
Expand All @@ -21,30 +21,131 @@
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.Expressions;
using SysML2.NET.Core.POCO.Kernel.FeatureValues;
using SysML2.NET.Core.POCO.Kernel.Metadata;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Extensions;

[TestFixture]
public class AssignmentActionUsageExtensionsTestFixture
{
[Test]
public void ComputeReferent_ThrowsNotSupportedException()
public void VerifyComputeReferent()
{
Assert.That(() => ((IAssignmentActionUsage)null).ComputeReferent(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAssignmentActionUsage)null).ComputeReferent(), Throws.TypeOf<ArgumentNullException>());

// No ownedMembership at all -> null.
var empty = new AssignmentActionUsage();

// A feature owned via a FeatureMembership is rejected by reject(FeatureMembership) -> null.
var featureMembershipOnly = new AssignmentActionUsage();
featureMembershipOnly.AssignOwnership(new FeatureMembership(), new Feature());

// A non-FeatureMembership membership whose memberElement is a MetadataFeature is excluded
// by the 'not MetadataFeature' filter -> null.
var metadataOnly = new AssignmentActionUsage();
var metadataMembership = new Membership();
metadataOnly.AssignOwnership(metadataMembership);
metadataMembership.MemberElement = new MetadataFeature();

// A non-FeatureMembership membership whose memberElement is a plain Feature -> returned.
var referentFeature = new Feature();
var positive = new AssignmentActionUsage();
var referentMembership = new Membership();
positive.AssignOwnership(referentMembership);
referentMembership.MemberElement = referentFeature;

// Ordering: the first qualifying membership in ownedMembership order wins.
var firstFeature = new Feature();
var secondFeature = new Feature();
var ordered = new AssignmentActionUsage();
var firstMembership = new Membership();
ordered.AssignOwnership(firstMembership);
firstMembership.MemberElement = firstFeature;
var secondMembership = new Membership();
ordered.AssignOwnership(secondMembership);
secondMembership.MemberElement = secondFeature;

using (Assert.EnterMultipleScope())
{
Assert.That(empty.ComputeReferent(), Is.Null);
Assert.That(featureMembershipOnly.ComputeReferent(), Is.Null);
Assert.That(metadataOnly.ComputeReferent(), Is.Null);
Assert.That(positive.ComputeReferent(), Is.SameAs(referentFeature));
Assert.That(ordered.ComputeReferent(), Is.SameAs(firstFeature));
}
}

[Test]
public void ComputeTargetArgument_ThrowsNotSupportedException()
public void VerifyComputeTargetArgument()
{
Assert.That(() => ((IAssignmentActionUsage)null).ComputeTargetArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAssignmentActionUsage)null).ComputeTargetArgument(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> argument(1) is null -> null.
Assert.That(new AssignmentActionUsage().ComputeTargetArgument(), Is.Null);

var targetExpression = new LiteralInteger();
var valueExpression = new LiteralInteger();
var assignmentActionUsage = CreateAssignmentActionUsageWithArguments(targetExpression, valueExpression);

using (Assert.EnterMultipleScope())
{
// targetArgument = argument(1)
Assert.That(assignmentActionUsage.ComputeTargetArgument(), Is.SameAs(targetExpression));
Assert.That(assignmentActionUsage.ComputeTargetArgument(), Is.Not.SameAs(valueExpression));
}
}

[Test]
public void ComputeValueExpression_ThrowsNotSupportedException()
public void VerifyComputeValueExpression()
{
Assert.That(() => ((IAssignmentActionUsage)null).ComputeValueExpression(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAssignmentActionUsage)null).ComputeValueExpression(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> argument(2) is null -> null.
Assert.That(new AssignmentActionUsage().ComputeValueExpression(), Is.Null);

var targetExpression = new LiteralInteger();
var valueExpression = new LiteralInteger();
var assignmentActionUsage = CreateAssignmentActionUsageWithArguments(targetExpression, valueExpression);

// Only a single input parameter present -> argument(2) is out of range -> null.
var singleArgumentAssignmentActionUsage = CreateAssignmentActionUsageWithArguments(new LiteralInteger());

using (Assert.EnterMultipleScope())
{
// valueExpression = argument(2)
Assert.That(assignmentActionUsage.ComputeValueExpression(), Is.SameAs(valueExpression));
Assert.That(assignmentActionUsage.ComputeValueExpression(), Is.Not.SameAs(targetExpression));
Assert.That(singleArgumentAssignmentActionUsage.ComputeValueExpression(), Is.Null);
}
}

/// <summary>
/// Builds an <see cref="AssignmentActionUsage" /> whose i-th owned input parameter carries a
/// <see cref="FeatureValue" /> whose value is the i-th supplied argument expression, so that
/// <c>Argument(i)</c> resolves to that expression.
/// </summary>
private static AssignmentActionUsage CreateAssignmentActionUsageWithArguments(params LiteralInteger[] argumentExpressions)
{
var assignmentActionUsage = new AssignmentActionUsage();

foreach (var argumentExpression in argumentExpressions)
{
var inputParameter = new ReferenceUsage { Direction = FeatureDirectionKind.In };
assignmentActionUsage.AssignOwnership(new FeatureMembership(), inputParameter);
inputParameter.AssignOwnership(new FeatureValue(), argumentExpression);
}

return assignmentActionUsage;
}
}
}
101 changes: 89 additions & 12 deletions SysML2.NET.Tests/Extend/IfActionUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="IfActionUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
//
// 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.
Expand All @@ -21,30 +21,107 @@
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.Expressions;
using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Extensions;

[TestFixture]
public class IfActionUsageExtensionsTestFixture
{
[Test]
public void ComputeElseAction_ThrowsNotSupportedException()
public void VerifyComputeElseAction()
{
Assert.That(() => ((IIfActionUsage)null).ComputeElseAction(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IIfActionUsage)null).ComputeElseAction(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> inputParameter(3) is null -> null.
Assert.That(new IfActionUsage().ComputeElseAction(), Is.Null);

// Only two input parameters -> inputParameter(3) is out of range -> null.
var twoParameterIfActionUsage = CreateIfActionUsageWithInputParameters(new LiteralInteger(), new ActionUsage());

// inputParameter(3) present and IS an IActionUsage -> returned.
var elseAction = new ActionUsage();
var ifActionUsage = CreateIfActionUsageWithInputParameters(new LiteralInteger(), new ActionUsage(), elseAction);

using (Assert.EnterMultipleScope())
{
Assert.That(twoParameterIfActionUsage.ComputeElseAction(), Is.Null);

// elseAction = inputParameter(3) as ActionUsage
Assert.That(ifActionUsage.ComputeElseAction(), Is.SameAs(elseAction));
}
}

[Test]
public void ComputeIfArgument_ThrowsNotSupportedException()
public void VerifyComputeIfArgument()
{
Assert.That(() => ((IIfActionUsage)null).ComputeIfArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IIfActionUsage)null).ComputeIfArgument(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> inputParameter(1) is null -> null.
Assert.That(new IfActionUsage().ComputeIfArgument(), Is.Null);

// inputParameter(1) present but NOT an IExpression -> the 'as IExpression' filter yields null.
var wrongTypeIfActionUsage = CreateIfActionUsageWithInputParameters(new ReferenceUsage());

// inputParameter(1) present and IS an IExpression -> returned.
var ifExpression = new LiteralInteger();
var ifActionUsage = CreateIfActionUsageWithInputParameters(ifExpression, new ActionUsage(), new ActionUsage());

using (Assert.EnterMultipleScope())
{
Assert.That(wrongTypeIfActionUsage.ComputeIfArgument(), Is.Null);

// ifArgument = inputParameter(1) as Expression
Assert.That(ifActionUsage.ComputeIfArgument(), Is.SameAs(ifExpression));
}
}

[Test]
public void ComputeThenAction_ThrowsNotSupportedException()
public void VerifyComputeThenAction()
{
Assert.That(() => ((IIfActionUsage)null).ComputeThenAction(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> inputParameter(2) is null -> null.
Assert.That(new IfActionUsage().ComputeThenAction(), Is.Null);

// inputParameter(2) present but NOT an IActionUsage -> the 'as IActionUsage' filter yields null.
var wrongTypeIfActionUsage = CreateIfActionUsageWithInputParameters(new LiteralInteger(), new ReferenceUsage());

// inputParameter(2) present and IS an IActionUsage -> returned.
var thenAction = new ActionUsage();
var ifActionUsage = CreateIfActionUsageWithInputParameters(new LiteralInteger(), thenAction, new ActionUsage());

using (Assert.EnterMultipleScope())
{
Assert.That(wrongTypeIfActionUsage.ComputeThenAction(), Is.Null);

// thenAction = inputParameter(2) as ActionUsage
Assert.That(ifActionUsage.ComputeThenAction(), Is.SameAs(thenAction));
}
}

/// <summary>
/// Builds an <see cref="IfActionUsage" /> owning the supplied features as ordered input parameters
/// (Direction = In), so that <c>InputParameter(i)</c> resolves to the i-th supplied feature.
/// </summary>
private static IfActionUsage CreateIfActionUsageWithInputParameters(params IFeature[] inputParameters)
{
Assert.That(() => ((IIfActionUsage)null).ComputeThenAction(), Throws.TypeOf<NotSupportedException>());
var ifActionUsage = new IfActionUsage();

foreach (var inputParameter in inputParameters)
{
inputParameter.Direction = FeatureDirectionKind.In;
ifActionUsage.AssignOwnership(new FeatureMembership(), inputParameter);
}

return ifActionUsage;
}
}
}
Loading
Loading