Skip to content

Commit 9fdc031

Browse files
Fix #205
1 parent 34f5332 commit 9fdc031

2 files changed

Lines changed: 252 additions & 59 deletions

File tree

Lines changed: 189 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,229 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// <copyright file="ViewUsageExtensionsTestFixture.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+
27+
using SysML2.NET.Core.POCO.Core.Features;
28+
using SysML2.NET.Core.POCO.Core.Types;
29+
using SysML2.NET.Core.POCO.Kernel.Functions;
30+
using SysML2.NET.Core.POCO.Kernel.Packages;
31+
using SysML2.NET.Core.POCO.Root.Namespaces;
32+
using SysML2.NET.Core.POCO.Systems.Requirements;
2733
using SysML2.NET.Core.POCO.Systems.Views;
34+
using SysML2.NET.Extensions;
2835

2936
[TestFixture]
3037
public class ViewUsageExtensionsTestFixture
3138
{
3239
[Test]
33-
public void ComputeExposedElement_ThrowsNotSupportedException()
40+
public void VerifyComputeExposedElement()
3441
{
35-
Assert.That(() => ((IViewUsage)null).ComputeExposedElement(), Throws.TypeOf<NotSupportedException>());
42+
Assert.That(() => ((IViewUsage)null).ComputeExposedElement(), Throws.TypeOf<ArgumentNullException>());
43+
44+
var viewUsage = new ViewUsage();
45+
46+
// Empty: no ownedImport → empty list.
47+
Assert.That(viewUsage.ComputeExposedElement(), Is.Empty);
48+
49+
// Discrimination: non-Expose import (MembershipImport) → excluded.
50+
var nonExposeMembership = new MembershipImport();
51+
viewUsage.AssignOwnership(nonExposeMembership);
52+
53+
Assert.That(viewUsage.ComputeExposedElement(), Is.Empty);
54+
55+
// STUB-BLOCKER: adding a MembershipExpose dispatches ComputeExposedElement to
56+
// MembershipExpose.ImportedMemberships(excluded), which calls
57+
// MembershipImportExtensions.ComputeRedefinedImportedMembershipsOperation — a
58+
// NotSupportedException stub. The populated positive case cannot be tested until that
59+
// upstream stub is implemented.
60+
var membershipExpose = new MembershipExpose();
61+
viewUsage.AssignOwnership(membershipExpose);
62+
63+
Assert.That(() => viewUsage.ComputeExposedElement(), Throws.TypeOf<NotSupportedException>());
3664
}
65+
3766
[Test]
38-
public void ComputeSatisfiedViewpoint_ThrowsNotSupportedException()
67+
public void VerifyComputeSatisfiedViewpoint()
3968
{
40-
Assert.That(() => ((IViewUsage)null).ComputeSatisfiedViewpoint(), Throws.TypeOf<NotSupportedException>());
69+
Assert.That(() => ((IViewUsage)null).ComputeSatisfiedViewpoint(), Throws.TypeOf<ArgumentNullException>());
70+
71+
var viewUsage = new ViewUsage();
72+
73+
// Empty: no nestedRequirement → empty list.
74+
Assert.That(viewUsage.ComputeSatisfiedViewpoint(), Is.Empty);
75+
76+
// Discrimination: plain RequirementUsage (not ViewpointUsage) → excluded.
77+
var plainRequirement = new RequirementUsage { IsComposite = true };
78+
var plainRequirementMembership = new FeatureMembership();
79+
viewUsage.AssignOwnership(plainRequirementMembership, plainRequirement);
80+
81+
Assert.That(viewUsage.ComputeSatisfiedViewpoint(), Is.Empty);
82+
83+
// Predicate discrimination: ViewpointUsage with IsComposite = false → excluded.
84+
var nonCompositeViewpoint = new ViewpointUsage { IsComposite = false };
85+
var nonCompositeViewpointMembership = new FeatureMembership();
86+
viewUsage.AssignOwnership(nonCompositeViewpointMembership, nonCompositeViewpoint);
87+
88+
Assert.That(viewUsage.ComputeSatisfiedViewpoint(), Is.Empty);
89+
90+
// Positive: ViewpointUsage with IsComposite = true → returned.
91+
var compositeViewpoint1 = new ViewpointUsage { IsComposite = true };
92+
var compositeViewpointMembership1 = new FeatureMembership();
93+
viewUsage.AssignOwnership(compositeViewpointMembership1, compositeViewpoint1);
94+
95+
Assert.That(viewUsage.ComputeSatisfiedViewpoint(), Is.EqualTo([compositeViewpoint1]));
96+
97+
// Populated: second composite ViewpointUsage also returned in iteration order.
98+
var compositeViewpoint2 = new ViewpointUsage { IsComposite = true };
99+
var compositeViewpointMembership2 = new FeatureMembership();
100+
viewUsage.AssignOwnership(compositeViewpointMembership2, compositeViewpoint2);
101+
102+
Assert.That(viewUsage.ComputeSatisfiedViewpoint(), Is.EqualTo([compositeViewpoint1, compositeViewpoint2]));
103+
}
104+
105+
[Test]
106+
public void VerifyComputeViewCondition()
107+
{
108+
Assert.That(() => ((IViewUsage)null).ComputeViewCondition(), Throws.TypeOf<ArgumentNullException>());
109+
110+
var viewUsage = new ViewUsage();
111+
112+
// Empty: no ownedMembership → empty list.
113+
Assert.That(viewUsage.ComputeViewCondition(), Is.Empty);
114+
115+
// Discrimination: non-ElementFilterMembership in ownedMembership → excluded.
116+
var nonFilterFeature = new Feature();
117+
var nonFilterMembership = new FeatureMembership();
118+
viewUsage.AssignOwnership(nonFilterMembership, nonFilterFeature);
119+
120+
Assert.That(viewUsage.ComputeViewCondition(), Is.Empty);
121+
122+
// STUB-BLOCKER: Wiring an ElementFilterMembership and reading its condition property
123+
// dispatches to ElementFilterMembershipExtensions.ComputeCondition, which is a NotSupportedException
124+
// stub. The populated case cannot be tested cleanly until that upstream stub is implemented.
125+
var filterCondition = new BooleanExpression();
126+
var filterMembership = new ElementFilterMembership();
127+
viewUsage.AssignOwnership(filterMembership, filterCondition);
128+
129+
Assert.That(() => viewUsage.ComputeViewCondition(), Throws.TypeOf<NotSupportedException>());
41130
}
131+
42132
[Test]
43-
public void ComputeViewCondition_ThrowsNotSupportedException()
133+
public void VerifyComputeViewDefinition()
44134
{
45-
Assert.That(() => ((IViewUsage)null).ComputeViewCondition(), Throws.TypeOf<NotSupportedException>());
135+
Assert.That(() => ((IViewUsage)null).ComputeViewDefinition(), Throws.TypeOf<ArgumentNullException>());
136+
137+
var viewUsage = new ViewUsage();
138+
139+
// Empty: no FeatureTyping → null.
140+
Assert.That(viewUsage.ComputeViewDefinition(), Is.Null);
141+
142+
// Negative: FeatureTyping whose Type is a non-ViewDefinition → null.
143+
var nonViewDefinitionType = new Feature();
144+
var typingToNonViewDefinition = new FeatureTyping { Type = nonViewDefinitionType };
145+
viewUsage.AssignOwnership(typingToNonViewDefinition);
146+
147+
Assert.That(viewUsage.ComputeViewDefinition(), Is.Null);
148+
149+
// Positive: FeatureTyping whose Type is a ViewDefinition → returned.
150+
var viewDefinition1 = new ViewDefinition();
151+
var typingToViewDefinition1 = new FeatureTyping { Type = viewDefinition1 };
152+
viewUsage.AssignOwnership(typingToViewDefinition1);
153+
154+
Assert.That(viewUsage.ComputeViewDefinition(), Is.SameAs(viewDefinition1));
155+
156+
// Multiple: two ViewDefinition typings → first returned (FirstOrDefault).
157+
var viewDefinition2 = new ViewDefinition();
158+
var typingToViewDefinition2 = new FeatureTyping { Type = viewDefinition2 };
159+
viewUsage.AssignOwnership(typingToViewDefinition2);
160+
161+
Assert.That(viewUsage.ComputeViewDefinition(), Is.SameAs(viewDefinition1));
46162
}
163+
47164
[Test]
48-
public void ComputeViewDefinition_ThrowsNotSupportedException()
165+
public void VerifyComputeViewRendering()
49166
{
50-
Assert.That(() => ((IViewUsage)null).ComputeViewDefinition(), Throws.TypeOf<NotSupportedException>());
167+
Assert.That(() => ((IViewUsage)null).ComputeViewRendering(), Throws.TypeOf<ArgumentNullException>());
168+
169+
var viewUsage = new ViewUsage();
170+
171+
// Empty: no featureMembership → null.
172+
Assert.That(viewUsage.ComputeViewRendering(), Is.Null);
173+
174+
// Discrimination: non-ViewRenderingMembership featureMembership → null.
175+
var plainFeature = new Feature();
176+
var plainFeatureMembership = new FeatureMembership();
177+
viewUsage.AssignOwnership(plainFeatureMembership, plainFeature);
178+
179+
Assert.That(viewUsage.ComputeViewRendering(), Is.Null);
180+
181+
// STUB-BLOCKER: Wiring a ViewRenderingMembership and reading its referencedRendering
182+
// property dispatches to ViewRenderingMembershipExtensions.ComputeReferencedRendering,
183+
// which is a NotSupportedException stub. The populated positive case cannot be tested
184+
// cleanly until that upstream stub is implemented.
185+
var renderingUsage = new RenderingUsage();
186+
var viewRenderingMembership = new ViewRenderingMembership();
187+
viewUsage.AssignOwnership(viewRenderingMembership, renderingUsage);
188+
189+
Assert.That(() => viewUsage.ComputeViewRendering(), Throws.TypeOf<NotSupportedException>());
51190
}
191+
52192
[Test]
53-
public void ComputeViewRendering_ThrowsNotSupportedException()
193+
public void VerifyComputeIncludeAsExposedOperation()
54194
{
55-
Assert.That(() => ((IViewUsage)null).ComputeViewRendering(), Throws.TypeOf<NotSupportedException>());
195+
// Null guard on subject.
196+
Assert.That(() => ((IViewUsage)null).ComputeIncludeAsExposedOperation(new Feature()), Throws.TypeOf<ArgumentNullException>());
197+
198+
var viewUsage = new ViewUsage();
199+
200+
// Null guard on element parameter.
201+
Assert.That(() => viewUsage.ComputeIncludeAsExposedOperation(null), Throws.TypeOf<ArgumentNullException>());
202+
203+
var element = new Feature();
204+
205+
// Case (a) — empty conditions: ViewUsage has no ElementFilterMembership in membership;
206+
// forAll over empty sequence is vacuously true → returns true.
207+
Assert.That(viewUsage.ComputeIncludeAsExposedOperation(element), Is.True);
208+
209+
// Case (a) variant: non-filter memberships present, still no ElementFilterMembership →
210+
// conditions remain empty → vacuously true.
211+
var nonFilterFeature = new Feature();
212+
var nonFilterMembership = new FeatureMembership();
213+
viewUsage.AssignOwnership(nonFilterMembership, nonFilterFeature);
214+
215+
Assert.That(viewUsage.ComputeIncludeAsExposedOperation(element), Is.True);
216+
217+
// Cases (b), (c), (d) — STUB-BLOCKER: adding an ElementFilterMembership and reading its
218+
// condition property dispatches to ElementFilterMembershipExtensions.ComputeCondition,
219+
// which is a NotSupportedException stub. Additionally, annotation.annotatingElement
220+
// dispatches to AnnotationExtensions.ComputeAnnotatingElement (also stubbed). These
221+
// cases cannot be tested cleanly until the upstream stubs are implemented.
222+
var filterCondition = new BooleanExpression();
223+
var filterMembership = new ElementFilterMembership();
224+
viewUsage.AssignOwnership(filterMembership, filterCondition);
225+
226+
Assert.That(() => viewUsage.ComputeIncludeAsExposedOperation(element), Throws.TypeOf<NotSupportedException>());
56227
}
57228
}
58229
}

0 commit comments

Comments
 (0)