Skip to content

Commit e30b161

Browse files
Fix #173
1 parent e32f982 commit e30b161

2 files changed

Lines changed: 230 additions & 68 deletions

File tree

Lines changed: 189 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,236 @@
11
// -------------------------------------------------------------------------------------------------
22
// <copyright file="RequirementDefinitionExtensionsTestFixture.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.Types;
28+
using SysML2.NET.Core.POCO.Kernel.Behaviors;
29+
using SysML2.NET.Core.POCO.Root.Annotations;
30+
using SysML2.NET.Core.POCO.Systems.Constraints;
31+
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
32+
using SysML2.NET.Core.POCO.Systems.Parts;
2733
using SysML2.NET.Core.POCO.Systems.Requirements;
34+
using SysML2.NET.Core.Systems.Requirements;
35+
using SysML2.NET.Extensions;
2836

2937
[TestFixture]
3038
public class RequirementDefinitionExtensionsTestFixture
3139
{
3240
[Test]
33-
public void ComputeActorParameter_ThrowsNotSupportedException()
41+
public void VerifyComputeActorParameter()
3442
{
35-
Assert.That(() => ((IRequirementDefinition)null).ComputeActorParameter(), Throws.TypeOf<NotSupportedException>());
43+
Assert.That(() => ((IRequirementDefinition)null).ComputeActorParameter(), Throws.TypeOf<ArgumentNullException>());
44+
45+
var requirementDefinition = new RequirementDefinition();
46+
47+
Assert.That(requirementDefinition.ComputeActorParameter(), Is.Empty);
48+
49+
// Discrimination: add a ParameterMembership (not ActorMembership) — must be excluded from result.
50+
var parameterMembership = new ParameterMembership();
51+
var parameterUsage = new Usage();
52+
requirementDefinition.AssignOwnership(parameterMembership, parameterUsage);
53+
54+
Assert.That(requirementDefinition.ComputeActorParameter(), Is.Empty);
55+
56+
// Populated case: ActorMembership is present; selecting ownedActorParameter triggers an
57+
// upstream stub (ActorMembershipExtensions.ComputeOwnedActorParameter is not yet implemented).
58+
var actorMembership = new ActorMembership();
59+
var actorPartUsage = new PartUsage();
60+
requirementDefinition.AssignOwnership(actorMembership, actorPartUsage);
61+
62+
Assert.That(() => requirementDefinition.ComputeActorParameter(), Throws.TypeOf<NotSupportedException>());
3663
}
37-
64+
3865
[Test]
39-
public void ComputeAssumedConstraint_ThrowsNotSupportedException()
66+
public void VerifyComputeAssumedConstraint()
4067
{
41-
Assert.That(() => ((IRequirementDefinition)null).ComputeAssumedConstraint(), Throws.TypeOf<NotSupportedException>());
68+
Assert.That(() => ((IRequirementDefinition)null).ComputeAssumedConstraint(), Throws.TypeOf<ArgumentNullException>());
69+
70+
var requirementDefinition = new RequirementDefinition();
71+
72+
Assert.That(requirementDefinition.ComputeAssumedConstraint(), Is.Empty);
73+
74+
// Type discrimination: add a FeatureMembership (not IRequirementConstraintMembership) — excluded.
75+
var featureMembership = new FeatureMembership();
76+
var featureUsage = new Usage();
77+
requirementDefinition.AssignOwnership(featureMembership, featureUsage);
78+
79+
Assert.That(requirementDefinition.ComputeAssumedConstraint(), Is.Empty);
80+
81+
// Kind discrimination: add a RequirementConstraintMembership with Kind = Requirement — excluded.
82+
var requiredMembership = new RequirementConstraintMembership { Kind = RequirementConstraintKind.Requirement };
83+
var requiredConstraintUsage = new ConstraintUsage();
84+
requirementDefinition.AssignOwnership(requiredMembership, requiredConstraintUsage);
85+
86+
Assert.That(requirementDefinition.ComputeAssumedConstraint(), Is.Empty);
87+
88+
// Populated case: RequirementConstraintMembership with Kind = Assumption; selecting
89+
// ownedConstraint triggers an upstream stub (RequirementConstraintMembershipExtensions
90+
// .ComputeOwnedConstraint is not yet implemented).
91+
var assumedMembership = new RequirementConstraintMembership { Kind = RequirementConstraintKind.Assumption };
92+
var assumedConstraintUsage = new ConstraintUsage();
93+
requirementDefinition.AssignOwnership(assumedMembership, assumedConstraintUsage);
94+
95+
Assert.That(() => requirementDefinition.ComputeAssumedConstraint(), Throws.TypeOf<NotSupportedException>());
4296
}
43-
97+
4498
[Test]
45-
public void ComputeFramedConcern_ThrowsNotSupportedException()
99+
public void VerifyComputeFramedConcern()
46100
{
47-
Assert.That(() => ((IRequirementDefinition)null).ComputeFramedConcern(), Throws.TypeOf<NotSupportedException>());
101+
Assert.That(() => ((IRequirementDefinition)null).ComputeFramedConcern(), Throws.TypeOf<ArgumentNullException>());
102+
103+
var requirementDefinition = new RequirementDefinition();
104+
105+
Assert.That(requirementDefinition.ComputeFramedConcern(), Is.Empty);
106+
107+
// Discrimination cannot be tested at this layer: any IFeatureMembership subtype (including
108+
// RequirementConstraintMembership) causes subject.featureMembership to traverse
109+
// RemoveRedefinedFeatures → IFeatureMembership.ownedMemberFeature, which dispatches to the
110+
// stubbed RequirementConstraintMembershipExtensions.ComputeOwnedConstraint and throws
111+
// NotSupportedException — identical to the populated stub-blocker case below.
112+
// The discrimination block is omitted until upstream stubs are implemented.
113+
114+
// Populated case: FramedConcernMembership is present; selecting ownedConcern triggers an
115+
// upstream stub (FramedConcernMembershipExtensions.ComputeOwnedConcern is not yet implemented).
116+
var framedMembership = new FramedConcernMembership();
117+
var concernUsage = new ConcernUsage();
118+
requirementDefinition.AssignOwnership(framedMembership, concernUsage);
119+
120+
Assert.That(() => requirementDefinition.ComputeFramedConcern(), Throws.TypeOf<NotSupportedException>());
48121
}
122+
49123
[Test]
50-
public void ComputeRequiredConstraint_ThrowsNotSupportedException()
124+
public void VerifyComputeRequiredConstraint()
51125
{
52-
Assert.That(() => ((IRequirementDefinition)null).ComputeRequiredConstraint(), Throws.TypeOf<NotSupportedException>());
126+
Assert.That(() => ((IRequirementDefinition)null).ComputeRequiredConstraint(), Throws.TypeOf<ArgumentNullException>());
127+
128+
var requirementDefinition = new RequirementDefinition();
129+
130+
Assert.That(requirementDefinition.ComputeRequiredConstraint(), Is.Empty);
131+
132+
// Type discrimination: add a FeatureMembership (not IRequirementConstraintMembership) — excluded.
133+
var featureMembership = new FeatureMembership();
134+
var featureUsage = new Usage();
135+
requirementDefinition.AssignOwnership(featureMembership, featureUsage);
136+
137+
Assert.That(requirementDefinition.ComputeRequiredConstraint(), Is.Empty);
138+
139+
// Kind discrimination: add a RequirementConstraintMembership with Kind = Assumption — excluded.
140+
var assumedMembership = new RequirementConstraintMembership { Kind = RequirementConstraintKind.Assumption };
141+
var assumedConstraintUsage = new ConstraintUsage();
142+
requirementDefinition.AssignOwnership(assumedMembership, assumedConstraintUsage);
143+
144+
Assert.That(requirementDefinition.ComputeRequiredConstraint(), Is.Empty);
145+
146+
// Populated case: RequirementConstraintMembership with Kind = Requirement; selecting
147+
// ownedConstraint triggers an upstream stub (RequirementConstraintMembershipExtensions
148+
// .ComputeOwnedConstraint is not yet implemented).
149+
var requiredMembership = new RequirementConstraintMembership { Kind = RequirementConstraintKind.Requirement };
150+
var requiredConstraintUsage = new ConstraintUsage();
151+
requirementDefinition.AssignOwnership(requiredMembership, requiredConstraintUsage);
152+
153+
Assert.That(() => requirementDefinition.ComputeRequiredConstraint(), Throws.TypeOf<NotSupportedException>());
53154
}
54-
155+
55156
[Test]
56-
public void ComputeStakeholderParameter_ThrowsNotSupportedException()
157+
public void VerifyComputeStakeholderParameter()
57158
{
58-
Assert.That(() => ((IRequirementDefinition)null).ComputeStakeholderParameter(), Throws.TypeOf<NotSupportedException>());
159+
Assert.That(() => ((IRequirementDefinition)null).ComputeStakeholderParameter(), Throws.TypeOf<ArgumentNullException>());
160+
161+
var requirementDefinition = new RequirementDefinition();
162+
163+
Assert.That(requirementDefinition.ComputeStakeholderParameter(), Is.Empty);
164+
165+
// Discrimination cannot be tested at this layer: any IFeatureMembership subtype (including
166+
// ActorMembership) causes subject.featureMembership to traverse RemoveRedefinedFeatures →
167+
// IFeatureMembership.ownedMemberFeature, which dispatches to the stubbed
168+
// ActorMembershipExtensions.ComputeOwnedActorParameter and throws NotSupportedException —
169+
// identical to the populated stub-blocker case below.
170+
// The discrimination block is omitted until upstream stubs are implemented.
171+
172+
// Populated case: StakeholderMembership is present; selecting ownedStakeholderParameter
173+
// triggers an upstream stub (StakeholderMembershipExtensions.ComputeOwnedStakeholderParameter
174+
// is not yet implemented).
175+
var stakeholderMembership = new StakeholderMembership();
176+
var stakeholderPartUsage = new PartUsage();
177+
requirementDefinition.AssignOwnership(stakeholderMembership, stakeholderPartUsage);
178+
179+
Assert.That(() => requirementDefinition.ComputeStakeholderParameter(), Throws.TypeOf<NotSupportedException>());
59180
}
60-
181+
61182
[Test]
62-
public void ComputeSubjectParameter_ThrowsNotSupportedException()
183+
public void VerifyComputeSubjectParameter()
63184
{
64-
Assert.That(() => ((IRequirementDefinition)null).ComputeSubjectParameter(), Throws.TypeOf<NotSupportedException>());
185+
Assert.That(() => ((IRequirementDefinition)null).ComputeSubjectParameter(), Throws.TypeOf<ArgumentNullException>());
186+
187+
var requirementDefinition = new RequirementDefinition();
188+
189+
// Empty case: no SubjectMembership in featureMembership → null.
190+
Assert.That(requirementDefinition.ComputeSubjectParameter(), Is.Null);
191+
192+
// Discrimination: add a ParameterMembership (not SubjectMembership) → still null.
193+
var parameterMembership = new ParameterMembership();
194+
var parameterUsage = new Usage();
195+
requirementDefinition.AssignOwnership(parameterMembership, parameterUsage);
196+
197+
Assert.That(requirementDefinition.ComputeSubjectParameter(), Is.Null);
198+
199+
// Populated case: SubjectMembership is present; selecting ownedSubjectParameter triggers an
200+
// upstream stub (SubjectMembershipExtensions.ComputeOwnedSubjectParameter is not yet implemented).
201+
var subjectMembership = new SubjectMembership();
202+
var subjectUsage = new Usage();
203+
requirementDefinition.AssignOwnership(subjectMembership, subjectUsage);
204+
205+
Assert.That(() => requirementDefinition.ComputeSubjectParameter(), Throws.TypeOf<NotSupportedException>());
65206
}
66-
207+
208+
private static readonly string[] ExpectedSingleComputedText = ["The requirement text."];
209+
private static readonly string[] ExpectedMultipleComputedText = ["The requirement text.", "Additional context."];
210+
67211
[Test]
68-
public void ComputeText_ThrowsNotSupportedException()
212+
public void VerifyComputeText()
69213
{
70-
Assert.That(() => ((IRequirementDefinition)null).ComputeText(), Throws.TypeOf<NotSupportedException>());
214+
Assert.That(() => ((IRequirementDefinition)null).ComputeText(), Throws.TypeOf<ArgumentNullException>());
215+
216+
var requirementDefinition = new RequirementDefinition();
217+
218+
// Empty case: no Documentation elements → empty list.
219+
Assert.That(requirementDefinition.ComputeText(), Is.Empty);
220+
221+
// One Documentation with a body.
222+
var firstDocumentation = new Documentation { Body = "The requirement text." };
223+
var firstAnnotation = new Annotation();
224+
requirementDefinition.AssignOwnership(firstAnnotation, firstDocumentation);
225+
226+
Assert.That(requirementDefinition.ComputeText(), Is.EqualTo(ExpectedSingleComputedText));
227+
228+
// Two Documentation elements — both bodies appear in order.
229+
var secondDocumentation = new Documentation { Body = "Additional context." };
230+
var secondAnnotation = new Annotation();
231+
requirementDefinition.AssignOwnership(secondAnnotation, secondDocumentation);
232+
233+
Assert.That(requirementDefinition.ComputeText(), Is.EqualTo(ExpectedMultipleComputedText));
71234
}
72235
}
73236
}

0 commit comments

Comments
 (0)