diff --git a/SysML2.NET.Tests/Extensions/ElementExtensionsTestFixture.cs b/SysML2.NET.Tests/Extensions/ElementExtensionsTestFixture.cs new file mode 100644 index 00000000..ee3940e1 --- /dev/null +++ b/SysML2.NET.Tests/Extensions/ElementExtensionsTestFixture.cs @@ -0,0 +1,90 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// 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. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace SysML2.NET.Tests.Extensions +{ + using System; + + using SysML2.NET.Core.POCO.Core.Features; + using SysML2.NET.Core.POCO.Core.Types; + using SysML2.NET.Core.POCO.Systems.Parts; + using SysML2.NET.Extensions; + + using NUnit.Framework; + + [TestFixture] + public class ElementExtensionsTestFixture + { + private PartDefinition source; + private FeatureMembership bridgeRelationship; + private Feature target; + + [SetUp] + public void SetUp() + { + source = new PartDefinition(); + bridgeRelationship = new FeatureMembership(); + target = new Feature(); + } + + [Test] + public void AssignOwnership_WithNullSource_ThrowsArgumentNullException() + { + Assert.Throws(() => ElementExtensions.AssignOwnership(null, bridgeRelationship, target)); + } + + [Test] + public void AssignOwnership_WithNullBridge_ThrowsArgumentNullException() + { + Assert.Throws(() => ElementExtensions.AssignOwnership(source, null, target)); + } + + [Test] + public void AssignOwnership_WithNullTarget_ThrowsArgumentNullException() + { + Assert.Throws(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, null)); + } + + [Test] + public void AssignOwnership_WithSourceEqualsTarget_ThrowsInvalidOperationException() + { + Assert.Throws(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, source)); + } + + [Test] + public void AssignOwnership_WithBridgeEqualsTarget_ThrowsInvalidOperationException() + { + Assert.Throws(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, bridgeRelationship)); + } + + [Test] + public void AssignOwnership_WithValidParameters_AssignsOwnershipCorrectly() + { + ElementExtensions.AssignOwnership(source, bridgeRelationship, target); + + using (Assert.EnterMultipleScope()) + { + Assert.That(bridgeRelationship.OwningRelatedElement, Is.EqualTo(source)); + Assert.That(source.OwnedRelationship, Does.Contain(bridgeRelationship)); + Assert.That(bridgeRelationship.OwnedRelatedElement, Does.Contain(target)); + } + } + } +} diff --git a/SysML2.NET.Tests/SysML2.NET.Tests.csproj b/SysML2.NET.Tests/SysML2.NET.Tests.csproj new file mode 100644 index 00000000..054da954 --- /dev/null +++ b/SysML2.NET.Tests/SysML2.NET.Tests.csproj @@ -0,0 +1,45 @@ + + + + net10.0 + 12.0 + Starion Group S.A. + Sam Gerene + Nunit test suite for the SysML2.NET.Extensions Library + Copyright © Starion Group S.A. + Apache-2.0 + https://github.com/STARIONGROUP/SysML2.NET.git + Git + false + disable + false + true + en-US + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/SysML2.NET.sln b/SysML2.NET.sln index f97d22fe..e8c69e28 100644 --- a/SysML2.NET.sln +++ b/SysML2.NET.sln @@ -67,6 +67,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysML2.NET.Kpar", "SysML2.N EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysML2.NET.Kpar.Tests", "SysML2.NET.Kpar.Tests\SysML2.NET.Kpar.Tests.csproj", "{ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysML2.NET.Tests", "SysML2.NET.Tests\SysML2.NET.Tests.csproj", "{C3953262-2718-4EC6-B7EB-BB94402D335A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -149,6 +151,10 @@ Global {ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}.Release|Any CPU.ActiveCfg = Release|Any CPU {ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}.Release|Any CPU.Build.0 = Release|Any CPU + {C3953262-2718-4EC6-B7EB-BB94402D335A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3953262-2718-4EC6-B7EB-BB94402D335A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3953262-2718-4EC6-B7EB-BB94402D335A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3953262-2718-4EC6-B7EB-BB94402D335A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE