|
1 | | -// ------------------------------------------------------------------------------------------------- |
| 1 | +// ------------------------------------------------------------------------------------------------- |
2 | 2 | // <copyright file="DocumentationExtensionsTestFixture.cs" company="Starion Group S.A."> |
3 | | -// |
| 3 | +// |
4 | 4 | // Copyright 2022-2026 Starion Group S.A. |
5 | | -// |
| 5 | +// |
6 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | // you may not use this file except in compliance with the License. |
8 | 8 | // You may obtain a copy of the License at |
9 | | -// |
| 9 | +// |
10 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
11 | | -// |
| 11 | +// |
12 | 12 | // Unless required by applicable law or agreed to in writing, software |
13 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
14 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | 15 | // See the License for the specific language governing permissions and |
16 | 16 | // limitations under the License. |
17 | | -// |
| 17 | +// |
18 | 18 | // </copyright> |
19 | 19 | // ------------------------------------------------------------------------------------------------ |
20 | 20 |
|
21 | 21 | namespace SysML2.NET.Tests.Extend |
22 | 22 | { |
23 | 23 | using System; |
24 | | - |
| 24 | + |
25 | 25 | using NUnit.Framework; |
26 | | - |
| 26 | + |
27 | 27 | using SysML2.NET.Core.POCO.Root.Annotations; |
| 28 | + using SysML2.NET.Core.POCO.Root.Elements; |
| 29 | + using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage; |
| 30 | + using SysML2.NET.Exceptions; |
| 31 | + using SysML2.NET.Extensions; |
28 | 32 |
|
29 | 33 | [TestFixture] |
30 | 34 | public class DocumentationExtensionsTestFixture |
31 | 35 | { |
32 | 36 | [Test] |
33 | | - public void ComputeDocumentedElement_ThrowsNotSupportedException() |
| 37 | + public void VerifyComputeDocumentedElement() |
34 | 38 | { |
35 | | - Assert.That(() => ((IDocumentation)null).ComputeDocumentedElement(), Throws.TypeOf<NotSupportedException>()); |
| 39 | + Assert.That(() => ((IDocumentation)null).ComputeDocumentedElement(), |
| 40 | + Throws.TypeOf<ArgumentNullException>()); |
| 41 | + |
| 42 | + // Fresh Documentation has no owning relationship, so the documented element cannot be |
| 43 | + // resolved — the implementation must throw IncompleteModelException (Option A path). |
| 44 | + var emptyDoc = new Documentation(); |
| 45 | + |
| 46 | + Assert.That(() => emptyDoc.ComputeDocumentedElement(), |
| 47 | + Throws.TypeOf<IncompleteModelException>()); |
| 48 | + |
| 49 | + // Populated case: wire a Definition as the owner of the Documentation via an Annotation. |
| 50 | + // After AssignOwnership, documentation.OwningRelationship.OwningRelatedElement == target, |
| 51 | + // so ComputeDocumentedElement() must return target. |
| 52 | + var target = new Definition(); |
| 53 | + var annotation = new Annotation(); |
| 54 | + var doc = new Documentation(); |
| 55 | + |
| 56 | + target.AssignOwnership(annotation, doc); |
| 57 | + |
| 58 | + Assert.That(doc.ComputeDocumentedElement(), Is.SameAs(target)); |
36 | 59 | } |
37 | 60 | } |
38 | 61 | } |
0 commit comments