Skip to content

Commit 2b16f09

Browse files
Fix #120 (#240)
1 parent 57947a6 commit 2b16f09

2 files changed

Lines changed: 50 additions & 16 deletions

File tree

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,61 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// <copyright file="DocumentationExtensionsTestFixture.cs" company="Starion Group S.A.">
3-
//
3+
//
44
// Copyright 2022-2026 Starion Group S.A.
5-
//
5+
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
88
// You may obtain a copy of the License at
9-
//
9+
//
1010
// http://www.apache.org/licenses/LICENSE-2.0
11-
//
11+
//
1212
// Unless required by applicable law or agreed to in writing, software
1313
// distributed under the License is distributed on an "AS IS" BASIS,
1414
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
17-
//
17+
//
1818
// </copyright>
1919
// ------------------------------------------------------------------------------------------------
2020

2121
namespace SysML2.NET.Tests.Extend
2222
{
2323
using System;
24-
24+
2525
using NUnit.Framework;
26-
26+
2727
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;
2832

2933
[TestFixture]
3034
public class DocumentationExtensionsTestFixture
3135
{
3236
[Test]
33-
public void ComputeDocumentedElement_ThrowsNotSupportedException()
37+
public void VerifyComputeDocumentedElement()
3438
{
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));
3659
}
3760
}
3861
}

SysML2.NET/Extend/DocumentationExtensions.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
namespace SysML2.NET.Core.POCO.Root.Annotations
2222
{
2323
using System;
24-
using System.Collections.Generic;
2524

2625
using SysML2.NET.Core.POCO.Root.Elements;
27-
using SysML2.NET.Core.POCO.Root.Namespaces;
26+
using SysML2.NET.Exceptions;
2827

2928
/// <summary>
3029
/// The <see cref="DocumentationExtensions"/> class provides extensions methods for
@@ -33,18 +32,30 @@ namespace SysML2.NET.Core.POCO.Root.Annotations
3332
internal static class DocumentationExtensions
3433
{
3534
/// <summary>
36-
/// Computes the derived property.
35+
/// Computes the derived property <c>documentedElement</c>.
3736
/// </summary>
37+
/// <remarks>
38+
/// Documentation is a Comment that specifically documents a documentedElement, which must be its owner.
39+
/// The <c>documentedElement</c> property redefines <c>annotatedElement</c> with cardinality 1..1 and
40+
/// subsets <c>owner</c>. The documented element is therefore the owner of the Documentation, accessed
41+
/// via <c>owner</c> (derived as <c>owningRelationship.owningRelatedElement</c>).
42+
/// </remarks>
3843
/// <param name="documentationSubject">
3944
/// The subject <see cref="IDocumentation"/>
4045
/// </param>
4146
/// <returns>
42-
/// the computed result
47+
/// The <see cref="IElement"/> that is documented by this <see cref="IDocumentation"/>
4348
/// </returns>
44-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
4549
internal static IElement ComputeDocumentedElement(this IDocumentation documentationSubject)
4650
{
47-
throw new NotSupportedException("Create a GitHub issue when this method is required");
51+
if (documentationSubject == null)
52+
{
53+
throw new ArgumentNullException(nameof(documentationSubject));
54+
}
55+
56+
return documentationSubject.owner
57+
?? throw new IncompleteModelException(
58+
$"{nameof(documentationSubject)} must have an owner (its documentedElement)");
4859
}
4960

5061
}

0 commit comments

Comments
 (0)