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
2 changes: 1 addition & 1 deletion SysML2.NET.Tests/Extend/ExpressionExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ExpressionExtensionsTestFixture.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 Down
37 changes: 32 additions & 5 deletions SysML2.NET.Tests/Extend/IntersectingExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="IntersectingExtensionsTestFixture.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,45 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Exceptions;

using Type = SysML2.NET.Core.POCO.Core.Types.Type;

[TestFixture]
public class IntersectingExtensionsTestFixture
{
[Test]
public void ComputeTypeIntersected_ThrowsNotSupportedException()
public void VerifyComputeTypeIntersected()
{
Assert.That(() => ((IIntersecting)null).ComputeTypeIntersected(), Throws.TypeOf<NotSupportedException>());
// Null subject → ArgumentNullException.
Assert.That(() => ((IIntersecting)null).ComputeTypeIntersected(), Throws.TypeOf<ArgumentNullException>());

// Empty Intersecting (OwningRelatedElement is null) → [1..1] violation: IncompleteModelException.
var emptyIntersecting = new Intersecting();

Assert.That(() => emptyIntersecting.ComputeTypeIntersected(), Throws.TypeOf<IncompleteModelException>());

// OwningRelatedElement is an IType → returns the same instance.
var type = new Type();
var intersectingWithType = new Intersecting();

((IContainedRelationship)intersectingWithType).OwningRelatedElement = type;

Assert.That(intersectingWithType.ComputeTypeIntersected(), Is.SameAs(type));

// OwningRelatedElement is a non-IType (Namespace) → [1..1] type violation: IncompleteModelException.
var namespaceObj = new Namespace();
var intersectingWithNamespace = new Intersecting();

((IContainedRelationship)intersectingWithNamespace).OwningRelatedElement = namespaceObj;

Assert.That(() => intersectingWithNamespace.ComputeTypeIntersected(), Throws.TypeOf<IncompleteModelException>());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ObjectiveMembershipExtensionsTestFixture.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 Down
34 changes: 29 additions & 5 deletions SysML2.NET.Tests/Extend/PortConjugationExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="PortConjugationExtensionsTestFixture.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,42 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Systems.Ports;
using SysML2.NET.Exceptions;

[TestFixture]
public class PortConjugationExtensionsTestFixture
{
[Test]
public void ComputeConjugatedPortDefinition_ThrowsNotSupportedException()
public void VerifyComputeConjugatedPortDefinition()
{
Assert.That(() => ((IPortConjugation)null).ComputeConjugatedPortDefinition(), Throws.TypeOf<NotSupportedException>());
// Null subject → ArgumentNullException.
Assert.That(() => ((IPortConjugation)null).ComputeConjugatedPortDefinition(), Throws.TypeOf<ArgumentNullException>());

// Empty PortConjugation (OwningRelatedElement is null) → [1..1] violation: IncompleteModelException.
var emptyPortConj = new PortConjugation();

Assert.That(() => emptyPortConj.ComputeConjugatedPortDefinition(), Throws.TypeOf<IncompleteModelException>());

// OwningRelatedElement is an IConjugatedPortDefinition → returns the same instance.
var conjugated = new ConjugatedPortDefinition();
var portConjWithConjugated = new PortConjugation();

((IContainedRelationship)portConjWithConjugated).OwningRelatedElement = conjugated;

Assert.That(portConjWithConjugated.ComputeConjugatedPortDefinition(), Is.SameAs(conjugated));

// OwningRelatedElement is a PortDefinition (IPortDefinition but NOT IConjugatedPortDefinition) → [1..1] type violation: IncompleteModelException.
var portDefinition = new PortDefinition();
var portConjWithPortDefinition = new PortConjugation();

((IContainedRelationship)portConjWithPortDefinition).OwningRelatedElement = portDefinition;

Assert.That(() => portConjWithPortDefinition.ComputeConjugatedPortDefinition(), Throws.TypeOf<IncompleteModelException>());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ResultExpressionMembershipExtensionsTestFixture.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 Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="StakeholderMembershipExtensionsTestFixture.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 Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="StateSubactionMembershipExtensionsTestFixture.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 Down
2 changes: 1 addition & 1 deletion SysML2.NET.Tests/Extend/StateUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="StateUsageExtensionsTestFixture.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 Down
28 changes: 23 additions & 5 deletions SysML2.NET.Tests/Extend/TypeFeaturingExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="TypeFeaturingExtensionsTestFixture.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.Core.Features;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;

[TestFixture]
public class TypeFeaturingExtensionsTestFixture
{
[Test]
public void ComputeOwningFeatureOfType_ThrowsNotSupportedException()
public void VerifyComputeOwningFeatureOfType()
{
Assert.That(() => ((ITypeFeaturing)null).ComputeOwningFeatureOfType(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((ITypeFeaturing)null).ComputeOwningFeatureOfType(), Throws.TypeOf<ArgumentNullException>());

var typeFeaturing = new TypeFeaturing();

Assert.That(typeFeaturing.ComputeOwningFeatureOfType(), Is.Null);

var feature = new Feature();

((IContainedRelationship)typeFeaturing).OwningRelatedElement = feature;

Assert.That(typeFeaturing.ComputeOwningFeatureOfType(), Is.SameAs(feature));

var nonFeatureTypeFeaturing = new TypeFeaturing();

((IContainedRelationship)nonFeatureTypeFeaturing).OwningRelatedElement = new Namespace();

Assert.That(nonFeatureTypeFeaturing.ComputeOwningFeatureOfType(), Is.Null);
}
}
}
37 changes: 32 additions & 5 deletions SysML2.NET.Tests/Extend/UnioningExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="UnioningExtensionsTestFixture.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,45 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Exceptions;

using SysMLType = SysML2.NET.Core.POCO.Core.Types.Type;

[TestFixture]
public class UnioningExtensionsTestFixture
{
[Test]
public void ComputeTypeUnioned_ThrowsNotSupportedException()
public void VerifyComputeTypeUnioned()
{
Assert.That(() => ((IUnioning)null).ComputeTypeUnioned(), Throws.TypeOf<NotSupportedException>());
// Null subject → ArgumentNullException.
Assert.That(() => ((IUnioning)null).ComputeTypeUnioned(), Throws.TypeOf<ArgumentNullException>());

// Empty Unioning (OwningRelatedElement is null) → [1..1] violation: IncompleteModelException.
var emptyUnioning = new Unioning();

Assert.That(() => emptyUnioning.ComputeTypeUnioned(), Throws.TypeOf<IncompleteModelException>());

// OwningRelatedElement is an IType → returns the same instance.
var type = new SysMLType();
var unioningWithType = new Unioning();

((IContainedRelationship)unioningWithType).OwningRelatedElement = type;

Assert.That(unioningWithType.ComputeTypeUnioned(), Is.SameAs(type));

// OwningRelatedElement is a non-IType element (Annotation) → [1..1] type violation: IncompleteModelException.
var annotation = new Annotation();
var unioningWithAnnotation = new Unioning();

((IContainedRelationship)unioningWithAnnotation).OwningRelatedElement = annotation;

Assert.That(() => unioningWithAnnotation.ComputeTypeUnioned(), Throws.TypeOf<IncompleteModelException>());
}
}
}
40 changes: 21 additions & 19 deletions SysML2.NET/Extend/IntersectingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="IntersectingExtensions.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.Core.Types
{
using System;
using System.Collections.Generic;

using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Exceptions;

/// <summary>
/// The <see cref="IntersectingExtensions"/> class provides extensions methods for
/// the <see cref="IIntersecting"/> interface
/// The <see cref="IntersectingExtensions" /> class provides extensions methods for
/// the <see cref="IIntersecting" /> interface
/// </summary>
internal static class IntersectingExtensions
{
/// <summary>
/// Computes the derived property.
/// </summary>
/// <param name="intersectingSubject">
/// The subject <see cref="IIntersecting"/>
/// The subject <see cref="IIntersecting" />
/// </param>
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IType ComputeTypeIntersected(this IIntersecting intersectingSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
}
if (intersectingSubject == null)
{
throw new ArgumentNullException(nameof(intersectingSubject));
}

Check warning on line 47 in SysML2.NET/Extend/IntersectingExtensions.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=STARIONGROUP_SysML2.NET&issues=AZ5pckQWEOv_2b6FCKsP&open=AZ5pckQWEOv_2b6FCKsP&pullRequest=268

return intersectingSubject.OwningRelatedElement as IType
?? throw new IncompleteModelException(
$"{nameof(intersectingSubject)} must have an owning related element of type {nameof(IType)}");
}
}
}
2 changes: 1 addition & 1 deletion SysML2.NET/Extend/ObjectiveMembershipExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ObjectiveMembershipExtensions.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 Down
Loading
Loading