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
52 changes: 40 additions & 12 deletions SysML2.NET.Tests/Extend/AttributeUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,72 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="AttributeUsageExtensionsTestFixture.cs" company="Starion Group S.A.">
//
//
// Copyright 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.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Systems.Attributes ;
using SysML2.NET.Core.POCO.Core.Classifiers;
using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Systems.Attributes;
using SysML2.NET.Extensions;

[TestFixture]
public class AttributeUsageExtensionsTestFixture
{
[Test]
public void ComputeAttributeDefinition_ThrowsNotSupportedException()
public void VerifyComputeAttributeDefinition()
{
Assert.That(() => ((IAttributeUsage)null).ComputeAttributeDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAttributeUsage)null).ComputeAttributeDefinition(), Throws.TypeOf<ArgumentNullException>());

var emptySubject = new AttributeUsage();

Assert.That(emptySubject.ComputeAttributeDefinition(), Has.Count.EqualTo(0));

var subject = new AttributeUsage();
var attributeDefinition = new AttributeDefinition();
var bareClassifier = new Classifier();

subject.AssignOwnership(new FeatureTyping { Type = attributeDefinition });
subject.AssignOwnership(new FeatureTyping { Type = bareClassifier });

// Only the IDataType (AttributeDefinition) is returned; bare Classifier is excluded.
Assert.That(subject.ComputeAttributeDefinition(), Is.EquivalentTo(new[] { attributeDefinition }));
}

[Test]
public void ComputeIsReference_ThrowsNotSupportedException()
public void VerifyComputeIsReference()
{
Assert.That(() => ((IAttributeUsage)null).ComputeIsReference(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IAttributeUsage)null).ComputeIsReference(), Throws.TypeOf<ArgumentNullException>());

var emptySubject = new AttributeUsage();

Assert.That(emptySubject.ComputeIsReference(), Is.True);

var populatedSubject = new AttributeUsage();
var attributeDefinition = new AttributeDefinition();
populatedSubject.AssignOwnership(new FeatureTyping { Type = attributeDefinition });

// Always true regardless of subject state — AttributeUsages are always referential.
Assert.That(populatedSubject.ComputeIsReference(), Is.True);
}
}
}
19 changes: 15 additions & 4 deletions SysML2.NET/Extend/AttributeUsageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Systems.Attributes
{
using System;
using System.Collections.Generic;
using System.Linq;

using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
Expand Down Expand Up @@ -63,16 +64,25 @@ internal static class AttributeUsageExtensions
/// <summary>
/// Computes the derived property.
/// </summary>
/// <remarks>
/// Walks <c>OwnedRelationship</c> → <c>IFeatureTyping</c> → <c>Type</c> directly,
/// filtering to <c>IDataType</c>. The AttributeUsage POCO's explicit-interface
/// <c>IUsage.definition</c> impl delegates to <c>this.attributeDefinition</c>,
/// which would route back into this method → stack overflow. Bypassing the
/// instance property mirrors the technique in
/// <see cref="UsageExtensions.ComputeDefinition" />.
/// </remarks>
/// <param name="attributeUsageSubject">
/// The subject <see cref="IAttributeUsage"/>
/// </param>
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List<IDataType> ComputeAttributeDefinition(this IAttributeUsage attributeUsageSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return attributeUsageSubject == null
? throw new ArgumentNullException(nameof(attributeUsageSubject))
: [..attributeUsageSubject.OwnedRelationship.OfType<IFeatureTyping>().Select(featureTyping => featureTyping.Type).OfType<IDataType>()];
}

/// <summary>
Expand All @@ -84,10 +94,11 @@ internal static List<IDataType> ComputeAttributeDefinition(this IAttributeUsage
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static bool ComputeIsReference(this IAttributeUsage attributeUsageSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return attributeUsageSubject == null
? throw new ArgumentNullException(nameof(attributeUsageSubject))
: true;
}

}
Expand Down
Loading