Skip to content

Commit 46e29a9

Browse files
[WIP] missing correct multiplicity on operation
1 parent 8f13ca0 commit 46e29a9

10 files changed

Lines changed: 513 additions & 73 deletions

SysML2.NET.Tests/Extend/ElementExtensionsTestFixture.cs

Lines changed: 160 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,78 +21,214 @@
2121
namespace SysML2.NET.Tests.Extend
2222
{
2323
using System;
24-
24+
using System.Linq;
25+
2526
using NUnit.Framework;
26-
27+
28+
using SysML2.NET.Core.POCO.Root.Annotations;
2729
using SysML2.NET.Core.POCO.Root.Elements;
30+
using SysML2.NET.Core.POCO.Root.Namespaces;
31+
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
32+
using SysML2.NET.Extensions;
2833

2934
[TestFixture]
3035
public class ElementExtensionsTestFixture
3136
{
3237
[Test]
33-
public void ComputeDocumentation_ThrowsNotSupportedException()
38+
public void VerifyComputeDocumentation()
3439
{
35-
Assert.That(() => ((IElement)null).ComputeDocumentation(), Throws.TypeOf<NotSupportedException>());
40+
Assert.That(() => ((IElement)null).ComputeDocumentation(), Throws.TypeOf<ArgumentNullException>());
41+
42+
var element = new Definition();
43+
var documentation = new Documentation();
44+
var annotation = new Annotation();
45+
46+
Assert.That(() => element.ComputeDocumentation(), Has.Count.EqualTo(0));
47+
48+
element.AssignOwnership(annotation, documentation);
49+
50+
Assert.That(element.ComputeDocumentation(), Is.EquivalentTo([documentation]));
3651
}
3752

3853
[Test]
39-
public void ComputeIsLibraryElement_ThrowsNotSupportedException()
54+
public void VerifyComputeIsLibraryElement()
4055
{
41-
Assert.That(() => ((IElement)null).ComputeIsLibraryElement(), Throws.TypeOf<NotSupportedException>());
56+
Assert.That(() => ((IElement)null).ComputeIsLibraryElement(), Throws.TypeOf<ArgumentNullException>());
57+
58+
var element = new Definition();
59+
var documentation = new Documentation();
60+
var annotation = new Annotation();
61+
62+
using (Assert.EnterMultipleScope())
63+
{
64+
Assert.That(() => element.ComputeIsLibraryElement(), Is.False);
65+
Assert.That(() => documentation.ComputeIsLibraryElement(), Is.False);
66+
}
67+
68+
element.AssignOwnership(annotation, documentation);
69+
70+
using (Assert.EnterMultipleScope())
71+
{
72+
Assert.That(() =>element.ComputeIsLibraryElement(), Is.False);
73+
Assert.That(() => documentation.ComputeIsLibraryElement(), Throws.TypeOf<NotSupportedException>());
74+
}
4275
}
4376

4477
[Test]
45-
public void ComputeName_ThrowsNotSupportedException()
78+
public void VerifyComputeName()
4679
{
47-
Assert.That(() => ((IElement)null).ComputeName(), Throws.TypeOf<NotSupportedException>());
80+
Assert.That(() => ((IElement)null).ComputeName(), Throws.TypeOf<ArgumentNullException>());
81+
82+
var element = new Definition();
83+
84+
Assert.That(() => element.ComputeName(), Is.Null);
85+
86+
element.DeclaredName = "definitionName";
87+
Assert.That(() => element.ComputeName(), Is.EqualTo("definitionName"));
4888
}
4989

5090
[Test]
51-
public void ComputeOwnedAnnotation_ThrowsNotSupportedException()
91+
public void VerifyComputeOwnedAnnotation()
5292
{
53-
Assert.That(() => ((IElement)null).ComputeOwnedAnnotation(), Throws.TypeOf<NotSupportedException>());
93+
Assert.That(() => ((IElement)null).ComputeOwnedAnnotation(), Throws.TypeOf<ArgumentNullException>());
94+
95+
var element = new Definition();
96+
var documentation = new Documentation();
97+
var annotation = new Annotation();
98+
element.AssignOwnership(annotation, documentation);
99+
Assert.That(() => element.ComputeOwnedAnnotation(), Has.Count.EqualTo(0));
100+
101+
annotation.AnnotatedElement = element;
102+
Assert.That(() => element.ComputeOwnedAnnotation(), Is.EquivalentTo([annotation]));
54103
}
55104

56105
[Test]
57-
public void ComputeOwnedElement_ThrowsNotSupportedException()
106+
public void VerifyComputeOwnedElement()
58107
{
59-
Assert.That(() => ((IElement)null).ComputeOwnedElement(), Throws.TypeOf<NotSupportedException>());
108+
Assert.That(() => ((IElement)null).ComputeOwnedElement(), Throws.TypeOf<ArgumentNullException>());
109+
110+
var element = new Definition();
111+
var documentation = new Documentation();
112+
var annotation = new Annotation();
113+
Assert.That(() => element.ComputeOwnedElement(), Has.Count.EqualTo(0));
114+
115+
element.AssignOwnership(annotation, documentation);
116+
Assert.That(() => element.ComputeDocumentation(), Is.EquivalentTo([documentation]));
60117
}
61118

62119
[Test]
63-
public void ComputeOwner_ThrowsNotSupportedException()
120+
public void VerifyComputeOwner()
64121
{
65-
Assert.That(() => ((IElement)null).ComputeOwner(), Throws.TypeOf<NotSupportedException>());
122+
Assert.That(() => ((IElement)null).ComputeOwner(), Throws.TypeOf<ArgumentNullException>());
123+
124+
var element = new Definition();
125+
var documentation = new Documentation();
126+
var annotation = new Annotation();
127+
128+
using (Assert.EnterMultipleScope())
129+
{
130+
Assert.That(() => element.ComputeOwner(), Is.Null);
131+
Assert.That(() => documentation.ComputeOwner(), Is.Null);
132+
}
133+
134+
element.AssignOwnership(annotation, documentation);
135+
136+
using (Assert.EnterMultipleScope())
137+
{
138+
Assert.That(() => element.ComputeOwner(), Is.Null);
139+
Assert.That(() => documentation.ComputeOwner(), Is.EqualTo(element));
140+
}
66141
}
67142

68143
[Test]
69-
public void ComputeOwningMembership_ThrowsNotSupportedException()
144+
public void VerifyComputeOwningMembership()
70145
{
71-
Assert.That(() => ((IElement)null).ComputeOwningMembership(), Throws.TypeOf<NotSupportedException>());
146+
Assert.That(() => ((IElement)null).ComputeOwningMembership(), Throws.TypeOf<ArgumentNullException>());
147+
148+
var element = new Definition();
149+
var documentation = new Documentation();
150+
var annotation = new Annotation();
151+
152+
Assert.That(() => documentation.ComputeOwningMembership(), Is.Null);
153+
154+
element.AssignOwnership(annotation, documentation);
155+
156+
using (Assert.EnterMultipleScope())
157+
{
158+
Assert.That(() => documentation.ComputeOwningMembership(), Is.Null);
159+
Assert.That(() => element.ComputeOwningMembership(), Is.Null);
160+
}
161+
162+
var membership = new OwningMembership();
163+
var namespaceElement = new Namespace();
164+
165+
namespaceElement.AssignOwnership(membership, element);
166+
Assert.That(() => element.ComputeOwningMembership(), Is.EqualTo(membership));
72167
}
73168

74169
[Test]
75-
public void ComputeOwningNamespace_ThrowsNotSupportedException()
170+
public void VerifyComputeOwningNamespace()
76171
{
77-
Assert.That(() => ((IElement)null).ComputeOwningNamespace(), Throws.TypeOf<NotSupportedException>());
172+
Assert.That(() => ((IElement)null).ComputeOwningNamespace(), Throws.TypeOf<ArgumentNullException>());
173+
174+
var element = new Definition();
175+
var documentation = new Documentation();
176+
var annotation = new Annotation();
177+
element.AssignOwnership(annotation, documentation);
178+
179+
Assert.That(() => documentation.ComputeOwningNamespace(), Is.Null);
180+
var membership = new OwningMembership();
181+
var namespaceElement = new Namespace();
182+
183+
namespaceElement.AssignOwnership(membership, element);
184+
Assert.That(() => element.ComputeOwningNamespace(), Is.EqualTo(namespaceElement));
78185
}
79186

80187
[Test]
81-
public void ComputeQualifiedName_ThrowsNotSupportedException()
188+
public void VerifyComputeQualifiedName()
82189
{
83-
Assert.That(() => ((IElement)null).ComputeQualifiedName(), Throws.TypeOf<NotSupportedException>());
190+
Assert.That(() => ((IElement)null).ComputeQualifiedName(), Throws.TypeOf<ArgumentNullException>());
191+
192+
var element = new Definition();
193+
194+
Assert.That(() => element.ComputeQualifiedName(), Is.Null);
195+
196+
var membership = new OwningMembership();
197+
var namespaceElement = new Namespace();
198+
199+
namespaceElement.AssignOwnership(membership, element);
200+
element.DeclaredName = "name";
201+
202+
Assert.That(() => element.ComputeQualifiedName(), Is.EqualTo("name"));
84203
}
85204

86205
[Test]
87-
public void ComputeShortName_ThrowsNotSupportedException()
206+
public void VerifyComputeShortName()
88207
{
89-
Assert.That(() => ((IElement)null).ComputeShortName(), Throws.TypeOf<NotSupportedException>());
208+
Assert.That(() => ((IElement)null).ComputeShortName(), Throws.TypeOf<ArgumentNullException>());
209+
210+
var element = new Definition();
211+
212+
Assert.That(() => element.ComputeShortName(), Is.Null);
213+
214+
element.DeclaredShortName = "shortName";
215+
Assert.That(() => element.ComputeShortName(), Is.EqualTo("shortName"));
90216
}
91217

92218
[Test]
93-
public void ComputeTextualRepresentation_ThrowsNotSupportedException()
219+
public void VerifyComputeTextualRepresentation()
94220
{
95-
Assert.That(() => ((IElement)null).ComputeTextualRepresentation(), Throws.TypeOf<NotSupportedException>());
221+
Assert.That(() => ((IElement)null).ComputeTextualRepresentation(), Throws.TypeOf<ArgumentNullException>());
222+
223+
var element = new Definition();
224+
var textualRepresentation = new TextualRepresentation();
225+
var annotation = new Annotation();
226+
227+
Assert.That(() => element.ComputeTextualRepresentation(), Has.Count.EqualTo(0));
228+
229+
element.AssignOwnership(annotation, textualRepresentation);
230+
231+
Assert.That(element.ComputeTextualRepresentation(), Is.EquivalentTo([textualRepresentation]));
96232
}
97233
}
98234
}

0 commit comments

Comments
 (0)