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="ReferenceSubsettingExtensionsTestFixture.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,43 @@
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;
using SysML2.NET.Exceptions;

[TestFixture]
public class ReferenceSubsettingExtensionsTestFixture
{
[Test]
public void ComputeReferencingFeature_ThrowsNotSupportedException()
public void VerifyComputeReferencingFeature()
{
Assert.That(() => ((IReferenceSubsetting)null).ComputeReferencingFeature(), Throws.TypeOf<NotSupportedException>());
// Null subject → ArgumentNullException.
Assert.That(() => ((IReferenceSubsetting)null).ComputeReferencingFeature(), Throws.TypeOf<ArgumentNullException>());

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

Assert.That(() => emptySubsetting.ComputeReferencingFeature(), Throws.TypeOf<IncompleteModelException>());

// OwningRelatedElement is an IFeature → returns the same instance.
var feature = new Feature();
var refSubsettingWithFeature = new ReferenceSubsetting();

((IContainedRelationship)refSubsettingWithFeature).OwningRelatedElement = feature;

Assert.That(refSubsettingWithFeature.ComputeReferencingFeature(), Is.SameAs(feature));

// OwningRelatedElement is a non-IFeature (Namespace) → [1..1] type violation: IncompleteModelException.
var namespaceObj = new Namespace();
var refSubsettingWithNamespace = new ReferenceSubsetting();

((IContainedRelationship)refSubsettingWithNamespace).OwningRelatedElement = namespaceObj;

Assert.That(() => refSubsettingWithNamespace.ComputeReferencingFeature(), Throws.TypeOf<IncompleteModelException>());
}
}
}
39 changes: 33 additions & 6 deletions SysML2.NET.Tests/Extend/SpecializationExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecializationExtensionsTestFixture.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.Extensions;

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

[TestFixture]
public class SpecializationExtensionsTestFixture
{
[Test]
public void ComputeOwningType_ThrowsNotSupportedException()
public void VerifyComputeOwningType()
{
Assert.That(() => ((ISpecialization)null).ComputeOwningType(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((ISpecialization)null).ComputeOwningType(), Throws.TypeOf<ArgumentNullException>());

var emptySpecialization = new Specialization();

Assert.That(emptySpecialization.ComputeOwningType(), Is.Null);

var owningType = new Type();
var specialization = new Specialization();

owningType.AssignOwnership(specialization);

Assert.That(specialization.ComputeOwningType(), Is.SameAs(owningType));

// NOTE: assigning a non-IType as OwningRelatedElement is not guarded by the public
// AssignOwnership API for Specialization, so we directly set the backing field via
// the IContainedRelationship explicit interface to exercise the as-cast-returns-null
// path, which proves ComputeOwningType returns null when the owner is not an IType.
var nonTypeSpecialization = new Specialization();
var nonTypeOwner = new Namespace();

((IContainedRelationship)nonTypeSpecialization).OwningRelatedElement = nonTypeOwner;

Assert.That(nonTypeSpecialization.ComputeOwningType(), Is.Null);
}
}
}
34 changes: 28 additions & 6 deletions SysML2.NET.Tests/Extend/SubclassificationExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="SubclassificationExtensionsTestFixture.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,40 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Core.Classifiers;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;

[TestFixture]
public class SubclassificationExtensionsTestFixture
{
[Test]
public void ComputeOwningClassifier_ThrowsNotSupportedException()
public void VerifyComputeOwningClassifier()
{
Assert.That(() => ((ISubclassification)null).ComputeOwningClassifier(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((ISubclassification)null).ComputeOwningClassifier(), Throws.TypeOf<ArgumentNullException>());

// Empty Subclassification (OwningRelatedElement is null) → returns null.
var subclassification = new Subclassification();

Assert.That(subclassification.ComputeOwningClassifier(), Is.Null);

// OwningRelatedElement is an IClassifier → returns the classifier.
var classifier = new Classifier();

((IContainedRelationship)subclassification).OwningRelatedElement = classifier;

Assert.That(subclassification.ComputeOwningClassifier(), Is.SameAs(classifier));

// OwningRelatedElement is NOT an IClassifier (e.g. Namespace) → returns null.
var nonClassifierSubclassification = new Subclassification();
var namespaceObj = new Namespace();

((IContainedRelationship)nonClassifierSubclassification).OwningRelatedElement = namespaceObj;

Assert.That(nonClassifierSubclassification.ComputeOwningClassifier(), Is.Null);
}
}
}
31 changes: 25 additions & 6 deletions SysML2.NET.Tests/Extend/SubsettingExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="SubsettingExtensionsTestFixture.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,37 @@
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 SubsettingExtensionsTestFixture
{
[Test]
public void ComputeOwningFeature_ThrowsNotSupportedException()
public void VerifyComputeOwningFeature()
{
Assert.That(() => ((ISubsetting)null).ComputeOwningFeature(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((ISubsetting)null).ComputeOwningFeature(), Throws.TypeOf<ArgumentNullException>());

var subsetting = new Subsetting();

Assert.That(subsetting.ComputeOwningFeature(), Is.Null);

var feature = new Feature();

((IContainedRelationship)subsetting).OwningRelatedElement = feature;

Assert.That(subsetting.ComputeOwningFeature(), Is.SameAs(feature));

var namespaceOwner = new Namespace();
var nonFeatureSubsetting = new Subsetting();

((IContainedRelationship)nonFeatureSubsetting).OwningRelatedElement = namespaceOwner;

Assert.That(nonFeatureSubsetting.ComputeOwningFeature(), Is.Null);
}
}
}
2 changes: 1 addition & 1 deletion SysML2.NET.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">-------------------------------------------------------------------------------------------------&#xD;
&lt;copyright file="${File.FileName}" company="Starion Group S.A."&gt;&#xD;
&#xD;
Copyright 2022-2026 Starion Group S.A.&#xD;
Copyright (C) 2022-2026 Starion Group S.A.&#xD;
&#xD;
Licensed under the Apache License, Version 2.0 (the "License");&#xD;
you may not use this file except in compliance with the License.&#xD;
Expand Down
52 changes: 30 additions & 22 deletions SysML2.NET/Extend/ReferenceSubsettingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ReferenceSubsettingExtensions.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.Features
{
using System;
using System.Collections.Generic;

using SysML2.NET.Core.POCO.Core.Types;
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="ReferenceSubsettingExtensions"/> class provides extensions methods for
/// the <see cref="IReferenceSubsetting"/> interface
/// The <see cref="ReferenceSubsettingExtensions" /> class provides extensions methods for
/// the <see cref="IReferenceSubsetting" /> interface
/// </summary>
internal static class ReferenceSubsettingExtensions
{
/// <summary>
/// Computes the derived property.
/// Computes the derived property <c>referencingFeature</c> — the <see cref="IFeature" /> that owns
/// this <see cref="IReferenceSubsetting" /> relationship, which is also its subsettingFeature.
/// </summary>
/// <param name="referenceSubsettingSubject">
/// The subject <see cref="IReferenceSubsetting"/>
/// The subject <see cref="IReferenceSubsetting" />
/// </param>
/// <returns>
/// the computed result
/// The <see cref="IFeature" /> that is the owning related element of this relationship.
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="referenceSubsettingSubject" /> is null.
/// </exception>
/// <exception cref="IncompleteModelException">
/// Thrown when the owning related element is null or is not an <see cref="IFeature" />.
/// </exception>
internal static IFeature ComputeReferencingFeature(this IReferenceSubsetting referenceSubsettingSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
}
if (referenceSubsettingSubject == null)
{
throw new ArgumentNullException(nameof(referenceSubsettingSubject));
}

Check warning on line 54 in SysML2.NET/Extend/ReferenceSubsettingExtensions.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=AZ5ow3i7jH9ez_061Wm2&open=AZ5ow3i7jH9ez_061Wm2&pullRequest=267

return referenceSubsettingSubject.OwningRelatedElement as IFeature
?? throw new IncompleteModelException(
$"{nameof(referenceSubsettingSubject)} must have an owning related element of type {nameof(IFeature)}");
}
}
}
35 changes: 15 additions & 20 deletions SysML2.NET/Extend/SpecializationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="SpecializationExtensions.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;

/// <summary>
/// The <see cref="SpecializationExtensions"/> class provides extensions methods for
/// the <see cref="ISpecialization"/> interface
/// The <see cref="SpecializationExtensions" /> class provides extensions methods for
/// the <see cref="ISpecialization" /> interface
/// </summary>
internal static class SpecializationExtensions
{
/// <summary>
/// Computes the derived property.
/// </summary>
/// <param name="specializationSubject">
/// The subject <see cref="ISpecialization"/>
/// The subject <see cref="ISpecialization" />
/// </param>
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static IType ComputeOwningType(this ISpecialization specializationSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return specializationSubject == null
? throw new ArgumentNullException(nameof(specializationSubject))
: specializationSubject.OwningRelatedElement as IType;
}

}
}
Loading
Loading