/* ======================================================================== * 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 NUnit.Framework; namespace Opc.Ua.Schema.Model.Tests { /// /// Unit tests for the class Equals method. /// [TestFixture] [Category("ModelDesign")] [SetCulture("en-us")] [SetUICulture("en-us")] [Parallelizable] public class LocalizedTextTests { /// /// Tests that Equals returns false when comparing with null. /// [Test] public void Equals_NullOther_ReturnsFalse() { // Arrange var localizedText = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act #pragma warning disable CA1508 // Avoid dead conditional code bool result = localizedText.Equals(null!); #pragma warning restore CA1508 // Avoid dead conditional code // Assert Assert.That(result, Is.False); } /// /// Tests that Equals returns true when comparing an instance with itself. /// [Test] public void Equals_SameInstance_ReturnsTrue() { // Arrange var localizedText = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText.Equals(localizedText); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals returns true when comparing two instances with identical property values. /// [Test] public void Equals_IdenticalValues_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals returns false when the Key property differs. /// [Test] public void Equals_DifferentKey_ReturnsFalse() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key2", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals returns false when the DoNotIgnore property differs. /// [Test] public void Equals_DifferentDoNotIgnore_ReturnsFalse() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = false, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals returns false when the Value property differs. /// [Test] public void Equals_DifferentValue_ReturnsFalse() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value2", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals returns false when the IsAutogenerated property differs. /// [Test] public void Equals_DifferentIsAutogenerated_ReturnsFalse() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = true }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals handles null Key values correctly. /// Verifies that two instances with null Key values are equal if all other properties match. /// [Test] public void Equals_NullKeyInBoth_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = null, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = null, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals returns false when one instance has null Key and the other has a non-null Key. /// [Test] public void Equals_NullKeyInOneInstance_ReturnsFalse() { // Arrange var localizedText1 = new LocalizedText { Key = null, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals handles null Value correctly. /// Verifies that two instances with null Value are equal if all other properties match. /// [Test] public void Equals_NullValueInBoth_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = null, IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = null, IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals returns false when one instance has null Value and the other has a non-null Value. /// [Test] public void Equals_NullValueInOneInstance_ReturnsFalse() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = null, IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals handles empty string Key values correctly. /// Verifies that two instances with empty Key values are equal if all other properties match. /// [Test] public void Equals_EmptyKeyInBoth_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = string.Empty, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = string.Empty, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals handles empty string Value correctly. /// Verifies that two instances with empty Value are equal if all other properties match. /// [Test] public void Equals_EmptyValueInBoth_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = string.Empty, IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = string.Empty, IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals handles whitespace string values correctly in Key property. /// Verifies that whitespace is considered a distinct value from empty or other whitespace patterns. /// [Test] public void Equals_WhitespaceKeyInBoth_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = " ", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = " ", DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals handles whitespace string values correctly in Value property. /// Verifies that whitespace is considered a distinct value from empty or other whitespace patterns. /// [Test] public void Equals_WhitespaceValueInBoth_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = " ", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = " ", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals handles special characters in string properties correctly. /// Verifies that special characters are properly compared. /// [Test] public void Equals_SpecialCharactersInStrings_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key\t\r\n\\!@#$%^&*()", DoNotIgnore = true, Value = "value\t\r\n\\!@#$%^&*()", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key\t\r\n\\!@#$%^&*()", DoNotIgnore = true, Value = "value\t\r\n\\!@#$%^&*()", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals correctly compares instances with default constructor values. /// The default constructor initializes Key to "" and DoNotIgnore to false. /// [Test] public void Equals_DefaultConstructorValues_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText(); var localizedText2 = new LocalizedText(); // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals correctly handles instances with all boolean combinations. /// Verifies equality with both DoNotIgnore and IsAutogenerated set to true. /// [Test] public void Equals_BothBooleanPropertiesTrue_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = true }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = true, Value = "value1", IsAutogenerated = true }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals correctly handles instances with all properties set to false. /// Verifies equality with both DoNotIgnore and IsAutogenerated set to false. /// [Test] public void Equals_BothBooleanPropertiesFalse_ReturnsTrue() { // Arrange var localizedText1 = new LocalizedText { Key = "key1", DoNotIgnore = false, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "key1", DoNotIgnore = false, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals handles very long string values correctly. /// Verifies that string comparison works properly with large strings. /// [Test] public void Equals_VeryLongStrings_ReturnsTrue() { // Arrange string longString = new('a', 10000); var localizedText1 = new LocalizedText { Key = longString, DoNotIgnore = true, Value = longString, IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = longString, DoNotIgnore = true, Value = longString, IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals returns false when comparing very long strings that differ. /// Verifies that string comparison correctly identifies differences in large strings. /// [Test] public void Equals_VeryLongStringsDifferent_ReturnsFalse() { // Arrange string longString1 = new('a', 10000); string longString2 = new('b', 10000); var localizedText1 = new LocalizedText { Key = longString1, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = longString2, DoNotIgnore = true, Value = "value1", IsAutogenerated = false }; // Act bool result = localizedText1.Equals(localizedText2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals(object) returns false when parameter is null. /// Verifies null handling in object overload. /// Expected result: false. /// [Test] public void Equals_NullObject_ReturnsFalse() { // Arrange var text = new LocalizedText { Key = "testKey", Value = "testValue" }; // Act #pragma warning disable CA1508 // Avoid dead conditional code bool result = text.Equals((object)null!); #pragma warning restore CA1508 // Avoid dead conditional code // Assert Assert.That(result, Is.False); } /// /// Tests that Equals(object) returns false when parameter is of different type. /// Verifies type checking via 'as' operator cast. /// Expected result: false. /// [Test] public void Equals_DifferentType_ReturnsFalse() { // Arrange var text = new LocalizedText { Key = "testKey", Value = "testValue" }; object differentType = "string object"; // Act bool result = text.Equals(differentType); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals(object) returns true when comparing two instances with identical property values. /// Verifies value-based equality comparison. /// Expected result: true. /// [Test] public void Equals_EqualInstances_ReturnsTrue() { // Arrange var text1 = new LocalizedText { Key = "testKey", DoNotIgnore = true, Value = "testValue", IsAutogenerated = false }; var text2 = new LocalizedText { Key = "testKey", DoNotIgnore = true, Value = "testValue", IsAutogenerated = false }; // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals(object) returns true when both instances have null Value and other properties are equal. /// Verifies null value handling in equality comparison. /// Expected result: true. /// [Test] public void Equals_BothNullValue_ReturnsTrue() { // Arrange var text1 = new LocalizedText { Key = "testKey", DoNotIgnore = true, Value = null, IsAutogenerated = false }; var text2 = new LocalizedText { Key = "testKey", DoNotIgnore = true, Value = null, IsAutogenerated = false }; // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals(object) returns false when one instance has null Value and the other does not. /// Verifies null vs non-null value comparison. /// Expected result: false. /// [Test] public void Equals_OneNullValue_ReturnsFalse() { // Arrange var text1 = new LocalizedText { Key = "testKey", DoNotIgnore = true, Value = null, IsAutogenerated = false }; var text2 = new LocalizedText { Key = "testKey", DoNotIgnore = true, Value = "testValue", IsAutogenerated = false }; // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals(object) returns true when comparing instances with empty string Key and Value. /// Verifies handling of empty strings in equality comparison. /// Expected result: true. /// [Test] public void Equals_EmptyStrings_ReturnsTrue() { // Arrange var text1 = new LocalizedText { Key = string.Empty, DoNotIgnore = false, Value = string.Empty, IsAutogenerated = false }; var text2 = new LocalizedText { Key = string.Empty, DoNotIgnore = false, Value = string.Empty, IsAutogenerated = false }; // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals(object) returns true when comparing default-initialized instances. /// Verifies equality comparison with default property values. /// Expected result: true. /// [Test] public void Equals_DefaultInstances_ReturnsTrue() { // Arrange var text1 = new LocalizedText(); var text2 = new LocalizedText(); // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.True); } /// /// Tests that Equals(object) returns false when Key differs by whitespace. /// Verifies that whitespace differences are detected. /// Expected result: false. /// [Test] public void Equals_KeyDiffersByWhitespace_ReturnsFalse() { // Arrange var text1 = new LocalizedText { Key = "testKey", DoNotIgnore = false, Value = "testValue", IsAutogenerated = false }; var text2 = new LocalizedText { Key = "testKey ", DoNotIgnore = false, Value = "testValue", IsAutogenerated = false }; // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.False); } /// /// Tests that Equals(object) returns false when Value differs by case. /// Verifies that string comparison is case-sensitive. /// Expected result: false. /// [Test] public void Equals_ValueDiffersByCase_ReturnsFalse() { // Arrange var text1 = new LocalizedText { Key = "testKey", DoNotIgnore = false, Value = "TestValue", IsAutogenerated = false }; var text2 = new LocalizedText { Key = "testKey", DoNotIgnore = false, Value = "testvalue", IsAutogenerated = false }; // Act bool result = text1.Equals((object)text2); // Assert Assert.That(result, Is.False); } /// /// Tests that GetHashCode returns consistent value across multiple invocations for the same object. /// Input: LocalizedText with all properties set to default values. /// Expected: Hash code remains consistent. /// [Test] public void GetHashCode_ConsistentInvocations_ReturnsSameHashCode() { // Arrange var localizedText = new LocalizedText { Key = "TestKey", DoNotIgnore = true, Value = "TestValue", IsAutogenerated = false }; // Act int hashCode1 = localizedText.GetHashCode(); int hashCode2 = localizedText.GetHashCode(); // Assert Assert.That(hashCode2, Is.EqualTo(hashCode1)); } /// /// Tests that equal objects produce equal hash codes. /// Input: Two LocalizedText instances with identical property values. /// Expected: Both objects return the same hash code. /// [Test] public void GetHashCode_EqualObjects_ReturnsSameHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = "TestKey", DoNotIgnore = true, Value = "TestValue", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "TestKey", DoNotIgnore = true, Value = "TestValue", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.EqualTo(hashCode1)); } /// /// Tests that different Key values produce different hash codes. /// Input: Two LocalizedText instances differing only in Key property. /// Expected: Different hash codes are returned. /// [Test] public void GetHashCode_DifferentKey_ReturnsDifferentHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = "Key1", DoNotIgnore = false, Value = "Value", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "Key2", DoNotIgnore = false, Value = "Value", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.Not.EqualTo(hashCode1)); } /// /// Tests that different DoNotIgnore values produce different hash codes. /// Input: Two LocalizedText instances differing only in DoNotIgnore property. /// Expected: Different hash codes are returned. /// [Test] public void GetHashCode_DifferentDoNotIgnore_ReturnsDifferentHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = "TestKey", DoNotIgnore = true, Value = "TestValue", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "TestKey", DoNotIgnore = false, Value = "TestValue", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.Not.EqualTo(hashCode1)); } /// /// Tests that different Value values produce different hash codes. /// Input: Two LocalizedText instances differing only in Value property. /// Expected: Different hash codes are returned. /// [Test] public void GetHashCode_DifferentValue_ReturnsDifferentHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = "TestKey", DoNotIgnore = false, Value = "Value1", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "TestKey", DoNotIgnore = false, Value = "Value2", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.Not.EqualTo(hashCode1)); } /// /// Tests that different IsAutogenerated values produce different hash codes. /// Input: Two LocalizedText instances differing only in IsAutogenerated property. /// Expected: Different hash codes are returned. /// [Test] public void GetHashCode_DifferentIsAutogenerated_ReturnsDifferentHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = "TestKey", DoNotIgnore = false, Value = "TestValue", IsAutogenerated = true }; var localizedText2 = new LocalizedText { Key = "TestKey", DoNotIgnore = false, Value = "TestValue", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.Not.EqualTo(hashCode1)); } /// /// Tests GetHashCode with null Key value. /// Input: LocalizedText with Key set to null. /// Expected: Hash code is computed without throwing exception. /// [Test] public void GetHashCode_NullKey_ReturnsHashCode() { // Arrange var localizedText = new LocalizedText { Key = null, DoNotIgnore = false, Value = "TestValue", IsAutogenerated = false }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests GetHashCode with null Value. /// Input: LocalizedText with Value set to null. /// Expected: Hash code is computed without throwing exception. /// [Test] public void GetHashCode_NullValue_ReturnsHashCode() { // Arrange var localizedText = new LocalizedText { Key = "TestKey", DoNotIgnore = false, Value = null, IsAutogenerated = false }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests GetHashCode with all null string properties. /// Input: LocalizedText with Key and Value set to null. /// Expected: Hash code is computed without throwing exception. /// [Test] public void GetHashCode_AllNullStrings_ReturnsHashCode() { // Arrange var localizedText = new LocalizedText { Key = null, DoNotIgnore = false, Value = null, IsAutogenerated = false }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests GetHashCode with empty string properties. /// Input: LocalizedText with Key and Value set to empty strings. /// Expected: Hash code is computed correctly. /// [Test] public void GetHashCode_EmptyStrings_ReturnsHashCode() { // Arrange var localizedText = new LocalizedText { Key = string.Empty, DoNotIgnore = false, Value = string.Empty, IsAutogenerated = false }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests GetHashCode with whitespace string properties. /// Input: LocalizedText with Key and Value set to whitespace strings. /// Expected: Hash code is computed correctly. /// [Test] public void GetHashCode_WhitespaceStrings_ReturnsHashCode() { // Arrange var localizedText = new LocalizedText { Key = " ", DoNotIgnore = false, Value = " ", IsAutogenerated = false }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests GetHashCode with very long string properties. /// Input: LocalizedText with Key and Value set to very long strings. /// Expected: Hash code is computed correctly. /// [Test] public void GetHashCode_VeryLongStrings_ReturnsHashCode() { // Arrange string longString = new('A', 10000); var localizedText = new LocalizedText { Key = longString, DoNotIgnore = true, Value = longString, IsAutogenerated = true }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests GetHashCode with special characters in string properties. /// Input: LocalizedText with Key and Value containing special characters. /// Expected: Hash code is computed correctly. /// [Test] public void GetHashCode_SpecialCharacters_ReturnsHashCode() { // Arrange var localizedText = new LocalizedText { Key = "Test\nKey\r\n\t", DoNotIgnore = false, Value = "Value\0\x01\x1F", IsAutogenerated = false }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests that two LocalizedText instances with different combinations of boolean properties produce different hash codes. /// Input: Multiple LocalizedText instances with different boolean property combinations. /// Expected: Different hash codes for different boolean combinations. /// [TestCase(false, false, TestName = "GetHashCode_BooleanCombination_FalseFalse")] [TestCase(false, true, TestName = "GetHashCode_BooleanCombination_FalseTrue")] [TestCase(true, false, TestName = "GetHashCode_BooleanCombination_TrueTrue")] [TestCase(true, true, TestName = "GetHashCode_BooleanCombination_TrueFalse")] public void GetHashCode_DifferentBooleanCombinations_ReturnsHashCode(bool doNotIgnore, bool isAutogenerated) { // Arrange var localizedText = new LocalizedText { Key = "TestKey", DoNotIgnore = doNotIgnore, Value = "TestValue", IsAutogenerated = isAutogenerated }; // Act int hashCode = localizedText.GetHashCode(); // Assert Assert.That(hashCode, Is.InstanceOf()); } /// /// Tests that equal LocalizedText instances with null properties produce equal hash codes. /// Input: Two LocalizedText instances with identical null properties. /// Expected: Same hash code is returned. /// [Test] public void GetHashCode_EqualObjectsWithNullProperties_ReturnsSameHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = null, DoNotIgnore = true, Value = null, IsAutogenerated = true }; var localizedText2 = new LocalizedText { Key = null, DoNotIgnore = true, Value = null, IsAutogenerated = true }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.EqualTo(hashCode1)); } /// /// Tests that LocalizedText instances where one has null Key and the other has non-null Key produce different hash codes. /// Input: Two LocalizedText instances differing only in Key nullability. /// Expected: Different hash codes are returned. /// [Test] public void GetHashCode_NullVsNonNullKey_ReturnsDifferentHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = null, DoNotIgnore = false, Value = "Value", IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "Key", DoNotIgnore = false, Value = "Value", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.Not.EqualTo(hashCode1)); } /// /// Tests that LocalizedText instances where one has null Value and the other has non-null Value produce different hash codes. /// Input: Two LocalizedText instances differing only in Value nullability. /// Expected: Different hash codes are returned. /// [Test] public void GetHashCode_NullVsNonNullValue_ReturnsDifferentHashCode() { // Arrange var localizedText1 = new LocalizedText { Key = "Key", DoNotIgnore = false, Value = null, IsAutogenerated = false }; var localizedText2 = new LocalizedText { Key = "Key", DoNotIgnore = false, Value = "Value", IsAutogenerated = false }; // Act int hashCode1 = localizedText1.GetHashCode(); int hashCode2 = localizedText2.GetHashCode(); // Assert Assert.That(hashCode2, Is.Not.EqualTo(hashCode1)); } } }