|
21 | 21 | namespace SysML2.NET.Tests.Extend |
22 | 22 | { |
23 | 23 | using System; |
24 | | - |
| 24 | + using System.Linq; |
| 25 | + |
25 | 26 | using NUnit.Framework; |
26 | | - |
| 27 | + |
| 28 | + using SysML2.NET.Core.POCO.Root.Annotations; |
27 | 29 | 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; |
28 | 33 |
|
29 | 34 | [TestFixture] |
30 | 35 | public class ElementExtensionsTestFixture |
31 | 36 | { |
32 | 37 | [Test] |
33 | | - public void ComputeDocumentation_ThrowsNotSupportedException() |
| 38 | + public void VerifyComputeDocumentation() |
34 | 39 | { |
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])); |
36 | 51 | } |
37 | 52 |
|
38 | 53 | [Test] |
39 | | - public void ComputeIsLibraryElement_ThrowsNotSupportedException() |
| 54 | + public void VerifyComputeIsLibraryElement() |
40 | 55 | { |
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 | + } |
42 | 75 | } |
43 | 76 |
|
44 | 77 | [Test] |
45 | | - public void ComputeName_ThrowsNotSupportedException() |
| 78 | + public void VerifyComputeName() |
46 | 79 | { |
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")); |
48 | 88 | } |
49 | 89 |
|
50 | 90 | [Test] |
51 | | - public void ComputeOwnedAnnotation_ThrowsNotSupportedException() |
| 91 | + public void VerifyComputeOwnedAnnotation() |
52 | 92 | { |
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])); |
54 | 103 | } |
55 | 104 |
|
56 | 105 | [Test] |
57 | | - public void ComputeOwnedElement_ThrowsNotSupportedException() |
| 106 | + public void VerifyComputeOwnedElement() |
58 | 107 | { |
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])); |
60 | 117 | } |
61 | 118 |
|
62 | 119 | [Test] |
63 | | - public void ComputeOwner_ThrowsNotSupportedException() |
| 120 | + public void VerifyComputeOwner() |
64 | 121 | { |
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 | + } |
66 | 141 | } |
67 | 142 |
|
68 | 143 | [Test] |
69 | | - public void ComputeOwningMembership_ThrowsNotSupportedException() |
| 144 | + public void VerifyComputeOwningMembership() |
70 | 145 | { |
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)); |
72 | 167 | } |
73 | 168 |
|
74 | 169 | [Test] |
75 | | - public void ComputeOwningNamespace_ThrowsNotSupportedException() |
| 170 | + public void VerifyComputeOwningNamespace() |
76 | 171 | { |
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)); |
78 | 185 | } |
79 | 186 |
|
80 | 187 | [Test] |
81 | | - public void ComputeQualifiedName_ThrowsNotSupportedException() |
| 188 | + public void VerifyComputeQualifiedName() |
82 | 189 | { |
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")); |
84 | 203 | } |
85 | 204 |
|
86 | 205 | [Test] |
87 | | - public void ComputeShortName_ThrowsNotSupportedException() |
| 206 | + public void VerifyComputeShortName() |
88 | 207 | { |
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")); |
90 | 216 | } |
91 | 217 |
|
92 | 218 | [Test] |
93 | | - public void ComputeTextualRepresentation_ThrowsNotSupportedException() |
| 219 | + public void VerifyComputeTextualRepresentation() |
94 | 220 | { |
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])); |
96 | 232 | } |
97 | 233 | } |
98 | 234 | } |
0 commit comments