mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-20 08:41:51 +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>
1060 lines
34 KiB
C#
1060 lines
34 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.Xml;
|
|
using NUnit.Framework;
|
|
|
|
namespace Opc.Ua.Schema.Model.Tests
|
|
{
|
|
/// <summary>
|
|
/// Unit tests for VariableDesign.Equals method
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("ModelDesign")]
|
|
[SetCulture("en-us")]
|
|
[SetUICulture("en-us")]
|
|
[Parallelizable]
|
|
public class VariableDesignTests
|
|
{
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with null.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_NullParameter_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign();
|
|
|
|
// Act
|
|
#pragma warning disable CA1508 // Avoid dead conditional code
|
|
bool result = variableDesign.Equals(null!);
|
|
#pragma warning restore CA1508 // Avoid dead conditional code
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when DefaultValue differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentDefaultValue_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var xmlDoc = new XmlDocument();
|
|
System.Xml.XmlElement defaultValue1 = xmlDoc.CreateElement("DefaultValue");
|
|
defaultValue1.InnerText = "TestValue1";
|
|
|
|
System.Xml.XmlElement defaultValue2 = xmlDoc.CreateElement("DefaultValue");
|
|
defaultValue2.InnerText = "TestValue2";
|
|
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DefaultValue = defaultValue1,
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DefaultValue = defaultValue2,
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when DataType differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentDataType_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType2", "http://test.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when DataType namespace differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentDataTypeNamespace_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test1.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test2.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when ArrayDimensions differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentArrayDimensions_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ArrayDimensions = "1,2,3"
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ArrayDimensions = "4,5,6"
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when MinimumSamplingInterval differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentMinimumSamplingInterval_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = 100
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = 200
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when MinimumSamplingIntervalSpecified differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentMinimumSamplingIntervalSpecified_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = 100,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = 100,
|
|
MinimumSamplingIntervalSpecified = false
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when Historizing differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentHistorizing_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
Historizing = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
Historizing = false
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when HistorizingSpecified differs.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentHistorizingSpecified_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
Historizing = true,
|
|
HistorizingSpecified = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
Historizing = true,
|
|
HistorizingSpecified = false
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals handles null DefaultValue correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_NullDefaultValue_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DefaultValue = null,
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com")
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DefaultValue = null,
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com")
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when one has null DefaultValue and the other does not.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_OneNullDefaultValue_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var xmlDoc = new XmlDocument();
|
|
System.Xml.XmlElement defaultValue = xmlDoc.CreateElement("DefaultValue");
|
|
defaultValue.InnerText = "TestValue";
|
|
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DefaultValue = defaultValue,
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com")
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DefaultValue = null,
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com")
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals handles null DataType correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_NullDataType_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = null,
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = null,
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when one has null DataType and the other does not.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_OneNullDataType_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = null,
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals handles null and empty ArrayDimensions correctly.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_NullArrayDimensions_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when ArrayDimensions is empty string vs null.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_EmptyVsNullArrayDimensions_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ArrayDimensions = string.Empty
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals with extreme MinimumSamplingInterval values.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_ExtremeMinimumSamplingInterval_ReturnsTrueForIdentical()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = int.MaxValue
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = int.MaxValue
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals with minimum MinimumSamplingInterval values.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_MinimumSamplingInterval_MinValue_ReturnsTrueForIdentical()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = int.MinValue
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = int.MinValue
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals with zero MinimumSamplingInterval.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_MinimumSamplingInterval_Zero_ReturnsTrueForIdentical()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = 0
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
DataType = new XmlQualifiedName("DataType1", "http://test.com"),
|
|
MinimumSamplingInterval = 0
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals(variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that GetHashCode works with all null reference properties.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_AllNullablePropertiesNull_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
DefaultValue = null,
|
|
DataType = null,
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with minimum MinimumSamplingInterval value.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_MinimumSamplingIntervalMinValue_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
MinimumSamplingInterval = int.MinValue,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with maximum MinimumSamplingInterval value.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_MinimumSamplingIntervalMaxValue_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
MinimumSamplingInterval = int.MaxValue,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with zero MinimumSamplingInterval value.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_MinimumSamplingIntervalZero_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
MinimumSamplingInterval = 0,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with all boolean "Specified" flags set to false.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_AllSpecifiedFlagsFalse_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
AccessLevelSpecified = false,
|
|
InstanceAccessLevelSpecified = false,
|
|
MinimumSamplingIntervalSpecified = false,
|
|
HistorizingSpecified = false
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with all boolean "Specified" flags set to true.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_AllSpecifiedFlagsTrue_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
AccessLevelSpecified = true,
|
|
InstanceAccessLevelSpecified = true,
|
|
MinimumSamplingIntervalSpecified = true,
|
|
HistorizingSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with Historizing set to true.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_HistorizingTrue_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
Historizing = true,
|
|
HistorizingSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with Historizing set to false.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_HistorizingFalse_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
Historizing = false,
|
|
HistorizingSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with empty string ArrayDimensions.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_EmptyArrayDimensions_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
ArrayDimensions = string.Empty
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with whitespace-only ArrayDimensions.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_WhitespaceArrayDimensions_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
ArrayDimensions = " "
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with very long ArrayDimensions string.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_VeryLongArrayDimensions_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
ArrayDimensions = new string('1', 10000)
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests GetHashCode with negative MinimumSamplingInterval.
|
|
/// </summary>
|
|
[Test]
|
|
public void GetHashCode_NegativeMinimumSamplingInterval_DoesNotThrow()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
MinimumSamplingInterval = -1000,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrow(() => variableDesign.GetHashCode());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with null object.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_NullObject_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign();
|
|
|
|
// Act
|
|
#pragma warning disable CA1508 // Avoid dead conditional code
|
|
bool result = variableDesign.Equals((object)null!);
|
|
#pragma warning restore CA1508 // Avoid dead conditional code
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with a different VariableDesign instance with different DataType.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentInstanceWithDifferentDataType_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
DataType = new XmlQualifiedName("Int32", "http://opcfoundation.org/UA/"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
DataType = new XmlQualifiedName("String", "http://opcfoundation.org/UA/"),
|
|
ValueRank = ValueRank.Scalar
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with a different VariableDesign instance with different ArrayDimensions.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentInstanceWithDifferentArrayDimensions_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
DataType = new XmlQualifiedName("Int32", "http://opcfoundation.org/UA/"),
|
|
ArrayDimensions = "1,2,3"
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
DataType = new XmlQualifiedName("Int32", "http://opcfoundation.org/UA/"),
|
|
ArrayDimensions = "1,2"
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with a different VariableDesign instance with different Historizing.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentInstanceWithDifferentHistorizing_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
Historizing = true,
|
|
HistorizingSpecified = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
Historizing = false,
|
|
HistorizingSpecified = true
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with a different VariableDesign instance with different MinimumSamplingInterval.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentInstanceWithDifferentMinimumSamplingInterval_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
MinimumSamplingInterval = 1000,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
MinimumSamplingInterval = 2000,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with an object of a completely different type.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentType_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org")
|
|
};
|
|
object differentObject = new();
|
|
|
|
// Act
|
|
bool result = variableDesign.Equals(differentObject);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with a string object.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_StringObject_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org")
|
|
};
|
|
const string stringObject = "TestVariable";
|
|
|
|
// Act
|
|
bool result = variableDesign.Equals(stringObject);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with an InstanceDesign object (base type).
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_BaseTypeInstanceDesign_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable1", "http://test.org")
|
|
};
|
|
var instanceDesign = new PropertyDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable2", "http://test.org")
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign.Equals((object)instanceDesign);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when comparing with a VariableDesign having different SymbolicName.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_DifferentSymbolicName_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("Variable1", "http://test.org")
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("Variable2", "http://test.org")
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns true when comparing two VariableDesign instances with null ArrayDimensions.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_BothNullArrayDimensions_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var symbolicName = new XmlQualifiedName("TestVariable", "http://test.org");
|
|
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = symbolicName,
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName(symbolicName.Name, symbolicName.Namespace),
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns false when one VariableDesign has null ArrayDimensions and the other has non-null.
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_OneNullArrayDimensionsOneNonNull_ReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
ArrayDimensions = null
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName("TestVariable", "http://test.org"),
|
|
ArrayDimensions = "1,2,3"
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.False);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns true when MinimumSamplingInterval values are at boundary (int.MaxValue).
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_MinimumSamplingIntervalMaxValue_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var symbolicName = new XmlQualifiedName("TestVariable", "http://test.org");
|
|
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = symbolicName,
|
|
MinimumSamplingInterval = int.MaxValue,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName(symbolicName.Name, symbolicName.Namespace),
|
|
MinimumSamplingInterval = int.MaxValue,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that Equals returns true when MinimumSamplingInterval values are at boundary (int.MinValue).
|
|
/// </summary>
|
|
[Test]
|
|
public void Equals_MinimumSamplingIntervalMinValue_ReturnsTrue()
|
|
{
|
|
// Arrange
|
|
var symbolicName = new XmlQualifiedName("TestVariable", "http://test.org");
|
|
|
|
var variableDesign1 = new VariableDesign
|
|
{
|
|
SymbolicName = symbolicName,
|
|
MinimumSamplingInterval = int.MinValue,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
var variableDesign2 = new VariableDesign
|
|
{
|
|
SymbolicName = new XmlQualifiedName(symbolicName.Name, symbolicName.Namespace),
|
|
MinimumSamplingInterval = int.MinValue,
|
|
MinimumSamplingIntervalSpecified = true
|
|
};
|
|
|
|
// Act
|
|
bool result = variableDesign1.Equals((object)variableDesign2);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.True);
|
|
}
|
|
}
|
|
}
|