Skip to content

Commit b211c7d

Browse files
Fix #89
1 parent b40d7cc commit b211c7d

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

SysML2.NET.Tests/Extend/ActionDefinitionExtensionsTestFixture.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,39 @@
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.DefinitionAndUsage;
30+
using SysML2.NET.Extensions;
2831

2932
[TestFixture]
3033
public class ActionDefinitionExtensionsTestFixture
3134
{
3235
[Test]
33-
public void ComputeAction_ThrowsNotSupportedException()
36+
public void VerifyComputeAction()
3437
{
35-
Assert.That(() => ((IActionDefinition)null).ComputeAction(), Throws.TypeOf<NotSupportedException>());
38+
Assert.That(() => ((IActionDefinition)null).ComputeAction(), Throws.TypeOf<ArgumentNullException>());
39+
40+
var emptyActionDefinition = new ActionDefinition();
41+
42+
Assert.That(emptyActionDefinition.ComputeAction(), Has.Count.EqualTo(0));
43+
44+
// Only ActionUsage instances must be returned; a bare Usage must be filtered out.
45+
var subject = new ActionDefinition();
46+
var actionUsage = new ActionUsage();
47+
var bareUsage = new Usage();
48+
49+
subject.AssignOwnership(new FeatureMembership(), actionUsage);
50+
subject.AssignOwnership(new FeatureMembership(), bareUsage);
51+
52+
using (Assert.EnterMultipleScope())
53+
{
54+
Assert.That(subject.ComputeAction(), Does.Contain(actionUsage));
55+
Assert.That(subject.ComputeAction(), Does.Not.Contain(bareUsage));
56+
}
3657
}
3758
}
3859
}

SysML2.NET/Extend/ActionDefinitionExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Systems.Actions
2222
{
2323
using System;
2424
using System.Collections.Generic;
25+
using System.Linq;
2526

2627
using SysML2.NET.Core.Core.Types;
2728
using SysML2.NET.Core.Root.Namespaces;
@@ -75,10 +76,11 @@ internal static class ActionDefinitionExtensions
7576
/// <returns>
7677
/// the computed result
7778
/// </returns>
78-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
7979
internal static List<IActionUsage> ComputeAction(this IActionDefinition actionDefinitionSubject)
8080
{
81-
throw new NotSupportedException("Create a GitHub issue when this method is required");
81+
return actionDefinitionSubject == null
82+
? throw new ArgumentNullException(nameof(actionDefinitionSubject))
83+
: [.. actionDefinitionSubject.usage.OfType<IActionUsage>()];
8284
}
8385

8486
}

0 commit comments

Comments
 (0)