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
90 changes: 90 additions & 0 deletions SysML2.NET.Tests/Extensions/ElementExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ElementExtensionsTestFixture.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.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<ArgumentNullException>(() => ElementExtensions.AssignOwnership(null, bridgeRelationship, target));
}

[Test]
public void AssignOwnership_WithNullBridge_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() => ElementExtensions.AssignOwnership(source, null, target));
}

[Test]
public void AssignOwnership_WithNullTarget_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, null));
}

[Test]
public void AssignOwnership_WithSourceEqualsTarget_ThrowsInvalidOperationException()
{
Assert.Throws<InvalidOperationException>(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, source));
}

[Test]
public void AssignOwnership_WithBridgeEqualsTarget_ThrowsInvalidOperationException()
{
Assert.Throws<InvalidOperationException>(() => 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));
}
}
}
}
45 changes: 45 additions & 0 deletions SysML2.NET.Tests/SysML2.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<Company>Starion Group S.A.</Company>
<Authors>Sam Gerene</Authors>
<Description>Nunit test suite for the SysML2.NET.Extensions Library</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/STARIONGROUP/SysML2.NET.git</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<ImplicitUsings>false</ImplicitUsings>
<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
<PreserveCompilationContext>true</PreserveCompilationContext>
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit.Console" Version="3.22.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />

<PackageReference Include="coverlet.collector" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SysML2.NET\SysML2.NET.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Extend\" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions SysML2.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading