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="EnumerationDefinitionExtensionsTestFixture.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,41 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Systems.Attributes;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Core.POCO.Systems.Enumerations;
using SysML2.NET.Extensions;

[TestFixture]
public class EnumerationDefinitionExtensionsTestFixture
{
[Test]
public void ComputeEnumeratedValue_ThrowsNotSupportedException()
public void VerifyComputeEnumeratedValue()
{
Assert.That(() => ((IEnumerationDefinition)null).ComputeEnumeratedValue(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IEnumerationDefinition)null).ComputeEnumeratedValue(), Throws.TypeOf<ArgumentNullException>());

// Empty: no variant memberships → empty list.
var emptySubject = new EnumerationDefinition();

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

// Populated: two VariantMemberships, one owning an EnumerationUsage variant, the other owning a
// non-EnumerationUsage variant (AttributeUsage). Only the EnumerationUsage survives the kind filter,
// and the variantMembership order is preserved.
var subject = new EnumerationDefinition();
var enumeratedValue = new EnumerationUsage();
var nonEnumeratedVariant = new AttributeUsage();
subject.AssignOwnership(new VariantMembership(), enumeratedValue);
subject.AssignOwnership(new VariantMembership(), nonEnumeratedVariant);

using (Assert.EnterMultipleScope())
{
Assert.That(subject.ComputeEnumeratedValue(), Is.EqualTo([enumeratedValue]));
Assert.That(subject.ComputeEnumeratedValue(), Does.Not.Contain(nonEnumeratedVariant));
}
}
}
}
34 changes: 28 additions & 6 deletions SysML2.NET.Tests/Extend/EnumerationUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="EnumerationUsageExtensionsTestFixture.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.Features;
using SysML2.NET.Core.POCO.Systems.Enumerations;
using SysML2.NET.Exceptions;
using SysML2.NET.Extensions;

[TestFixture]
public class EnumerationUsageExtensionsTestFixture
{
[Test]
public void ComputeEnumerationDefinition_ThrowsNotSupportedException()
public void VerifyComputeEnumerationDefinition()
{
Assert.That(() => ((IEnumerationUsage)null).ComputeEnumerationDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IEnumerationUsage)null).ComputeEnumerationDefinition(), Throws.TypeOf<ArgumentNullException>());

// [1..1] lower-bound violation: no EnumerationDefinition typing → IncompleteModelException.
var subjectNoTyping = new EnumerationUsage();

Assert.That(subjectNoTyping.ComputeEnumerationDefinition, Throws.TypeOf<IncompleteModelException>());

// Populated: exactly one FeatureTyping whose Type is an EnumerationDefinition → returned.
var subjectOneTyping = new EnumerationUsage();
var enumerationDefinition = new EnumerationDefinition();
subjectOneTyping.AssignOwnership(new FeatureTyping { Type = enumerationDefinition });

Assert.That(subjectOneTyping.ComputeEnumerationDefinition(), Is.SameAs(enumerationDefinition));

// [1..1] upper-bound violation: two EnumerationDefinition typings → MultiplicityViolationException.
var subjectTwoTypings = new EnumerationUsage();
subjectTwoTypings.AssignOwnership(new FeatureTyping { Type = new EnumerationDefinition() });
subjectTwoTypings.AssignOwnership(new FeatureTyping { Type = new EnumerationDefinition() });

Assert.That(subjectTwoTypings.ComputeEnumerationDefinition, Throws.TypeOf<MultiplicityViolationException>());
}
}
}
40 changes: 34 additions & 6 deletions SysML2.NET.Tests/Extend/FlowDefinitionExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="FlowDefinitionExtensionsTestFixture.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,46 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Core.POCO.Systems.Flows;
using SysML2.NET.Extensions;

[TestFixture]
public class FlowDefinitionExtensionsTestFixture
{
[Test]
public void ComputeFlowEnd_ThrowsNotSupportedException()
public void VerifyComputeFlowEnd()
{
Assert.That(() => ((IFlowDefinition)null).ComputeFlowEnd(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IFlowDefinition)null).ComputeFlowEnd(), Throws.TypeOf<ArgumentNullException>());

// Empty: no end features → empty list.
var emptySubject = new FlowDefinition();

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

// Populated: an end feature that is a Usage (IsEnd = true), plus (a) a non-end Usage and
// (b) an end feature that is NOT a Usage. flowEnd = endFeature->selectByKind(Usage) keeps only
// the end Usage.
var subject = new FlowDefinition();
var endUsage = new ReferenceUsage { IsEnd = true };
var nonEndUsage = new ReferenceUsage { IsEnd = false };
var nonUsageEndFeature = new Feature { IsEnd = true };
subject.AssignOwnership(new FeatureMembership(), endUsage);
subject.AssignOwnership(new FeatureMembership(), nonEndUsage);
subject.AssignOwnership(new FeatureMembership(), nonUsageEndFeature);

using (Assert.EnterMultipleScope())
{
Assert.That(subject.ComputeFlowEnd(), Has.Count.EqualTo(1));
Assert.That(subject.ComputeFlowEnd(), Does.Contain(endUsage));
Assert.That(subject.ComputeFlowEnd(), Does.Not.Contain(nonEndUsage));
Assert.That(subject.ComputeFlowEnd(), Does.Not.Contain(nonUsageEndFeature));
}
}
}
}
37 changes: 31 additions & 6 deletions SysML2.NET.Tests/Extend/FlowUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="FlowUsageExtensionsTestFixture.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.Kernel.Interactions;
using SysML2.NET.Core.POCO.Systems.Flows;
using SysML2.NET.Extensions;

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

[TestFixture]
public class FlowUsageExtensionsTestFixture
{
[Test]
public void ComputeFlowDefinition_ThrowsNotSupportedException()
public void VerifyComputeFlowDefinition()
{
Assert.That(() => ((IFlowUsage)null).ComputeFlowDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IFlowUsage)null).ComputeFlowDefinition(), Throws.TypeOf<ArgumentNullException>());

// Empty: no typings → empty list.
var emptySubject = new FlowUsage();

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

// Populated: a type that is an Interaction plus a non-Interaction type. flowDefinition =
// type->selectByKind(Interaction) keeps only the Interaction.
var subject = new FlowUsage();
var interaction = new Interaction();
var plainType = new Type();
subject.AssignOwnership(new FeatureTyping { Type = interaction });
subject.AssignOwnership(new FeatureTyping { Type = plainType });

using (Assert.EnterMultipleScope())
{
Assert.That(subject.ComputeFlowDefinition(), Has.Count.EqualTo(1));
Assert.That(subject.ComputeFlowDefinition(), Does.Contain(interaction));
Assert.That(subject.ComputeFlowDefinition(), Does.Not.Contain(plainType));
}
}
}
}
27 changes: 21 additions & 6 deletions SysML2.NET.Tests/Extend/ItemUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="ItemUsageExtensionsTestFixture.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,33 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Kernel.Structures;
using SysML2.NET.Core.POCO.Systems.Items;
using SysML2.NET.Extensions;

[TestFixture]
public class ItemUsageExtensionsTestFixture
{
[Test]
public void ComputeItemDefinition_ThrowsNotSupportedException()
public void VerifyComputeItemDefinition()
{
Assert.That(() => ((IItemUsage)null).ComputeItemDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IItemUsage)null).ComputeItemDefinition(), Throws.TypeOf<ArgumentNullException>());

// ComputeItemDefinition faithfully implements the OCL itemDefinition = occurrenceDefinition->selectByKind(Structure),
// reading the subsetted occurrenceDefinition property directly. occurrenceDefinition resolves to
// OccurrenceUsageExtensions.ComputeOccurrenceDefinition, which is still a stub, so any non-null subject throws
// NotSupportedException (stub-blocker pattern).
// For later: once OccurrenceUsageExtensions.ComputeOccurrenceDefinition is implemented, replace the assertion below with a
// real one: a subject whose occurrenceDefinition includes a Structure plus a non-Structure Class → ComputeItemDefinition
// returns only the Structure(s).
var subject = new ItemUsage();
subject.AssignOwnership(new FeatureTyping { Type = new Structure() });

Assert.That(subject.ComputeItemDefinition, Throws.TypeOf<NotSupportedException>());
}
}
}
38 changes: 32 additions & 6 deletions SysML2.NET.Tests/Extend/MetadataUsageExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="MetadataUsageExtensionsTestFixture.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,44 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Kernel.Metadata;
using SysML2.NET.Core.POCO.Systems.Metadata;
using SysML2.NET.Exceptions;
using SysML2.NET.Extensions;

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

[TestFixture]
public class MetadataUsageExtensionsTestFixture
{
[Test]
public void ComputeMetadataDefinition_ThrowsNotSupportedException()
public void VerifyComputeMetadataDefinition()
{
Assert.That(() => ((IMetadataUsage)null).ComputeMetadataDefinition(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IMetadataUsage)null).ComputeMetadataDefinition(), Throws.TypeOf<ArgumentNullException>());

// [0..1] lower bound: no Metaclass typing → null.
var subjectNoTyping = new MetadataUsage();

Assert.That(subjectNoTyping.ComputeMetadataDefinition(), Is.Null);

// Populated: one FeatureTyping whose Type is a Metaclass (a non-Metaclass typing is filtered out) → returned.
var subjectOneTyping = new MetadataUsage();
var metaclass = new Metaclass();
subjectOneTyping.AssignOwnership(new FeatureTyping { Type = metaclass });
subjectOneTyping.AssignOwnership(new FeatureTyping { Type = new Type() });

Assert.That(subjectOneTyping.ComputeMetadataDefinition(), Is.SameAs(metaclass));

// [0..1] upper-bound violation (STRICT contract): two Metaclass typings → MultiplicityViolationException.
var subjectTwoTypings = new MetadataUsage();
subjectTwoTypings.AssignOwnership(new FeatureTyping { Type = new Metaclass() });
subjectTwoTypings.AssignOwnership(new FeatureTyping { Type = new Metaclass() });

Assert.That(subjectTwoTypings.ComputeMetadataDefinition, Throws.TypeOf<MultiplicityViolationException>());
}
}
}
Loading
Loading