Skip to content

Commit bba35ee

Browse files
Fix #224: Containment pattern optimized to support reference (#230)
* Fix #224: Containment pattern optimized to support reference * Fix SQ issues and rebase
1 parent 875a904 commit bba35ee

14 files changed

Lines changed: 1860 additions & 79 deletions

File tree

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ dotnet-coverage collect "dotnet test SysML2.NET.sln --no-build" -f xml -o covera
2929

3030
Test framework: **NUnit**. Test classes use `[TestFixture]` and `[Test]` attributes.
3131

32+
**When writing or modifying unit tests** in any `*.Tests/` project: read `TESTING.md` at the repo root for the NUnit conventions (one `[Test]` per method-under-test, `Assert.That` everywhere, `Assert.EnterMultipleScope` only for consecutive asserts, mandatory positive + negative coverage, assertion idiom preferences, `Verify{MethodUnderTest}` naming).
33+
3234
## Architecture
3335

3436
### Code Generation
@@ -155,3 +157,4 @@ Auto-generated DTOs use structured namespaces reflecting the KerML/SysML package
155157
- Use meaningful variable names instead of single-letter names in any context (e.g., 'charIndex' instead of 'i', 'currentChar' instead of 'c', 'element' instead of 'e')
156158
- Use 'NotSupportedException' (not 'NotImplementedException') for placeholder/stub methods that require manual implementation
157159
- Prefer C# property patterns ('x is IType { Prop: value }') over declared-variable-plus-predicate form ('x is IType name && name.Prop == value') when the narrowed variable is only consulted once; the property-pattern form is more concise and intent-revealing
160+
- Surround every braced block (`if`, `else if`, `while`, `for`, `foreach`, `switch`, `using`, `try`/`catch`/`finally`, `lock`, `do…while`, anonymous `{ }`) with a blank line on both sides — the rule does NOT apply at the very start/end of a method body, nor between a `}` and a continuation keyword (`else`, `catch`, `finally`, `while` of `do…while`) that belongs to the same control flow

SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenExtensions/ElementExtensions.cs

Lines changed: 219 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="UmlCorePocoValidationGeneratorTestFixture.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SysML2.NET.CodeGenerator.Tests.Generators.UmlHandleBarsGenerators
22+
{
23+
using System.IO;
24+
using System.Threading.Tasks;
25+
26+
using NUnit.Framework;
27+
28+
using SysML2.NET.CodeGenerator.Generators.UmlHandleBarsGenerators;
29+
30+
[TestFixture]
31+
public class UmlCorePocoValidationGeneratorTestFixture
32+
{
33+
private DirectoryInfo outputDirectory;
34+
private UmlCorePocoValidationGenerator generator;
35+
36+
[OneTimeSetUp]
37+
public void OneTimeSetup()
38+
{
39+
var directoryInfo = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
40+
41+
var path = Path.Combine("UML", "_SysML2.NET.AutoGenExtensions.ElementExtensions");
42+
43+
this.outputDirectory = directoryInfo.CreateSubdirectory(path);
44+
this.generator = new UmlCorePocoValidationGenerator();
45+
}
46+
47+
[Test]
48+
public async Task VerifyElementExtensionsAreGenerated()
49+
{
50+
await Assert.ThatAsync(
51+
() => this.generator.GenerateAsync(GeneratorSetupFixture.XmiReaderResult, this.outputDirectory),
52+
Throws.Nothing);
53+
}
54+
55+
[Test]
56+
[Category("Expected")]
57+
public async Task VerifyExpectedElementExtensionsMatches()
58+
{
59+
var generatedCode = await this.generator.GenerateElementExtensions(
60+
GeneratorSetupFixture.XmiReaderResult,
61+
this.outputDirectory);
62+
63+
var expected = await File.ReadAllTextAsync(Path.Combine(TestContext.CurrentContext.TestDirectory,
64+
"Expected/UML/Core/AutoGenExtensions/ElementExtensions.cs"));
65+
66+
Assert.That(generatedCode, Is.EqualTo(expected));
67+
}
68+
}
69+
}

SysML2.NET.CodeGenerator.Tests/SysML2.NET.CodeGenerator.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
<Compile Remove="Extensions\**" />
2020
<EmbeddedResource Remove="Extensions\**" />
2121
<None Remove="Extensions\**" />
22+
<Compile Remove="Expected\UML\Core\AutoGenExtensions\ElementExtensions.cs" />
2223
<Compile Remove="Expected\UML\Core\AutoGenReaders\AnnotatingElementReader.cs" />
24+
<None Include="Expected\UML\Core\AutoGenExtensions\ElementExtensions.cs">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
2327
<None Include="Expected\UML\Core\AutoGenReaders\AnnotatingElementReader.cs">
2428
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2529
</None>

0 commit comments

Comments
 (0)