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
14 changes: 12 additions & 2 deletions SysML2.NET.Tests/Extend/ElementExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void VerifyComputeIsLibraryElement()
using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputeIsLibraryElement, Is.False);
Assert.That(documentation.ComputeIsLibraryElement, Throws.TypeOf<NotSupportedException>());
Assert.That(documentation.ComputeIsLibraryElement, Is.False);
}
}

Expand Down Expand Up @@ -289,7 +289,17 @@ public void VerifyComputePathOperation()
using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputePathOperation, Is.EqualTo("name"));
Assert.That(secondElement.ComputePathOperation, Throws.TypeOf<NotSupportedException>());
Assert.That(secondElement.ComputePathOperation, Is.EqualTo("/2/1"));
}

namespaceElement.DeclaredName = "namespace";
membership.DeclaredName = "firstMember";
secondMembership.DeclaredName = "secondMember";

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputePathOperation, Is.EqualTo("name"));
Assert.That(secondElement.ComputePathOperation, Is.EqualTo("/2/1"));
}
}

Expand Down
49 changes: 46 additions & 3 deletions SysML2.NET.Tests/Extend/RelationshipExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,61 @@
namespace SysML2.NET.Tests.Extend
{
using System;


using Moq;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;

[TestFixture]
public class RelationshipExtensionsTestFixture
{
[Test]
public void ComputeRelatedElement_ThrowsNotSupportedException()
public void VerfiyComputeRelatedElement()
{
Assert.That(() => ((IRelationship)null).ComputeRelatedElement(), Throws.TypeOf<ArgumentNullException>());

var relationship = new Mock<IRelationship>();
relationship.Setup(x => x.Source).Returns([]);
relationship.Setup(x => x.Target).Returns([]);

Assert.That(relationship.Object.ComputeRelatedElement(), Is.Empty);

var sourceDefinition = new Definition();
relationship.Setup(x => x.Source).Returns([sourceDefinition]);

Assert.That(relationship.Object.ComputeRelatedElement(), Is.EquivalentTo([sourceDefinition]));

var targetDefinition = new Definition();
relationship.Setup(x => x.Target).Returns([targetDefinition]);

Assert.That(relationship.Object.ComputeRelatedElement(), Is.EquivalentTo([sourceDefinition, targetDefinition]));
var secondSource = new Definition();

relationship.Setup(x => x.Source).Returns([sourceDefinition, secondSource]);
Assert.That(relationship.Object.ComputeRelatedElement(), Is.EquivalentTo([sourceDefinition, secondSource, targetDefinition]));
}

[Test]
public void VerifyComputeRedefinedLibraryNamespaceOperation()
{
Assert.That(() => ((IRelationship)null).ComputeRedefinedLibraryNamespaceOperation(), Throws.TypeOf<ArgumentNullException>());
}

[Test]
public void VerifyComputeRedefinedPathOperation()
{
Assert.That(() => ((IRelationship)null).ComputeRelatedElement(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IRelationship)null).ComputeRedefinedPathOperation(), Throws.TypeOf<ArgumentNullException>());

var membership = new OwningMembership()
{
DeclaredName = "name"
};

Assert.That(((IRelationship)membership).ComputeRedefinedPathOperation(), Is.Empty);
}
}
}
1 change: 1 addition & 0 deletions SysML2.NET.Tests/SysML2.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.5.1" />
<PackageReference Include="NUnit.Console" Version="3.22.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.2.0" />
Expand Down
26 changes: 20 additions & 6 deletions SysML2.NET/Extend/RelationshipExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Root.Elements
{
using System;
using System.Collections.Generic;
using System.Linq;

using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Namespaces;
Expand All @@ -41,10 +42,9 @@ internal static class RelationshipExtensions
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static List<IElement> ComputeRelatedElement(this IRelationship relationshipSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return relationshipSubject == null ? throw new ArgumentNullException(nameof(relationshipSubject)) : [..relationshipSubject.Source, ..relationshipSubject.Target];
}

/// <summary>
Expand All @@ -57,10 +57,14 @@ internal static List<IElement> ComputeRelatedElement(this IRelationship relation
/// <returns>
/// The expected <see cref="INamespace" />
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static INamespace ComputeRedefinedLibraryNamespaceOperation(this IRelationship relationshipSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
if (relationshipSubject == null)
{
throw new ArgumentNullException(nameof(relationshipSubject));
}

return relationshipSubject.OwningRelatedElement?.LibraryNamespace() ?? relationshipSubject.OwningRelationship?.LibraryNamespace();
}

/// <summary>
Expand All @@ -75,10 +79,20 @@ internal static INamespace ComputeRedefinedLibraryNamespaceOperation(this IRelat
/// <returns>
/// The expected <see cref="string" />
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static string ComputeRedefinedPathOperation(this IRelationship relationshipSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
if (relationshipSubject == null)
{
throw new ArgumentNullException(nameof(relationshipSubject));
}

if (relationshipSubject.OwningRelationship == null && relationshipSubject.OwningRelatedElement != null)
{
var index = ((IContainedElement)relationshipSubject.OwningRelatedElement).OwnedRelationship.IndexOf(relationshipSubject) + 1;
return $"{relationshipSubject.OwningRelatedElement.Path()}/{index}";
}

return relationshipSubject.ComputePathOperation();
}
}
}
Loading