mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-19 15:22:15 +08:00
9b034f8291
# Description Nullable reference types are now enabled once, in `common.props`, and every project in the repository builds warning-clean with them. **Configuration** - `<Nullable>enable</Nullable>` lives in `common.props`. All per-project `<Nullable>` settings are removed: 178 project files (enable, annotations, and the `disable` in the three Aot test projects). - 419 per-file `#nullable enable`/`restore` directives and the 4 `#nullable disable` directives are removed. - Kept on purpose: - The 5 `<auto-generated>` schema files (`UANodeSet.cs`, `UA Type Dictionary.cs`, `OPCBinarySchema.cs`, `SecuredApplication.cs`, `PInvokeHelper.cs`) keep `#nullable enable`. The compiler ignores the project setting in generated code, so the directive is required there. - `tests/Opc.Ua.Interop.LegacyPeer` keeps `disable`. It builds against the 1.5.378 packages and does not import the repository props. - `docs/DeveloperGuide.md` and `.github/copilot-instructions.md` now describe the central setting. **Migration** (the 43 unset and 13 annotations-only projects, roughly 10k diagnostics) - **Production code: annotated at the declarations.** Covers `tools/Opc.Ua.SourceGeneration.Core`, `src/Opc.Ua.Lds.Server` and the LDS sample. - Members, parameters and returns are nullable where null actually flows. - Null-check helpers carry `[NotNullWhen]` (`IsNull`, `IsValidXmlName`, `IsMethodTypeDesign`). - `CoreUtils.Format`, `Utils.Format`, `ITemplateWriter.WriteLine` take `params object?[]`. `Template.AddReplacement` takes `string?` (rendering already skips null replacements). - `IRegisteredServerStore.RegisterAsync` returns `Task<RegistrationEntry?>`: it returns null when a registration is removed. - Dereferences backed by an invariant (for example, the validated model) use `!`, so runtime behaviour is unchanged. - **Behavioural changes in production code** (small, deliberate): - `NodeSetToModelDesign` throws `InvalidOperationException` when the file is not a NodeSet. Before, it threw a NullReferenceException on the next line. - `ModelDesignValidator` starts its lookup tables empty instead of null. A redundant `if (m_nodes == null) return;` guard is gone. - **Test code: minimal annotations.** - `?` on values that can be null, `!` where the test asserts non-null. - `= null!` for fixture members assigned in SetUp. - `TryGetStructure<T>(out T? x)` where the inferred `T?` broke the `IEncodeable` constraint. - A few redundant `== null` checks on structs (`NodeId`, `ArrayOf<T>`) folded into the adjacent `IsNull`/`Count` checks. **Notes for reviewers** - The diff is large (~1,500 files) but almost entirely mechanical: `?`, `!` and directive removal. The non-annotation changes are listed above. - Known follow-up, not done here: `IModelDesign.Namespaces/TargetNamespace/NamespaceUris` stay non-nullable even though the validator returns null before it loads a dictionary. Making them nullable would ripple through every generator call site. ## Related Issues - Fixes #4439 ## Checklist - [ ] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [ ] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [ ] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [ ] I have addressed **all** PR feedback received. The "no new warnings" box covers net10.0 and net48: full non-incremental builds of `UA.slnx`, `tools/SourceGeneration.slnx`, `tools/MigrationAnalyzer.slnx` and the Aot test projects finished with 0 warnings and 0 errors under the repository's warnings-as-errors settings. net9.0 and net8.0 also had no nullable diagnostics, but they were not rebuilt after the final fixes. Tests have not been run locally yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
632 lines
24 KiB
C#
632 lines
24 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
|
|
namespace Opc.Ua.SourceGeneration.Api.Tests
|
|
{
|
|
/// <summary>
|
|
/// Unit tests for <see cref = "DesignFileExtensions"/> class.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("Api")]
|
|
[SetCulture("en-us")]
|
|
[SetUICulture("en-us")]
|
|
[Parallelizable]
|
|
public class DesignFileExtensionsTests
|
|
{
|
|
/// <summary>
|
|
/// Tests that Group throws ArgumentNullException when collection parameter is null.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_NullCollection_ThrowsArgumentNullException()
|
|
{
|
|
// Arrange
|
|
DesignFileCollection? collection = null;
|
|
// Act & Assert
|
|
Assert.Throws<ArgumentNullException>(() => collection!.Group().ToList());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group throws NullReferenceException when DesignFiles property is null.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_NullDesignFiles_ThrowsArgumentNullException()
|
|
{
|
|
// Arrange
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = null!,
|
|
IdentifierFilePath = null!,
|
|
Options = null!
|
|
};
|
|
// Act & Assert
|
|
Assert.Throws<ArgumentNullException>(() => collection.Group().ToList());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group returns empty enumerable when DesignFiles is empty.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_EmptyDesignFiles_ReturnsEmptyEnumerable()
|
|
{
|
|
// Arrange
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = [],
|
|
IdentifierFilePath = null!,
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group returns single group with one file when DesignFiles contains single file.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_SingleDesignFile_ReturnsSingleGroup()
|
|
{
|
|
// Arrange
|
|
string designFile = Path.Combine("C:", "TestDir", "Design1.xml");
|
|
var options = new DesignFileOptions
|
|
{
|
|
Version = "v105"
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets =
|
|
[
|
|
designFile
|
|
],
|
|
IdentifierFilePath = "global.csv",
|
|
Options = options
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].Targets, Is.Not.Null);
|
|
Assert.That(result[0].Targets, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].Targets[0], Is.EqualTo(designFile));
|
|
Assert.That(result[0].IdentifierFilePath, Is.EqualTo("global.csv"));
|
|
Assert.That(result[0].Options, Is.EqualTo(options));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group returns one generation unit per design file when
|
|
/// multiple targets share a directory.
|
|
/// </summary>
|
|
[Test]
|
|
public void GroupMultipleFilesInSameDirectoryReturnsOneGroupPerTarget()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml"),
|
|
Path.Combine(dir, "Design2.xml"),
|
|
Path.Combine(dir, "Design3.xml")
|
|
};
|
|
var options = new DesignFileOptions
|
|
{
|
|
Version = "v104"
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "fallback.csv",
|
|
Options = options
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(3));
|
|
Assert.That(result.SelectMany(group => group.Targets), Is.EquivalentTo(designFiles));
|
|
foreach (DesignFileCollection group in result)
|
|
{
|
|
Assert.That(group.Targets, Has.Count.EqualTo(1));
|
|
Assert.That(group.Dependencies, Has.Count.EqualTo(2));
|
|
Assert.That(group.Dependencies, Does.Not.Contain(group.Targets[0]));
|
|
Assert.That(group.IdentifierFilePath, Is.EqualTo("fallback.csv"));
|
|
Assert.That(group.Options, Is.EqualTo(options));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group returns multiple groups when design files are in different directories.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_FilesInDifferentDirectories_ReturnsMultipleGroups()
|
|
{
|
|
// Arrange
|
|
string dir1 = Path.Combine("C:", "Dir1");
|
|
string dir2 = Path.Combine("C:", "Dir2");
|
|
string dir3 = Path.Combine("C:", "Dir3");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir1, "Design1.xml"),
|
|
Path.Combine(dir2, "Design2.xml"),
|
|
Path.Combine(dir3, "Design3.xml")
|
|
};
|
|
var options = new DesignFileOptions
|
|
{
|
|
StartId = 1000
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "default.csv",
|
|
Options = options
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(3));
|
|
foreach (DesignFileCollection group in result)
|
|
{
|
|
Assert.That(group.Targets, Is.Not.Null);
|
|
Assert.That(group.Targets, Has.Count.EqualTo(1));
|
|
Assert.That(group.IdentifierFilePath, Is.EqualTo("default.csv"));
|
|
Assert.That(group.Options, Is.EqualTo(options));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group uses collection's IdentifierFilePath when identifierFiles parameter is null.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_NullIdentifierFilesParameter_UsesCollectionIdentifierFilePath()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "collection_identifier.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group(null!).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].IdentifierFilePath, Is.EqualTo("collection_identifier.csv"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group uses collection's IdentifierFilePath when identifierFiles parameter is empty.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_EmptyIdentifierFilesList_UsesCollectionIdentifierFilePath()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "fallback.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group([]).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].IdentifierFilePath, Is.EqualTo("fallback.csv"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group assigns an identifier file by matching the target
|
|
/// base name, even when several models share a directory.
|
|
/// </summary>
|
|
[Test]
|
|
public void GroupBasenameIdentifierFilesAssignsEachTarget()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml"),
|
|
Path.Combine(dir, "Design2.xml")
|
|
};
|
|
var identifierFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.csv"),
|
|
Path.Combine(dir, "Design2.CSV")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "fallback.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group(identifierFiles).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(2));
|
|
Assert.That(
|
|
result.Single(group => group.Targets[0].EndsWith("Design1.xml", StringComparison.Ordinal))
|
|
.IdentifierFilePath,
|
|
Is.EqualTo(Path.Combine(dir, "Design1.csv")));
|
|
Assert.That(
|
|
result.Single(group => group.Targets[0].EndsWith("Design2.xml", StringComparison.Ordinal))
|
|
.IdentifierFilePath,
|
|
Is.EqualTo(Path.Combine(dir, "Design2.CSV")));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that the legacy single-model case continues to use the only
|
|
/// adjacent identifier file even when its basename differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void GroupSingleTargetWithNonBasenameIdentifierUsesAdjacentFile()
|
|
{
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
string target = Path.Combine(dir, "Design.xml");
|
|
string identifierFile = Path.Combine(dir, "LegacyIdentifiers.csv");
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = [target],
|
|
IdentifierFilePath = "fallback.csv"
|
|
};
|
|
|
|
DesignFileCollection result = collection
|
|
.Group([identifierFile])
|
|
.Single();
|
|
|
|
Assert.That(result.IdentifierFilePath, Is.EqualTo(identifierFile));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that each single-model directory preserves its legacy
|
|
/// non-basename identifier file in a multi-directory collection.
|
|
/// </summary>
|
|
[Test]
|
|
public void GroupMultipleSingleTargetDirectoriesUseAdjacentLegacyFiles()
|
|
{
|
|
string dir1 = Path.Combine("C:", "Dir1");
|
|
string dir2 = Path.Combine("C:", "Dir2");
|
|
string target1 = Path.Combine(dir1, "Model1.xml");
|
|
string target2 = Path.Combine(dir2, "Model2.xml");
|
|
string identifier1 = Path.Combine(dir1, "Identifiers.csv");
|
|
string identifier2 = Path.Combine(dir2, "Identifiers.csv");
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = [target1, target2],
|
|
IdentifierFilePath = "fallback.csv"
|
|
};
|
|
|
|
List<DesignFileCollection> result = collection
|
|
.Group([identifier1, identifier2])
|
|
.ToList();
|
|
|
|
Assert.That(
|
|
result.Single(group => group.Targets[0] == target1).IdentifierFilePath,
|
|
Is.EqualTo(identifier1));
|
|
Assert.That(
|
|
result.Single(group => group.Targets[0] == target2).IdentifierFilePath,
|
|
Is.EqualTo(identifier2));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that unrelated identifier files in the same directory are
|
|
/// ignored in favour of the target's basename match.
|
|
/// </summary>
|
|
[Test]
|
|
public void GroupMultipleIdentifierFilesInSameDirectoryUsesBasenameMatch()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design2.xml")
|
|
};
|
|
var identifierFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "identifiers1.csv"),
|
|
Path.Combine(dir, "Design2.csv"),
|
|
Path.Combine(dir, "identifiers3.csv")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "fallback.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group(identifierFiles).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].IdentifierFilePath, Is.EqualTo(Path.Combine(dir, "Design2.csv")));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group uses collection's IdentifierFilePath when identifier files are in non-matching directories.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_IdentifierFilesInNonMatchingDirectories_UsesCollectionIdentifierFilePath()
|
|
{
|
|
// Arrange
|
|
string designDir = Path.Combine("C:", "DesignDir");
|
|
string idDir = Path.Combine("C:", "IdentifierDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(designDir, "Design1.xml")
|
|
};
|
|
var identifierFiles = new List<string>
|
|
{
|
|
Path.Combine(idDir, "identifiers.csv")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "fallback.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group(identifierFiles).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].IdentifierFilePath, Is.EqualTo("fallback.csv"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group correctly maps identifier files to their respective directories when multiple directories exist.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_MultipleDirectoriesWithIdentifierFiles_CorrectlyMapsIdentifierFiles()
|
|
{
|
|
// Arrange
|
|
string dir1 = Path.Combine("C:", "Dir1");
|
|
string dir2 = Path.Combine("C:", "Dir2");
|
|
string dir3 = Path.Combine("C:", "Dir3");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir1, "Design1.xml"),
|
|
Path.Combine(dir2, "Design2.xml"),
|
|
Path.Combine(dir3, "Design3.xml")
|
|
};
|
|
var identifierFiles = new List<string>
|
|
{
|
|
Path.Combine(dir1, "Design1.csv"),
|
|
Path.Combine(dir3, "Design3.csv")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "fallback.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group(identifierFiles).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(3));
|
|
DesignFileCollection group1 = result.FirstOrDefault(g => g.Targets.Contains(Path.Combine(dir1, "Design1.xml")))!;
|
|
Assert.That(group1, Is.Not.Null);
|
|
Assert.That(group1.IdentifierFilePath, Is.EqualTo(Path.Combine(dir1, "Design1.csv")));
|
|
DesignFileCollection group2 = result.FirstOrDefault(g => g.Targets.Contains(Path.Combine(dir2, "Design2.xml")))!;
|
|
Assert.That(group2, Is.Not.Null);
|
|
Assert.That(group2.IdentifierFilePath, Is.EqualTo("fallback.csv"));
|
|
DesignFileCollection group3 = result.FirstOrDefault(g => g.Targets.Contains(Path.Combine(dir3, "Design3.xml")))!;
|
|
Assert.That(group3, Is.Not.Null);
|
|
Assert.That(group3.IdentifierFilePath, Is.EqualTo(Path.Combine(dir3, "Design3.csv")));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group handles complex scenario with mixed directories, multiple files, and partial identifier file coverage.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_ComplexScenario_CorrectlyGroupsAndAssignsIdentifierFiles()
|
|
{
|
|
// Arrange
|
|
string dir1 = Path.Combine("C:", "Project", "Dir1");
|
|
string dir2 = Path.Combine("C:", "Project", "Dir2");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir1, "DesignA.xml"),
|
|
Path.Combine(dir1, "DesignB.xml"),
|
|
Path.Combine(dir2, "DesignC.xml"),
|
|
Path.Combine(dir2, "DesignD.xml"),
|
|
Path.Combine(dir2, "DesignE.xml")
|
|
};
|
|
var identifierFiles = new List<string>
|
|
{
|
|
Path.Combine(dir2, "DesignC.csv")
|
|
};
|
|
var options = new DesignFileOptions
|
|
{
|
|
Version = "v105",
|
|
StartId = 5000,
|
|
ModelVersion = "1.0.0"
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "global_fallback.csv",
|
|
Options = options
|
|
};
|
|
// Act
|
|
var result = collection.Group(identifierFiles).ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(5));
|
|
DesignFileCollection group1 = result.FirstOrDefault(g => g.Targets.Contains(Path.Combine(dir1, "DesignA.xml")))!;
|
|
Assert.That(group1, Is.Not.Null);
|
|
Assert.That(group1.Targets, Has.Count.EqualTo(1));
|
|
Assert.That(group1.IdentifierFilePath, Is.EqualTo("global_fallback.csv"));
|
|
Assert.That(group1.Options, Is.EqualTo(options));
|
|
DesignFileCollection group2 = result.FirstOrDefault(g => g.Targets.Contains(Path.Combine(dir2, "DesignC.xml")))!;
|
|
Assert.That(group2, Is.Not.Null);
|
|
Assert.That(group2.Targets, Has.Count.EqualTo(1));
|
|
Assert.That(group2.IdentifierFilePath, Is.EqualTo(Path.Combine(dir2, "DesignC.csv")));
|
|
Assert.That(group2.Options, Is.EqualTo(options));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group handles null collection IdentifierFilePath correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_NullCollectionIdentifierFilePath_ReturnsNullIdentifierFilePath()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = null!,
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].IdentifierFilePath, Is.Null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group handles empty string collection IdentifierFilePath correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_EmptyStringCollectionIdentifierFilePath_ReturnsEmptyIdentifierFilePath()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = string.Empty,
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].IdentifierFilePath, Is.EqualTo(string.Empty));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group handles design files with relative paths correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void GroupDesignFilesWithRelativePathsEmitsEachTarget()
|
|
{
|
|
// Arrange
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine("SubDir1", "Design1.xml"),
|
|
Path.Combine("SubDir1", "Design2.xml"),
|
|
Path.Combine("SubDir2", "Design3.xml")
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "default.csv",
|
|
Options = null!
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(3));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Group preserves all DesignFileOptions properties correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void Group_WithCompleteOptions_PreservesAllOptionProperties()
|
|
{
|
|
// Arrange
|
|
string dir = Path.Combine("C:", "TestDir");
|
|
var designFiles = new List<string>
|
|
{
|
|
Path.Combine(dir, "Design1.xml")
|
|
};
|
|
var options = new DesignFileOptions
|
|
{
|
|
Version = "v105",
|
|
StartId = 10000,
|
|
ModelVersion = "2.3.4",
|
|
ModelPublicationDate = "2025-01-01",
|
|
ReleaseCandidate = false
|
|
};
|
|
var collection = new DesignFileCollection
|
|
{
|
|
Targets = designFiles,
|
|
IdentifierFilePath = "test.csv",
|
|
Options = options
|
|
};
|
|
// Act
|
|
var result = collection.Group().ToList();
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].Options, Is.EqualTo(options));
|
|
Assert.That(result[0].Options.Version, Is.EqualTo("v105"));
|
|
Assert.That(result[0].Options.StartId, Is.EqualTo(10000));
|
|
Assert.That(result[0].Options.ModelVersion, Is.EqualTo("2.3.4"));
|
|
Assert.That(result[0].Options.ModelPublicationDate, Is.EqualTo("2025-01-01"));
|
|
Assert.That(result[0].Options.ReleaseCandidate, Is.False);
|
|
}
|
|
}
|
|
}
|