Skip to content

Commit c02a34f

Browse files
1 parent 19d5058 commit c02a34f

8 files changed

Lines changed: 219 additions & 208 deletions

SysML2.NET.Tests/Extend/InterfaceDefinitionExtensionsTestFixture.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// <copyright file="InterfaceDefinitionExtensionsTestFixture.cs" company="Starion Group S.A.">
33
//
4-
// Copyright 2022-2026 Starion Group S.A.
4+
// Copyright (C) 2022-2026 Starion Group S.A.
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,18 +21,50 @@
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;
28+
using SysML2.NET.Core.POCO.Systems.Attributes;
2729
using SysML2.NET.Core.POCO.Systems.Interfaces;
30+
using SysML2.NET.Core.POCO.Systems.Ports;
31+
using SysML2.NET.Extensions;
2832

2933
[TestFixture]
3034
public class InterfaceDefinitionExtensionsTestFixture
3135
{
3236
[Test]
33-
public void ComputeInterfaceEnd_ThrowsNotSupportedException()
37+
public void Verify_ComputeInterfaceEnd()
3438
{
35-
Assert.That(() => ((IInterfaceDefinition)null).ComputeInterfaceEnd(), Throws.TypeOf<NotSupportedException>());
39+
Assert.That(
40+
() => ((IInterfaceDefinition)null).ComputeInterfaceEnd(),
41+
Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("interfaceDefinitionSubject"));
42+
43+
var emptyInterfaceDefinition = new InterfaceDefinition();
44+
45+
Assert.That(emptyInterfaceDefinition.ComputeInterfaceEnd(), Is.Empty);
46+
47+
var singleEndInterfaceDefinition = new InterfaceDefinition();
48+
var singleEndPort = new PortUsage { IsEnd = true };
49+
singleEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), singleEndPort);
50+
51+
Assert.That(singleEndInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([singleEndPort]));
52+
53+
var mixedIsEndInterfaceDefinition = new InterfaceDefinition();
54+
var nonEndPort = new PortUsage { IsEnd = false };
55+
var endPort = new PortUsage { IsEnd = true };
56+
mixedIsEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), nonEndPort);
57+
mixedIsEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), endPort);
58+
59+
Assert.That(mixedIsEndInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([endPort]));
60+
61+
var typeFilteringInterfaceDefinition = new InterfaceDefinition();
62+
var endPortUsage = new PortUsage { IsEnd = true };
63+
var endAttributeUsage = new AttributeUsage { IsEnd = true };
64+
typeFilteringInterfaceDefinition.AssignOwnership(new FeatureMembership(), endPortUsage);
65+
typeFilteringInterfaceDefinition.AssignOwnership(new FeatureMembership(), endAttributeUsage);
66+
67+
Assert.That(typeFilteringInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([endPortUsage]));
3668
}
3769
}
3870
}

SysML2.NET.Tests/Extend/InterfaceUsageExtensionsTestFixture.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// <copyright file="InterfaceUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
33
//
4-
// Copyright 2022-2026 Starion Group S.A.
4+
// Copyright (C) 2022-2026 Starion Group S.A.
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,18 +21,56 @@
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.Features;
28+
using SysML2.NET.Core.POCO.Systems.Connections;
2729
using SysML2.NET.Core.POCO.Systems.Interfaces;
30+
using SysML2.NET.Extensions;
2831

2932
[TestFixture]
3033
public class InterfaceUsageExtensionsTestFixture
3134
{
3235
[Test]
33-
public void ComputeInterfaceDefinition_ThrowsNotSupportedException()
36+
public void Verify_ComputeInterfaceDefinition()
3437
{
35-
Assert.That(() => ((IInterfaceUsage)null).ComputeInterfaceDefinition(), Throws.TypeOf<NotSupportedException>());
38+
Assert.That(() => ((IInterfaceUsage)null).ComputeInterfaceDefinition(), Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("interfaceUsageSubject"));
39+
40+
// Empty InterfaceUsage: no FeatureTyping in OwnedRelationship -> empty list.
41+
var emptyInterfaceUsage = new InterfaceUsage();
42+
43+
Assert.That(emptyInterfaceUsage.ComputeInterfaceDefinition(), Is.Empty);
44+
45+
// Single FeatureTyping typed by an InterfaceDefinition -> single-element list.
46+
var singleInterfaceUsage = new InterfaceUsage();
47+
var soleInterfaceDefinition = new InterfaceDefinition();
48+
singleInterfaceUsage.AssignOwnership(new FeatureTyping { Type = soleInterfaceDefinition });
49+
50+
Assert.That(singleInterfaceUsage.ComputeInterfaceDefinition(), Is.EqualTo([soleInterfaceDefinition]));
51+
52+
// Filter discrimination: one FeatureTyping typed by InterfaceDefinition, one typed by a non-InterfaceDefinition ConnectionDefinition.
53+
var filteringInterfaceUsage = new InterfaceUsage();
54+
var keptInterfaceDefinition = new InterfaceDefinition();
55+
var droppedConnectionDefinition = new ConnectionDefinition();
56+
filteringInterfaceUsage.AssignOwnership(new FeatureTyping { Type = keptInterfaceDefinition });
57+
filteringInterfaceUsage.AssignOwnership(new FeatureTyping { Type = droppedConnectionDefinition });
58+
59+
using (Assert.EnterMultipleScope())
60+
{
61+
Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Has.Count.EqualTo(1));
62+
Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Does.Contain(keptInterfaceDefinition));
63+
Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Does.Not.Contain(droppedConnectionDefinition));
64+
}
65+
66+
// Multiple matches: two FeatureTypings, both typed by distinct InterfaceDefinitions -> both, in order.
67+
var multiInterfaceUsage = new InterfaceUsage();
68+
var firstInterfaceDefinition = new InterfaceDefinition();
69+
var secondInterfaceDefinition = new InterfaceDefinition();
70+
multiInterfaceUsage.AssignOwnership(new FeatureTyping { Type = firstInterfaceDefinition });
71+
multiInterfaceUsage.AssignOwnership(new FeatureTyping { Type = secondInterfaceDefinition });
72+
73+
Assert.That(multiInterfaceUsage.ComputeInterfaceDefinition(), Is.EqualTo([firstInterfaceDefinition, secondInterfaceDefinition]));
3674
}
3775
}
3876
}

SysML2.NET.Tests/Extend/PortDefinitionExtensionsTestFixture.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// <copyright file="PortDefinitionExtensionsTestFixture.cs" company="Starion Group S.A.">
33
//
4-
// Copyright 2022-2026 Starion Group S.A.
4+
// Copyright (C) 2022-2026 Starion Group S.A.
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,18 +21,36 @@
2121
namespace SysML2.NET.Tests.Extend
2222
{
2323
using System;
24-
24+
2525
using NUnit.Framework;
26-
26+
27+
using SysML2.NET.Core.POCO.Root.Namespaces;
28+
using SysML2.NET.Core.POCO.Systems.Parts;
2729
using SysML2.NET.Core.POCO.Systems.Ports;
30+
using SysML2.NET.Extensions;
2831

2932
[TestFixture]
3033
public class PortDefinitionExtensionsTestFixture
3134
{
3235
[Test]
33-
public void ComputeConjugatedPortDefinition_ThrowsNotSupportedException()
36+
public void Verify_ComputeConjugatedPortDefinition()
3437
{
35-
Assert.That(() => ((IPortDefinition)null).ComputeConjugatedPortDefinition(), Throws.TypeOf<NotSupportedException>());
38+
Assert.That(
39+
() => ((IPortDefinition)null).ComputeConjugatedPortDefinition(),
40+
Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("portDefinitionSubject"));
41+
42+
var emptyPortDefinition = new PortDefinition();
43+
Assert.That(emptyPortDefinition.ComputeConjugatedPortDefinition(), Is.Null);
44+
45+
var portDefinitionWithConjugated = new PortDefinition();
46+
var conjugated = new ConjugatedPortDefinition();
47+
portDefinitionWithConjugated.AssignOwnership(new OwningMembership(), conjugated);
48+
Assert.That(portDefinitionWithConjugated.ComputeConjugatedPortDefinition(), Is.SameAs(conjugated));
49+
50+
var portDefinitionWithOtherMember = new PortDefinition();
51+
var partUsage = new PartUsage();
52+
portDefinitionWithOtherMember.AssignOwnership(new OwningMembership(), partUsage);
53+
Assert.That(portDefinitionWithOtherMember.ComputeConjugatedPortDefinition(), Is.Null);
3654
}
3755
}
3856
}

SysML2.NET.Tests/Extend/PortUsageExtensionsTestFixture.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// <copyright file="PortUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
33
//
4-
// Copyright 2022-2026 Starion Group S.A.
4+
// Copyright (C) 2022-2026 Starion Group S.A.
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,18 +21,49 @@
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.Features;
28+
using SysML2.NET.Core.POCO.Systems.Occurrences;
2729
using SysML2.NET.Core.POCO.Systems.Ports;
30+
using SysML2.NET.Extensions;
2831

2932
[TestFixture]
3033
public class PortUsageExtensionsTestFixture
3134
{
3235
[Test]
33-
public void ComputePortDefinition_ThrowsNotSupportedException()
36+
public void Verify_ComputePortDefinition()
3437
{
35-
Assert.That(() => ((IPortUsage)null).ComputePortDefinition(), Throws.TypeOf<NotSupportedException>());
38+
Assert.That(
39+
() => ((IPortUsage)null).ComputePortDefinition(),
40+
Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("portUsageSubject"));
41+
42+
var emptySubject = new PortUsage();
43+
44+
Assert.That(emptySubject.ComputePortDefinition(), Is.Empty);
45+
46+
var singleSubject = new PortUsage();
47+
var portDefinition = new PortDefinition();
48+
singleSubject.AssignOwnership(new FeatureTyping { Type = portDefinition });
49+
50+
Assert.That(singleSubject.ComputePortDefinition(), Is.EqualTo([portDefinition]));
51+
52+
var filterSubject = new PortUsage();
53+
var filteredPortDefinition = new PortDefinition();
54+
var nonPortOccurrenceDefinition = new OccurrenceDefinition();
55+
filterSubject.AssignOwnership(new FeatureTyping { Type = filteredPortDefinition });
56+
filterSubject.AssignOwnership(new FeatureTyping { Type = nonPortOccurrenceDefinition });
57+
58+
Assert.That(filterSubject.ComputePortDefinition(), Is.EqualTo([filteredPortDefinition]));
59+
60+
var multiSubject = new PortUsage();
61+
var firstPortDefinition = new PortDefinition();
62+
var secondPortDefinition = new PortDefinition();
63+
multiSubject.AssignOwnership(new FeatureTyping { Type = firstPortDefinition });
64+
multiSubject.AssignOwnership(new FeatureTyping { Type = secondPortDefinition });
65+
66+
Assert.That(multiSubject.ComputePortDefinition(), Is.EqualTo([firstPortDefinition, secondPortDefinition]));
3667
}
3768
}
3869
}
Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,51 @@
11
// -------------------------------------------------------------------------------------------------
22
// <copyright file="InterfaceDefinitionExtensions.cs" company="Starion Group S.A.">
3-
//
4-
// Copyright (C) 2022-2026 Starion Group S.A.
5-
//
6-
// Licensed under the Apache License, Version 2.0 (the "License");
7-
// you may not use this file except in compliance with the License.
8-
// You may obtain a copy of the License at
9-
//
3+
//
4+
// Copyright (C) 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
1010
// http://www.apache.org/licenses/LICENSE-2.0
11-
//
11+
//
1212
// Unless required by applicable law or agreed to in writing, software
1313
// distributed under the License is distributed on an "AS IS" BASIS,
1414
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
17-
//
17+
//
1818
// </copyright>
1919
// ------------------------------------------------------------------------------------------------
2020

2121
namespace SysML2.NET.Core.POCO.Systems.Interfaces
2222
{
2323
using System;
2424
using System.Collections.Generic;
25+
using System.Linq;
2526

26-
using SysML2.NET.Core.Core.Types;
27-
using SysML2.NET.Core.Root.Namespaces;
28-
using SysML2.NET.Core.POCO.Core.Classifiers;
29-
using SysML2.NET.Core.POCO.Core.Features;
30-
using SysML2.NET.Core.POCO.Core.Types;
31-
using SysML2.NET.Core.POCO.Kernel.Associations;
32-
using SysML2.NET.Core.POCO.Root.Annotations;
33-
using SysML2.NET.Core.POCO.Root.Elements;
34-
using SysML2.NET.Core.POCO.Root.Namespaces;
35-
using SysML2.NET.Core.POCO.Systems.Actions;
36-
using SysML2.NET.Core.POCO.Systems.Allocations;
37-
using SysML2.NET.Core.POCO.Systems.AnalysisCases;
38-
using SysML2.NET.Core.POCO.Systems.Attributes;
39-
using SysML2.NET.Core.POCO.Systems.Calculations;
40-
using SysML2.NET.Core.POCO.Systems.Cases;
41-
using SysML2.NET.Core.POCO.Systems.Connections;
42-
using SysML2.NET.Core.POCO.Systems.Constraints;
43-
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
44-
using SysML2.NET.Core.POCO.Systems.Enumerations;
45-
using SysML2.NET.Core.POCO.Systems.Flows;
46-
using SysML2.NET.Core.POCO.Systems.Items;
47-
using SysML2.NET.Core.POCO.Systems.Metadata;
48-
using SysML2.NET.Core.POCO.Systems.Occurrences;
49-
using SysML2.NET.Core.POCO.Systems.Parts;
5027
using SysML2.NET.Core.POCO.Systems.Ports;
51-
using SysML2.NET.Core.POCO.Systems.Requirements;
52-
using SysML2.NET.Core.POCO.Systems.States;
53-
using SysML2.NET.Core.POCO.Systems.UseCases;
54-
using SysML2.NET.Core.POCO.Systems.VerificationCases;
55-
using SysML2.NET.Core.POCO.Systems.Views;
5628

5729
/// <summary>
58-
/// The <see cref="InterfaceDefinitionExtensions"/> class provides extensions methods for
59-
/// the <see cref="IInterfaceDefinition"/> interface
30+
/// The <see cref="InterfaceDefinitionExtensions" /> class provides extensions methods for
31+
/// the <see cref="IInterfaceDefinition" /> interface
6032
/// </summary>
6133
internal static class InterfaceDefinitionExtensions
6234
{
6335
/// <summary>
6436
/// Computes the derived property.
6537
/// </summary>
6638
/// <param name="interfaceDefinitionSubject">
67-
/// The subject <see cref="IInterfaceDefinition"/>
39+
/// The subject <see cref="IInterfaceDefinition" />
6840
/// </param>
6941
/// <returns>
7042
/// the computed result
7143
/// </returns>
72-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
7344
internal static List<IPortUsage> ComputeInterfaceEnd(this IInterfaceDefinition interfaceDefinitionSubject)
7445
{
75-
throw new NotSupportedException("Create a GitHub issue when this method is required");
46+
return interfaceDefinitionSubject == null
47+
? throw new ArgumentNullException(nameof(interfaceDefinitionSubject))
48+
: [..interfaceDefinitionSubject.feature.Where(feature => feature.IsEnd).OfType<IPortUsage>()];
7649
}
77-
7850
}
7951
}

0 commit comments

Comments
 (0)