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
64 changes: 51 additions & 13 deletions SysML2.NET.Tests/Extend/ForLoopActionUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,82 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="ForLoopActionUsageExtensionsTestFixture.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.Core.Types;
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.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.Attributes;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Extensions;

[TestFixture]
public class ForLoopActionUsageExtensionsTestFixture
{
[Test]
public void ComputeLoopVariable_ThrowsNotSupportedException()
public void VerifyComputeLoopVariable()
{
Assert.That(() => ((IForLoopActionUsage)null).ComputeLoopVariable(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IForLoopActionUsage)null).ComputeLoopVariable(), Throws.TypeOf<ArgumentNullException>());

// No ownedFeature -> ownedFeature.FirstOrDefault() is null -> null.
Assert.That(new ForLoopActionUsage().ComputeLoopVariable(), Is.Null);

// First ownedFeature IS a ReferenceUsage -> returned via the as-cast.
var subjectWithLoopVariable = new ForLoopActionUsage();
var loopVariable = new ReferenceUsage();
subjectWithLoopVariable.AssignOwnership(new FeatureMembership(), loopVariable);

// First ownedFeature is NOT a ReferenceUsage -> the as-cast yields null.
var subjectWithNonReferenceFirstFeature = new ForLoopActionUsage();
subjectWithNonReferenceFirstFeature.AssignOwnership(new FeatureMembership(), new AttributeUsage());

using (Assert.EnterMultipleScope())
{
// loopVariable = ownedFeature->first() as ReferenceUsage
Assert.That(subjectWithLoopVariable.ComputeLoopVariable(), Is.SameAs(loopVariable));
Assert.That(subjectWithNonReferenceFirstFeature.ComputeLoopVariable(), Is.Null);
}
}

[Test]
public void ComputeSeqArgument_ThrowsNotSupportedException()
public void VerifyComputeSeqArgument()
{
Assert.That(() => ((IForLoopActionUsage)null).ComputeSeqArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IForLoopActionUsage)null).ComputeSeqArgument(), Throws.TypeOf<ArgumentNullException>());

// No input parameter -> argument(1) is out of range -> null.
Assert.That(new ForLoopActionUsage().ComputeSeqArgument(), Is.Null);

var seqExpression = new LiteralInteger();
var subjectWithSeqArgument = new ForLoopActionUsage();
var inputParameter = new ReferenceUsage { Direction = FeatureDirectionKind.In };
subjectWithSeqArgument.AssignOwnership(new FeatureMembership(), inputParameter);
inputParameter.AssignOwnership(new FeatureValue(), seqExpression);

// seqArgument = argument(1)
Assert.That(subjectWithSeqArgument.ComputeSeqArgument(), Is.SameAs(seqExpression));
}
}
}
46 changes: 36 additions & 10 deletions SysML2.NET.Tests/Extend/LoopActionUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="LoopActionUsageExtensionsTestFixture.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.Core.Types;
using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Extensions;

[TestFixture]
public class LoopActionUsageExtensionsTestFixture
{
[Test]
public void ComputeBodyAction_ThrowsNotSupportedException()
public void VerifyComputeBodyAction()
{
Assert.That(() => ((ILoopActionUsage)null).ComputeBodyAction(), Throws.TypeOf<NotSupportedException>());
// LoopActionUsage is abstract, so the concrete ILoopActionUsage subtype WhileLoopActionUsage is used as subject.
Assert.That(() => ((ILoopActionUsage)null).ComputeBodyAction(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> inputParameter(2) is out of range -> null.
Assert.That(new WhileLoopActionUsage().ComputeBodyAction(), Is.Null);

// Position-2 input parameter that IS an ActionUsage -> returned via the as-cast.
var subjectWithBodyAction = new WhileLoopActionUsage();
var bodyActionParameter = new ActionUsage { Direction = FeatureDirectionKind.In };
subjectWithBodyAction.AssignOwnership(new FeatureMembership(), new ReferenceUsage { Direction = FeatureDirectionKind.In });
subjectWithBodyAction.AssignOwnership(new FeatureMembership(), bodyActionParameter);

// Position-2 input parameter that is NOT an ActionUsage -> the as-cast yields null.
var subjectWithNonActionSecondParameter = new WhileLoopActionUsage();
subjectWithNonActionSecondParameter.AssignOwnership(new FeatureMembership(), new ReferenceUsage { Direction = FeatureDirectionKind.In });
subjectWithNonActionSecondParameter.AssignOwnership(new FeatureMembership(), new ReferenceUsage { Direction = FeatureDirectionKind.In });

using (Assert.EnterMultipleScope())
{
// bodyAction = inputParameter(2) as ActionUsage
Assert.That(subjectWithBodyAction.ComputeBodyAction(), Is.SameAs(bodyActionParameter));
Assert.That(subjectWithNonActionSecondParameter.ComputeBodyAction(), Is.Null);
}
}
}
}
64 changes: 54 additions & 10 deletions SysML2.NET.Tests/Extend/PerformActionUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,82 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="PerformActionUsageExtensionsTestFixture.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.Features;
using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.Attributes;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Extensions;

[TestFixture]
public class PerformActionUsageExtensionsTestFixture
{
[Test]
public void ComputePerformedAction_ThrowsNotSupportedException()
public void VerifyComputePerformedAction()
{
Assert.That(() => ((IPerformActionUsage)null).ComputePerformedAction(), Throws.TypeOf<ArgumentNullException>());

// No ownedReferenceSubsetting -> referencedFeatureTarget() is null -> returns self.
var subjectNoReferent = new PerformActionUsage();

Assert.That(subjectNoReferent.ComputePerformedAction(), Is.SameAs(subjectNoReferent));

// ReferenceSubsetting whose referent IS an ActionUsage -> returns that ActionUsage.
var subjectWithActionReferent = new PerformActionUsage();
var actionReferent = new ActionUsage();
subjectWithActionReferent.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = actionReferent });

// ReferenceSubsetting whose referent is NOT an ActionUsage -> the as-cast yields null.
var subjectWithNonActionReferent = new PerformActionUsage();
subjectWithNonActionReferent.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = new AttributeUsage() });

using (Assert.EnterMultipleScope())
{
Assert.That(subjectWithActionReferent.ComputePerformedAction(), Is.SameAs(actionReferent));
Assert.That(subjectWithNonActionReferent.ComputePerformedAction(), Is.Null);
}
}

[Test]
public void VerifyComputeRedefinedNamingFeatureOperation()
{
Assert.That(() => ((IPerformActionUsage)null).ComputePerformedAction(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IPerformActionUsage)null).ComputeRedefinedNamingFeatureOperation(), Throws.TypeOf<ArgumentNullException>());

// performedAction <> self (an ActionUsage referent) -> returns that performedAction.
var subjectWithActionReferent = new PerformActionUsage();
var actionReferent = new ActionUsage();
subjectWithActionReferent.AssignOwnership(new ReferenceSubsetting { ReferencedFeature = actionReferent });

// performedAction == self (no referent) -> falls through to the Usage-level namingFeature.
var subjectNoReferent = new PerformActionUsage();

using (Assert.EnterMultipleScope())
{
Assert.That(subjectWithActionReferent.ComputeRedefinedNamingFeatureOperation(), Is.SameAs(actionReferent));
Assert.That(subjectNoReferent.ComputeRedefinedNamingFeatureOperation(), Is.EqualTo(UsageExtensions.ComputeRedefinedNamingFeatureOperation(subjectNoReferent)));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,97 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="WhileLoopActionUsageExtensionsTestFixture.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.Core.Types;
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 WhileLoopActionUsageExtensionsTestFixture
{
[Test]
public void ComputeUntilArgument_ThrowsNotSupportedException()
public void VerifyComputeWhileArgument()
{
Assert.That(() => ((IWhileLoopActionUsage)null).ComputeUntilArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IWhileLoopActionUsage)null).ComputeWhileArgument(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> inputParameter(1) is out of range -> null.
Assert.That(new WhileLoopActionUsage().ComputeWhileArgument(), Is.Null);

// Position-1 input parameter that IS an Expression -> returned via the as-cast.
var whileExpression = new LiteralInteger { Direction = FeatureDirectionKind.In };
var subjectWithWhileArgument = new WhileLoopActionUsage();
subjectWithWhileArgument.AssignOwnership(new FeatureMembership(), whileExpression);

// Position-1 input parameter that is NOT an Expression -> the as-cast yields null.
var subjectWithNonExpressionFirstParameter = new WhileLoopActionUsage();
subjectWithNonExpressionFirstParameter.AssignOwnership(new FeatureMembership(), new ReferenceUsage { Direction = FeatureDirectionKind.In });

using (Assert.EnterMultipleScope())
{
// whileArgument = inputParameter(1) as Expression
Assert.That(subjectWithWhileArgument.ComputeWhileArgument(), Is.SameAs(whileExpression));
Assert.That(subjectWithNonExpressionFirstParameter.ComputeWhileArgument(), Is.Null);
}
}

[Test]
public void ComputeWhileArgument_ThrowsNotSupportedException()
public void VerifyComputeUntilArgument()
{
Assert.That(() => ((IWhileLoopActionUsage)null).ComputeWhileArgument(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IWhileLoopActionUsage)null).ComputeUntilArgument(), Throws.TypeOf<ArgumentNullException>());

// No input parameters -> inputParameter(3) is out of range -> null.
Assert.That(new WhileLoopActionUsage().ComputeUntilArgument(), Is.Null);

// Only two input parameters -> inputParameter(3) is out of range -> null.
var subjectWithTwoParameters = new WhileLoopActionUsage();
subjectWithTwoParameters.AssignOwnership(new FeatureMembership(), new LiteralInteger { Direction = FeatureDirectionKind.In });
subjectWithTwoParameters.AssignOwnership(new FeatureMembership(), new LiteralInteger { Direction = FeatureDirectionKind.In });

// Three input parameters where position-3 IS an Expression -> returned via the as-cast.
var untilExpression = new LiteralInteger { Direction = FeatureDirectionKind.In };
var subjectWithUntilArgument = new WhileLoopActionUsage();
subjectWithUntilArgument.AssignOwnership(new FeatureMembership(), new LiteralInteger { Direction = FeatureDirectionKind.In });
subjectWithUntilArgument.AssignOwnership(new FeatureMembership(), new LiteralInteger { Direction = FeatureDirectionKind.In });
subjectWithUntilArgument.AssignOwnership(new FeatureMembership(), untilExpression);

// Three input parameters where position-3 is NOT an Expression -> the as-cast yields null.
var subjectWithNonExpressionThirdParameter = new WhileLoopActionUsage();
subjectWithNonExpressionThirdParameter.AssignOwnership(new FeatureMembership(), new LiteralInteger { Direction = FeatureDirectionKind.In });
subjectWithNonExpressionThirdParameter.AssignOwnership(new FeatureMembership(), new LiteralInteger { Direction = FeatureDirectionKind.In });
subjectWithNonExpressionThirdParameter.AssignOwnership(new FeatureMembership(), new ReferenceUsage { Direction = FeatureDirectionKind.In });

using (Assert.EnterMultipleScope())
{
// untilArgument = inputParameter(3) as Expression
Assert.That(subjectWithUntilArgument.ComputeUntilArgument(), Is.SameAs(untilExpression));
Assert.That(subjectWithTwoParameters.ComputeUntilArgument(), Is.Null);
Assert.That(subjectWithNonExpressionThirdParameter.ComputeUntilArgument(), Is.Null);
}
}
}
}
Loading
Loading