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
56 changes: 48 additions & 8 deletions SysML2.NET.Tests/Extend/BehaviorExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="BehaviorExtensionsTestFixture.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,24 +21,64 @@
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.Behaviors;
using SysML2.NET.Extensions;

[TestFixture]
public class BehaviorExtensionsTestFixture
{
[Test]
public void ComputeParameter_ThrowsNotSupportedException()
public void VerifyComputeParameter()
{
Assert.That(() => ((IBehavior)null).ComputeParameter(), Throws.TypeOf<NotSupportedException>());
// Null subject:
Assert.That(() => ((IBehavior)null).ComputeParameter(), Throws.TypeOf<ArgumentNullException>());

// Empty Behavior Parameter list:
var emptySubject = new Behavior();
Assert.That(emptySubject.ComputeParameter(), Has.Count.EqualTo(0));

// Typed by DirectedFeature:
var subject = new Behavior();
var parameter = new Feature { Direction = FeatureDirectionKind.In };
var plainFeature = new Feature();
subject.AssignOwnership(new FeatureMembership(), parameter);
subject.AssignOwnership(new FeatureMembership(), plainFeature);

using (Assert.EnterMultipleScope())
{
Assert.That(subject.ComputeParameter(), Does.Contain(parameter));
Assert.That(subject.ComputeParameter(), Does.Not.Contain(plainFeature));
}
}

[Test]
public void ComputeStep_ThrowsNotSupportedException()
public void VerifyComputeStep()
{
Assert.That(() => ((IBehavior)null).ComputeStep(), Throws.TypeOf<NotSupportedException>());
// Null subject:
Assert.That(() => ((IBehavior)null).ComputeStep(), Throws.TypeOf<ArgumentNullException>());

// Empty Behavior Step list:
var emptySubject = new Behavior();
Assert.That(emptySubject.ComputeStep(), Has.Count.EqualTo(0));

// Typed by Step:
var subject = new Behavior();
var step = new Step();
var plainFeature = new Feature();
subject.AssignOwnership(new FeatureMembership(), step);
subject.AssignOwnership(new FeatureMembership(), plainFeature);

using (Assert.EnterMultipleScope())
{
Assert.That(subject.ComputeStep(), Does.Contain(step));
Assert.That(subject.ComputeStep(), Does.Not.Contain(plainFeature));
}
}
}
}
46 changes: 20 additions & 26 deletions SysML2.NET/Extend/BehaviorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="BehaviorExtensions.cs" company="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.
// You may obtain a copy of the License at
//
//
// 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.
// 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.Core.POCO.Kernel.Behaviors
{
using System;
using System.Collections.Generic;
using System.Linq;

using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
using SysML2.NET.Core.POCO.Core.Classifiers;
using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Kernel.Classes;
using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;

/// <summary>
/// The <see cref="BehaviorExtensions"/> class provides extensions methods for
/// the <see cref="IBehavior"/> interface
/// The <see cref="BehaviorExtensions" /> class provides extensions methods for
/// the <see cref="IBehavior" /> interface
/// </summary>
internal static class BehaviorExtensions
{
/// <summary>
/// Computes the derived property.
/// </summary>
/// <param name="behaviorSubject">
/// The subject <see cref="IBehavior"/>
/// The subject <see cref="IBehavior" />
/// </param>
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List<IFeature> ComputeParameter(this IBehavior behaviorSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return behaviorSubject == null
? throw new ArgumentNullException(nameof(behaviorSubject))
: [..behaviorSubject.feature.Where(memberFeature => behaviorSubject.DirectionOf(memberFeature) != null)];
}

/// <summary>
Expand All @@ -64,16 +58,16 @@ internal static List<IFeature> ComputeParameter(this IBehavior behaviorSubject)
/// </code>
/// </remarks>
/// <param name="behaviorSubject">
/// The subject <see cref="IBehavior"/>
/// The subject <see cref="IBehavior" />
/// </param>
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List<IStep> ComputeStep(this IBehavior behaviorSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return behaviorSubject == null
? throw new ArgumentNullException(nameof(behaviorSubject))
: [..behaviorSubject.feature.OfType<IStep>()];
}

}
}
Loading