Skip to content
Open
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
262 changes: 238 additions & 24 deletions SysML2.NET.Tests/Extend/ElementExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,78 +21,292 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;


using SysML2.NET.Core.POCO.Kernel.Packages;
using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
using SysML2.NET.Extensions;

[TestFixture]
public class ElementExtensionsTestFixture
{
[Test]
public void ComputeDocumentation_ThrowsNotSupportedException()
public void VerifyComputeDocumentation()
{
Assert.That(() => ((IElement)null).ComputeDocumentation(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeDocumentation(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();

Assert.That(element.ComputeDocumentation, Has.Count.EqualTo(0));

element.AssignOwnership(annotation, documentation);

Assert.That(element.ComputeDocumentation(), Is.EquivalentTo([documentation]));
}

[Test]
public void ComputeIsLibraryElement_ThrowsNotSupportedException()
public void VerifyComputeIsLibraryElement()
{
Assert.That(() => ((IElement)null).ComputeIsLibraryElement(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeIsLibraryElement(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputeIsLibraryElement, Is.False);
Assert.That(documentation.ComputeIsLibraryElement, Is.False);
}

element.AssignOwnership(annotation, documentation);

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputeIsLibraryElement, Is.False);
Assert.That(documentation.ComputeIsLibraryElement, Throws.TypeOf<NotSupportedException>());
}
}

[Test]
public void ComputeName_ThrowsNotSupportedException()
public void VerifyComputeName()
{
Assert.That(() => ((IElement)null).ComputeName(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeName(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();

Assert.That(element.ComputeName, Is.Null);

element.DeclaredName = "definitionName";
Assert.That(element.ComputeName, Is.EqualTo("definitionName"));
}

[Test]
public void ComputeOwnedAnnotation_ThrowsNotSupportedException()
public void VerifyComputeOwnedAnnotation()
{
Assert.That(() => ((IElement)null).ComputeOwnedAnnotation(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeOwnedAnnotation(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();
element.AssignOwnership(annotation, documentation);
Assert.That(element.ComputeOwnedAnnotation, Has.Count.EqualTo(0));

annotation.AnnotatedElement = element;
Assert.That(element.ComputeOwnedAnnotation, Is.EquivalentTo([annotation]));
}

[Test]
public void ComputeOwnedElement_ThrowsNotSupportedException()
public void VerifyComputeOwnedElement()
{
Assert.That(() => ((IElement)null).ComputeOwnedElement(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeOwnedElement(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();
Assert.That(element.ComputeOwnedElement, Has.Count.EqualTo(0));

element.AssignOwnership(annotation, documentation);
Assert.That(element.ComputeDocumentation, Is.EquivalentTo([documentation]));
}

[Test]
public void ComputeOwner_ThrowsNotSupportedException()
public void VerifyComputeOwner()
{
Assert.That(() => ((IElement)null).ComputeOwner(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeOwner(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputeOwner, Is.Null);
Assert.That(documentation.ComputeOwner, Is.Null);
}

element.AssignOwnership(annotation, documentation);

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputeOwner, Is.Null);
Assert.That(documentation.ComputeOwner, Is.EqualTo(element));
}
}

[Test]
public void ComputeOwningMembership_ThrowsNotSupportedException()
public void VerifyComputeOwningMembership()
{
Assert.That(() => ((IElement)null).ComputeOwningMembership(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeOwningMembership(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();

Assert.That(documentation.ComputeOwningMembership, Is.Null);

element.AssignOwnership(annotation, documentation);

using (Assert.EnterMultipleScope())
{
Assert.That(documentation.ComputeOwningMembership, Is.Null);
Assert.That(element.ComputeOwningMembership, Is.Null);
}

var membership = new OwningMembership();
var namespaceElement = new Namespace();

namespaceElement.AssignOwnership(membership, element);
Assert.That(element.ComputeOwningMembership, Is.EqualTo(membership));
}

[Test]
public void ComputeOwningNamespace_ThrowsNotSupportedException()
public void VerifyComputeOwningNamespace()
{
Assert.That(() => ((IElement)null).ComputeOwningNamespace(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeOwningNamespace(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var documentation = new Documentation();
var annotation = new Annotation();
element.AssignOwnership(annotation, documentation);

Assert.That(documentation.ComputeOwningNamespace, Is.Null);
var membership = new OwningMembership();
var namespaceElement = new Namespace();

namespaceElement.AssignOwnership(membership, element);
Assert.That(element.ComputeOwningNamespace, Is.EqualTo(namespaceElement));
}

[Test]
public void ComputeQualifiedName_ThrowsNotSupportedException()
public void VerifyComputeQualifiedName()
{
Assert.That(() => ((IElement)null).ComputeQualifiedName(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeQualifiedName(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();

Assert.That(element.ComputeQualifiedName, Is.Null);

var membership = new OwningMembership();
var secondMembership = new OwningMembership();

var namespaceElement = new Namespace();

namespaceElement.AssignOwnership(membership, element);
element.DeclaredName = "name";

Assert.That(element.ComputeQualifiedName, Is.EqualTo("name"));

var secondElement = new Definition()
{
DeclaredName = "name"
};

namespaceElement.AssignOwnership(secondMembership, secondElement);

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputeQualifiedName, Is.EqualTo("name"));
Assert.That(secondElement.ComputeQualifiedName, Is.Null);
}

var packageOwner = new Package()
{
DeclaredName = "owner"
};

var packageMembership = new OwningMembership();
packageOwner.AssignOwnership(packageMembership, namespaceElement);

Assert.That(element.ComputeQualifiedName, Is.Null);

namespaceElement.DeclaredName = "namespace";
Assert.That(element.ComputeQualifiedName, Is.EqualTo("namespace::name"));
}

[Test]
public void ComputeShortName_ThrowsNotSupportedException()
public void VerifyComputeShortName()
{
Assert.That(() => ((IElement)null).ComputeShortName(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeShortName(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();

Assert.That(element.ComputeShortName, Is.Null);

element.DeclaredShortName = "shortName";
Assert.That(element.ComputeShortName, Is.EqualTo("shortName"));
}

[Test]
public void ComputeTextualRepresentation_ThrowsNotSupportedException()
public void VerifyComputeTextualRepresentation()
{
Assert.That(() => ((IElement)null).ComputeTextualRepresentation(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();
var textualRepresentation = new TextualRepresentation();
var annotation = new Annotation();

Assert.That(element.ComputeTextualRepresentation, Has.Count.EqualTo(0));

element.AssignOwnership(annotation, textualRepresentation);

Assert.That(element.ComputeTextualRepresentation(), Is.EquivalentTo([textualRepresentation]));
}

[Test]
public void VerifyComputePathOperation()
{
Assert.That(() => ((IElement)null).ComputePathOperation(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition();

Assert.That(element.ComputePathOperation, Is.Empty);
element.DeclaredName = "name";

Assert.That(element.ComputePathOperation, Is.Empty);

var membership = new OwningMembership();
var secondMembership = new OwningMembership();
var namespaceElement = new Namespace();

namespaceElement.AssignOwnership(membership, element);

Assert.That(element.ComputePathOperation, Is.EqualTo("name"));

var secondElement = new Definition()
{
DeclaredName = "name"
};

namespaceElement.AssignOwnership(secondMembership, secondElement);

using (Assert.EnterMultipleScope())
{
Assert.That(element.ComputePathOperation, Is.EqualTo("name"));
Assert.That(secondElement.ComputePathOperation, Throws.TypeOf<NotSupportedException>());
}
}

[Test]
public void VerifyComputeEscapedNameOperation()
{
Assert.That(() => ((IElement)null).ComputeTextualRepresentation(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IElement)null).ComputeEscapedNameOperation(), Throws.TypeOf<ArgumentNullException>());

var element = new Definition()
{
DeclaredName = "basic"
};

Assert.That(element.ComputeEscapedNameOperation, Is.EqualTo("basic"));

element.DeclaredName = "non basic";
Assert.That(element.ComputeEscapedNameOperation, Is.EqualTo("\'non basic\'"));
}
}
}
2 changes: 1 addition & 1 deletion SysML2.NET.Tests/Extend/MembershipExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void ComputeMemberElementId_ThrowsNotSupportedException()
[Test]
public void ComputeMembershipOwningNamespace_ThrowsNotSupportedException()
{
Assert.That(() => ((IMembership)null).ComputeMembershipOwningNamespace(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IMembership)null).ComputeMembershipOwningNamespace(), Throws.TypeOf<ArgumentNullException>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class OwningMembershipExtensionsTestFixture
[Test]
public void ComputeOwnedMemberElement_ThrowsNotSupportedException()
{
Assert.That(() => ((IOwningMembership)null).ComputeOwnedMemberElement(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IOwningMembership)null).ComputeOwnedMemberElement(), Throws.TypeOf<ArgumentNullException>());
}

[Test]
Expand All @@ -44,7 +44,7 @@ public void ComputeOwnedMemberElementId_ThrowsNotSupportedException()
[Test]
public void ComputeOwnedMemberName_ThrowsNotSupportedException()
{
Assert.That(() => ((IOwningMembership)null).ComputeOwnedMemberName(), Throws.TypeOf<NotSupportedException>());
Assert.That(() => ((IOwningMembership)null).ComputeOwnedMemberName(), Throws.TypeOf<ArgumentNullException>());
}

[Test]
Expand Down
Loading
Loading