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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="InterfaceDefinitionExtensionsTestFixture.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,18 +21,50 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Systems.Attributes;
using SysML2.NET.Core.POCO.Systems.Interfaces;
using SysML2.NET.Core.POCO.Systems.Ports;
using SysML2.NET.Extensions;

[TestFixture]
public class InterfaceDefinitionExtensionsTestFixture
{
[Test]
public void ComputeInterfaceEnd_ThrowsNotSupportedException()
public void Verify_ComputeInterfaceEnd()
{
Assert.That(() => ((IInterfaceDefinition)null).ComputeInterfaceEnd(), Throws.TypeOf<NotSupportedException>());
Assert.That(
() => ((IInterfaceDefinition)null).ComputeInterfaceEnd(),
Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("interfaceDefinitionSubject"));

var emptyInterfaceDefinition = new InterfaceDefinition();

Assert.That(emptyInterfaceDefinition.ComputeInterfaceEnd(), Is.Empty);

var singleEndInterfaceDefinition = new InterfaceDefinition();
var singleEndPort = new PortUsage { IsEnd = true };
singleEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), singleEndPort);

Assert.That(singleEndInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([singleEndPort]));

var mixedIsEndInterfaceDefinition = new InterfaceDefinition();
var nonEndPort = new PortUsage { IsEnd = false };
var endPort = new PortUsage { IsEnd = true };
mixedIsEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), nonEndPort);
mixedIsEndInterfaceDefinition.AssignOwnership(new FeatureMembership(), endPort);

Assert.That(mixedIsEndInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([endPort]));

var typeFilteringInterfaceDefinition = new InterfaceDefinition();
var endPortUsage = new PortUsage { IsEnd = true };
var endAttributeUsage = new AttributeUsage { IsEnd = true };
typeFilteringInterfaceDefinition.AssignOwnership(new FeatureMembership(), endPortUsage);
typeFilteringInterfaceDefinition.AssignOwnership(new FeatureMembership(), endAttributeUsage);

Assert.That(typeFilteringInterfaceDefinition.ComputeInterfaceEnd(), Is.EqualTo([endPortUsage]));
}
}
}
50 changes: 44 additions & 6 deletions SysML2.NET.Tests/Extend/InterfaceUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="InterfaceUsageExtensionsTestFixture.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,18 +21,56 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Systems.Connections;
using SysML2.NET.Core.POCO.Systems.Interfaces;
using SysML2.NET.Extensions;

[TestFixture]
public class InterfaceUsageExtensionsTestFixture
{
[Test]
public void ComputeInterfaceDefinition_ThrowsNotSupportedException()
public void Verify_ComputeInterfaceDefinition()
{
Assert.That(() => ((IInterfaceUsage)null).ComputeInterfaceDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IInterfaceUsage)null).ComputeInterfaceDefinition(), Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("interfaceUsageSubject"));

// Empty InterfaceUsage: no FeatureTyping in OwnedRelationship -> empty list.
var emptyInterfaceUsage = new InterfaceUsage();

Assert.That(emptyInterfaceUsage.ComputeInterfaceDefinition(), Is.Empty);

// Single FeatureTyping typed by an InterfaceDefinition -> single-element list.
var singleInterfaceUsage = new InterfaceUsage();
var soleInterfaceDefinition = new InterfaceDefinition();
singleInterfaceUsage.AssignOwnership(new FeatureTyping { Type = soleInterfaceDefinition });

Assert.That(singleInterfaceUsage.ComputeInterfaceDefinition(), Is.EqualTo([soleInterfaceDefinition]));

// Filter discrimination: one FeatureTyping typed by InterfaceDefinition, one typed by a non-InterfaceDefinition ConnectionDefinition.
var filteringInterfaceUsage = new InterfaceUsage();
var keptInterfaceDefinition = new InterfaceDefinition();
var droppedConnectionDefinition = new ConnectionDefinition();
filteringInterfaceUsage.AssignOwnership(new FeatureTyping { Type = keptInterfaceDefinition });
filteringInterfaceUsage.AssignOwnership(new FeatureTyping { Type = droppedConnectionDefinition });

using (Assert.EnterMultipleScope())
{
Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Has.Count.EqualTo(1));
Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Does.Contain(keptInterfaceDefinition));
Assert.That(filteringInterfaceUsage.ComputeInterfaceDefinition(), Does.Not.Contain(droppedConnectionDefinition));
}

// Multiple matches: two FeatureTypings, both typed by distinct InterfaceDefinitions -> both, in order.
var multiInterfaceUsage = new InterfaceUsage();
var firstInterfaceDefinition = new InterfaceDefinition();
var secondInterfaceDefinition = new InterfaceDefinition();
multiInterfaceUsage.AssignOwnership(new FeatureTyping { Type = firstInterfaceDefinition });
multiInterfaceUsage.AssignOwnership(new FeatureTyping { Type = secondInterfaceDefinition });

Assert.That(multiInterfaceUsage.ComputeInterfaceDefinition(), Is.EqualTo([firstInterfaceDefinition, secondInterfaceDefinition]));
}
}
}
30 changes: 24 additions & 6 deletions SysML2.NET.Tests/Extend/PortDefinitionExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="PortDefinitionExtensionsTestFixture.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,18 +21,36 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.Parts;
using SysML2.NET.Core.POCO.Systems.Ports;
using SysML2.NET.Extensions;

[TestFixture]
public class PortDefinitionExtensionsTestFixture
{
[Test]
public void ComputeConjugatedPortDefinition_ThrowsNotSupportedException()
public void Verify_ComputeConjugatedPortDefinition()
{
Assert.That(() => ((IPortDefinition)null).ComputeConjugatedPortDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(
() => ((IPortDefinition)null).ComputeConjugatedPortDefinition(),
Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("portDefinitionSubject"));

var emptyPortDefinition = new PortDefinition();
Assert.That(emptyPortDefinition.ComputeConjugatedPortDefinition(), Is.Null);

var portDefinitionWithConjugated = new PortDefinition();
var conjugated = new ConjugatedPortDefinition();
portDefinitionWithConjugated.AssignOwnership(new OwningMembership(), conjugated);
Assert.That(portDefinitionWithConjugated.ComputeConjugatedPortDefinition(), Is.SameAs(conjugated));

var portDefinitionWithOtherMember = new PortDefinition();
var partUsage = new PartUsage();
portDefinitionWithOtherMember.AssignOwnership(new OwningMembership(), partUsage);
Assert.That(portDefinitionWithOtherMember.ComputeConjugatedPortDefinition(), Is.Null);
}
}
}
43 changes: 37 additions & 6 deletions SysML2.NET.Tests/Extend/PortUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="PortUsageExtensionsTestFixture.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,18 +21,49 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Systems.Occurrences;
using SysML2.NET.Core.POCO.Systems.Ports;
using SysML2.NET.Extensions;

[TestFixture]
public class PortUsageExtensionsTestFixture
{
[Test]
public void ComputePortDefinition_ThrowsNotSupportedException()
public void Verify_ComputePortDefinition()
{
Assert.That(() => ((IPortUsage)null).ComputePortDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(
() => ((IPortUsage)null).ComputePortDefinition(),
Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("portUsageSubject"));

var emptySubject = new PortUsage();

Assert.That(emptySubject.ComputePortDefinition(), Is.Empty);

var singleSubject = new PortUsage();
var portDefinition = new PortDefinition();
singleSubject.AssignOwnership(new FeatureTyping { Type = portDefinition });

Assert.That(singleSubject.ComputePortDefinition(), Is.EqualTo([portDefinition]));

var filterSubject = new PortUsage();
var filteredPortDefinition = new PortDefinition();
var nonPortOccurrenceDefinition = new OccurrenceDefinition();
filterSubject.AssignOwnership(new FeatureTyping { Type = filteredPortDefinition });
filterSubject.AssignOwnership(new FeatureTyping { Type = nonPortOccurrenceDefinition });

Assert.That(filterSubject.ComputePortDefinition(), Is.EqualTo([filteredPortDefinition]));

var multiSubject = new PortUsage();
var firstPortDefinition = new PortDefinition();
var secondPortDefinition = new PortDefinition();
multiSubject.AssignOwnership(new FeatureTyping { Type = firstPortDefinition });
multiSubject.AssignOwnership(new FeatureTyping { Type = secondPortDefinition });

Assert.That(multiSubject.ComputePortDefinition(), Is.EqualTo([firstPortDefinition, secondPortDefinition]));
}
}
}
60 changes: 16 additions & 44 deletions SysML2.NET/Extend/InterfaceDefinitionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,51 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="InterfaceDefinitionExtensions.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.Systems.Interfaces
{
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.Associations;
using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.Actions;
using SysML2.NET.Core.POCO.Systems.Allocations;
using SysML2.NET.Core.POCO.Systems.AnalysisCases;
using SysML2.NET.Core.POCO.Systems.Attributes;
using SysML2.NET.Core.POCO.Systems.Calculations;
using SysML2.NET.Core.POCO.Systems.Cases;
using SysML2.NET.Core.POCO.Systems.Connections;
using SysML2.NET.Core.POCO.Systems.Constraints;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Core.POCO.Systems.Enumerations;
using SysML2.NET.Core.POCO.Systems.Flows;
using SysML2.NET.Core.POCO.Systems.Items;
using SysML2.NET.Core.POCO.Systems.Metadata;
using SysML2.NET.Core.POCO.Systems.Occurrences;
using SysML2.NET.Core.POCO.Systems.Parts;
using SysML2.NET.Core.POCO.Systems.Ports;
using SysML2.NET.Core.POCO.Systems.Requirements;
using SysML2.NET.Core.POCO.Systems.States;
using SysML2.NET.Core.POCO.Systems.UseCases;
using SysML2.NET.Core.POCO.Systems.VerificationCases;
using SysML2.NET.Core.POCO.Systems.Views;

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

}
}
Loading
Loading