Skip to content

Commit 41aa4ca

Browse files
[Add] test project for SysML2.NET (#84)
* [Add] test project for SysML2.NET * [Add] testfixture for ElementExtensions
1 parent 9627845 commit 41aa4ca

3 files changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="ElementExtensionsTestFixture.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SysML2.NET.Tests.Extensions
22+
{
23+
using System;
24+
25+
using SysML2.NET.Core.POCO.Core.Features;
26+
using SysML2.NET.Core.POCO.Core.Types;
27+
using SysML2.NET.Core.POCO.Systems.Parts;
28+
using SysML2.NET.Extensions;
29+
30+
using NUnit.Framework;
31+
32+
[TestFixture]
33+
public class ElementExtensionsTestFixture
34+
{
35+
private PartDefinition source;
36+
private FeatureMembership bridgeRelationship;
37+
private Feature target;
38+
39+
[SetUp]
40+
public void SetUp()
41+
{
42+
source = new PartDefinition();
43+
bridgeRelationship = new FeatureMembership();
44+
target = new Feature();
45+
}
46+
47+
[Test]
48+
public void AssignOwnership_WithNullSource_ThrowsArgumentNullException()
49+
{
50+
Assert.Throws<ArgumentNullException>(() => ElementExtensions.AssignOwnership(null, bridgeRelationship, target));
51+
}
52+
53+
[Test]
54+
public void AssignOwnership_WithNullBridge_ThrowsArgumentNullException()
55+
{
56+
Assert.Throws<ArgumentNullException>(() => ElementExtensions.AssignOwnership(source, null, target));
57+
}
58+
59+
[Test]
60+
public void AssignOwnership_WithNullTarget_ThrowsArgumentNullException()
61+
{
62+
Assert.Throws<ArgumentNullException>(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, null));
63+
}
64+
65+
[Test]
66+
public void AssignOwnership_WithSourceEqualsTarget_ThrowsInvalidOperationException()
67+
{
68+
Assert.Throws<InvalidOperationException>(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, source));
69+
}
70+
71+
[Test]
72+
public void AssignOwnership_WithBridgeEqualsTarget_ThrowsInvalidOperationException()
73+
{
74+
Assert.Throws<InvalidOperationException>(() => ElementExtensions.AssignOwnership(source, bridgeRelationship, bridgeRelationship));
75+
}
76+
77+
[Test]
78+
public void AssignOwnership_WithValidParameters_AssignsOwnershipCorrectly()
79+
{
80+
ElementExtensions.AssignOwnership(source, bridgeRelationship, target);
81+
82+
using (Assert.EnterMultipleScope())
83+
{
84+
Assert.That(bridgeRelationship.OwningRelatedElement, Is.EqualTo(source));
85+
Assert.That(source.OwnedRelationship, Does.Contain(bridgeRelationship));
86+
Assert.That(bridgeRelationship.OwnedRelatedElement, Does.Contain(target));
87+
}
88+
}
89+
}
90+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<LangVersion>12.0</LangVersion>
6+
<Company>Starion Group S.A.</Company>
7+
<Authors>Sam Gerene</Authors>
8+
<Description>Nunit test suite for the SysML2.NET.Extensions Library</Description>
9+
<Copyright>Copyright © Starion Group S.A.</Copyright>
10+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
11+
<RepositoryUrl>https://github.com/STARIONGROUP/SysML2.NET.git</RepositoryUrl>
12+
<RepositoryType>Git</RepositoryType>
13+
<ImplicitUsings>false</ImplicitUsings>
14+
<Nullable>disable</Nullable>
15+
<IsPackable>false</IsPackable>
16+
<PreserveCompilationContext>true</PreserveCompilationContext>
17+
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.3" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
23+
<PackageReference Include="NUnit" Version="4.4.0" />
24+
<PackageReference Include="NUnit.Console" Version="3.22.0" />
25+
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
26+
27+
<PackageReference Include="coverlet.collector" Version="8.0.0">
28+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
29+
<PrivateAssets>all</PrivateAssets>
30+
</PackageReference>
31+
<PackageReference Include="coverlet.msbuild" Version="8.0.0">
32+
<PrivateAssets>all</PrivateAssets>
33+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
34+
</PackageReference>
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<ProjectReference Include="..\SysML2.NET\SysML2.NET.csproj" />
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<Folder Include="Extend\" />
43+
</ItemGroup>
44+
45+
</Project>

SysML2.NET.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysML2.NET.Kpar", "SysML2.N
6767
EndProject
6868
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysML2.NET.Kpar.Tests", "SysML2.NET.Kpar.Tests\SysML2.NET.Kpar.Tests.csproj", "{ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}"
6969
EndProject
70+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysML2.NET.Tests", "SysML2.NET.Tests\SysML2.NET.Tests.csproj", "{C3953262-2718-4EC6-B7EB-BB94402D335A}"
71+
EndProject
7072
Global
7173
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7274
Debug|Any CPU = Debug|Any CPU
@@ -149,6 +151,10 @@ Global
149151
{ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
150152
{ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
151153
{ACA8A0A2-EF4E-4F22-9164-07F6550F81F0}.Release|Any CPU.Build.0 = Release|Any CPU
154+
{C3953262-2718-4EC6-B7EB-BB94402D335A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155+
{C3953262-2718-4EC6-B7EB-BB94402D335A}.Debug|Any CPU.Build.0 = Debug|Any CPU
156+
{C3953262-2718-4EC6-B7EB-BB94402D335A}.Release|Any CPU.ActiveCfg = Release|Any CPU
157+
{C3953262-2718-4EC6-B7EB-BB94402D335A}.Release|Any CPU.Build.0 = Release|Any CPU
152158
EndGlobalSection
153159
GlobalSection(SolutionProperties) = preSolution
154160
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)