From ea79d40bc4ed5fb1f8d07fd765b3f3e8b62dc4c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 12:51:31 +0000 Subject: [PATCH 1/3] Initial plan From e74ede8ba757c7ff5ebacbc51136ec46ec641a4b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 12:58:24 +0000 Subject: [PATCH 2/3] Fix compilation errors by updating .NET version to 9.0 and MSTest to v3.6.4 Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com> --- global.json | 4 ++++ src/LuYao.Common/LuYao.Common.csproj | 2 +- src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj | 2 +- src/LuYao.Text.Json/LuYao.Text.Json.csproj | 2 +- .../LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj | 8 ++++---- .../LuYao.Text.Json.UnitTests.csproj | 6 +++--- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/global.json b/global.json index 2c63c08..e23e021 100644 --- a/global.json +++ b/global.json @@ -1,2 +1,6 @@ { + "sdk": { + "version": "9.0.0", + "rollForward": "latestMinor" + } } diff --git a/src/LuYao.Common/LuYao.Common.csproj b/src/LuYao.Common/LuYao.Common.csproj index b7d4475..831494b 100644 --- a/src/LuYao.Common/LuYao.Common.csproj +++ b/src/LuYao.Common/LuYao.Common.csproj @@ -2,7 +2,7 @@ - net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0 + net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0 LuYao LuYao.Common latest diff --git a/src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj b/src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj index 964751b..a2aeb5a 100644 --- a/src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj +++ b/src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj @@ -3,7 +3,7 @@ - net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0 + net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0 latest True LuYao.Text.Json diff --git a/src/LuYao.Text.Json/LuYao.Text.Json.csproj b/src/LuYao.Text.Json/LuYao.Text.Json.csproj index 3a23aef..a4dd638 100644 --- a/src/LuYao.Text.Json/LuYao.Text.Json.csproj +++ b/src/LuYao.Text.Json/LuYao.Text.Json.csproj @@ -3,7 +3,7 @@ - net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0 + net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0 latest True True diff --git a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj index 56cd0ed..4fe6108 100644 --- a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj +++ b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj @@ -1,6 +1,6 @@  - net10.0 + net9.0 latest enable LuYao @@ -16,9 +16,9 @@ - - - + + + diff --git a/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj b/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj index f1665e5..63155f0 100644 --- a/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj +++ b/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj @@ -1,7 +1,7 @@  - net10.0 + net9.0 latest enable enable @@ -19,8 +19,8 @@ - - + + From 0f1dc91965c38c7261f8336249c690daebaa6a96 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:34:06 +0000 Subject: [PATCH 3/3] Upgrade MSTest to v3.11.1 and refactor exception tests to use Assert.ThrowsException Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com> --- .../Collections/EnumerableExtensionsTests.cs | 9 +- .../Collections/Generic/KeyedListTests.cs | 98 ++++++++++--------- .../Data/RecordObjectTests.cs | 15 ++- .../Data/RecordTests.cs | 6 +- .../Encoders/Base16Tests.cs | 6 +- .../Encoders/Base32Tests.cs | 3 +- .../Encoders/Base64Tests.cs | 11 +-- tests/LuYao.Common.UnitTests/EnumTests.cs | 3 +- .../LuYao.Common.UnitTests/GZipStringTests.cs | 42 ++++---- .../Globalization/RmbHelperTests.cs | 9 +- .../Limiters/TokenBucket/TokenBucketsTests.cs | 12 +-- .../LuYao.Common.UnitTests.csproj | 6 +- .../Text/CSharpStringBuilderTests.cs | 3 +- .../Text/Json/JsonReaderTest.cs | 48 ++++----- .../Xml/TranslatableXmlModelTests.cs | 5 +- .../LuYao.Text.Json.UnitTests.csproj | 4 +- 16 files changed, 122 insertions(+), 158 deletions(-) diff --git a/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs b/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs index d6d3c07..cd93f60 100644 --- a/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs @@ -63,26 +63,23 @@ public void SplitToBatch_ListWithRemainder_ReturnsLastBatchWithFewerItems() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void SplitToBatch_NullSource_ThrowsArgumentNullException() { List? input = null; - _ = input.SplitToBatch(2).ToList(); + Assert.ThrowsException(() => input.SplitToBatch(2).ToList()); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SplitToBatch_BatchSizeZero_ThrowsArgumentOutOfRangeException() { var input = Enumerable.Range(1, 3); - _ = input.SplitToBatch(0).ToList(); + Assert.ThrowsException(() => input.SplitToBatch(0).ToList()); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SplitToBatch_BatchSizeNegative_ThrowsArgumentOutOfRangeException() { var input = Enumerable.Range(1, 3); - _ = input.SplitToBatch(-1).ToList(); + Assert.ThrowsException(() => input.SplitToBatch(-1).ToList()); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs b/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs index 3611bef..c11eb32 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs @@ -63,13 +63,20 @@ public void Constructor_WithValidKeySelector_CreatesInstance() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] + + public void Constructor_WithNullKeySelector_ThrowsArgumentNullException() + + { - // Arrange & Act - var keyedList = new KeyedList(null!); - // Assert: 期望抛出 ArgumentNullException + + // Arrange, Act & Assert + + + Assert.ThrowsException(() => new KeyedList(null!)); + + } #endregion @@ -87,13 +94,20 @@ public void Indexer_GetWithValidIndex_ReturnsCorrectItem() } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] + + public void Indexer_GetWithInvalidIndex_ThrowsArgumentOutOfRangeException() + + { - // Arrange & Act - var item = _keyedList[-1]; - // Assert: 期望抛出 ArgumentOutOfRangeException + + // Arrange, Act & Assert + + + Assert.ThrowsException(() => _keyedList[-1]); + + } [TestMethod] @@ -110,16 +124,27 @@ public void Indexer_SetWithValidIndex_UpdatesItem() } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] + + public void Indexer_SetWithInvalidIndex_ThrowsArgumentOutOfRangeException() + + { + + // Arrange + + var newItem = new TestItem { Id = 10, Name = "New Item" }; - // Act - _keyedList[10] = newItem; - // Assert: 期望抛出 ArgumentOutOfRangeException + + // Act & Assert + + + Assert.ThrowsException(() => _keyedList[10] = newItem); + + } #endregion @@ -375,39 +400,30 @@ public void CopyTo_ValidArrayWithOffset_CopiesItemsWithOffset() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void CopyTo_NullArray_ThrowsArgumentNullException() { - // Arrange & Act - _keyedList.CopyTo(null!, 0); - - // Assert: 期望抛出 ArgumentNullException + // Arrange, Act & Assert + Assert.ThrowsException(() => _keyedList.CopyTo(null!, 0)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void CopyTo_NegativeArrayIndex_ThrowsArgumentOutOfRangeException() { // Arrange var array = new TestItem[_keyedList.Count]; - // Act - _keyedList.CopyTo(array, -1); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.ThrowsException(() => _keyedList.CopyTo(array, -1)); } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void CopyTo_InsufficientArraySpace_ThrowsArgumentException() { // Arrange var array = new TestItem[_keyedList.Count - 1]; - // Act - _keyedList.CopyTo(array, 0); - - // Assert: 期望抛出 ArgumentException + // Act & Assert + Assert.ThrowsException(() => _keyedList.CopyTo(array, 0)); } #endregion @@ -482,29 +498,23 @@ public void Insert_ValidIndex_InsertsItemAtCorrectPosition() } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void Insert_NegativeIndex_ThrowsArgumentOutOfRangeException() { // Arrange var newItem = new TestItem { Id = 4, Name = "Item 4" }; - // Act - _keyedList.Insert(-1, newItem); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.ThrowsException(() => _keyedList.Insert(-1, newItem)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void Insert_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException() { // Arrange var newItem = new TestItem { Id = 4, Name = "Item 4" }; - // Act - _keyedList.Insert(_keyedList.Count + 1, newItem); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.ThrowsException(() => _keyedList.Insert(_keyedList.Count + 1, newItem)); } #endregion @@ -562,23 +572,17 @@ public void RemoveAt_ValidIndex_RemovesItemAtIndex() } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RemoveAt_NegativeIndex_ThrowsArgumentOutOfRangeException() { - // Act - _keyedList.RemoveAt(-1); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.ThrowsException(() => _keyedList.RemoveAt(-1)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RemoveAt_IndexEqualToCount_ThrowsArgumentOutOfRangeException() { - // Act - _keyedList.RemoveAt(_keyedList.Count); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.ThrowsException(() => _keyedList.RemoveAt(_keyedList.Count)); } #endregion diff --git a/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs index 9c32601..d7210eb 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs @@ -84,14 +84,13 @@ public void Add_ValidObject_ShouldCreateColumnsAndAddRow() /// 测试 Add 方法传入 null 对象时抛出异常 /// [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Add_NullObject_ShouldThrowArgumentNullException() { // Arrange var record = new Record(); - // Act - record.Add(null!); + // Act & Assert + Assert.ThrowsException(() => record.Add(null!)); } /// @@ -154,11 +153,10 @@ public void From_SingleObject_ShouldCreateRecordWithData() /// 测试 From 方法传入 null 对象时抛出异常 /// [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void From_SingleObject_Null_ShouldThrowArgumentNullException() { - // Act - Record.From((TestModel)null!); + // Act & Assert + Assert.ThrowsException(() => Record.From((TestModel)null!)); } /// @@ -297,11 +295,10 @@ public void From_CollectionWithNulls_ShouldSkipNullItems() /// 测试 From 方法传入 null 集合时抛出异常 /// [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void From_NullCollection_ShouldThrowArgumentNullException() { - // Act - Record.FromList((TestModel[])null!); + // Act & Assert + Assert.ThrowsException(() => Record.FromList((TestModel[])null!)); } #endregion diff --git a/tests/LuYao.Common.UnitTests/Data/RecordTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordTests.cs index 90c1752..29f074b 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordTests.cs @@ -1007,7 +1007,6 @@ public void BoundaryCheck_EmptyTable_IndexGreaterThanZeroThrowsException() } [TestMethod] - [ExpectedException(typeof(DuplicateNameException))] public void Columns_AddDuplicateName_ThrowsException() { // Arrange @@ -1015,11 +1014,10 @@ public void Columns_AddDuplicateName_ThrowsException() table.Columns.Add("TestColumn"); // Act & Assert - table.Columns.Add("TestColumn"); // 应该抛出异常 + Assert.ThrowsException(() => table.Columns.Add("TestColumn")); // 应该抛出异常 } [TestMethod] - [ExpectedException(typeof(DuplicateNameException))] public void Columns_AddDuplicateNameDifferentType_ThrowsException() { // Arrange @@ -1027,7 +1025,7 @@ public void Columns_AddDuplicateNameDifferentType_ThrowsException() table.Columns.Add("TestColumn"); // Act & Assert - table.Columns.Add("TestColumn"); // 应该抛出异常 + Assert.ThrowsException(() => table.Columns.Add("TestColumn")); // 应该抛出异常 } public class Student diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs index 46f4569..3a8825e 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs @@ -42,19 +42,17 @@ public void FromBase16_EmptyString_ReturnsEmptyArray() } [TestMethod] - [ExpectedException(typeof(FormatException))] public void FromBase16_InvalidHex_ThrowsFormatException() { string input = "ZZ"; - Base16.FromBase16(input); + Assert.ThrowsException(() => Base16.FromBase16(input)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void FromBase16_OddLength_ThrowsArgumentOutOfRangeException() { string input = "ABC"; - Base16.FromBase16(input); + Assert.ThrowsException(() => Base16.FromBase16(input)); } } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs index cb42f72..72b4a47 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs @@ -43,10 +43,9 @@ public void FromBase32_SampleString_ReturnsExpectedBytes() } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void FromBase32_InvalidCharacter_ThrowsArgumentException() { - Base32.FromBase32("INVALID*"); + Assert.ThrowsException(() => Base32.FromBase32("INVALID*")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs index 33dfebb..30bc34e 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs @@ -10,7 +10,7 @@ public class Base64Tests public void ToBase64_StandardEncoding_ReturnsCorrectBase64() { // Arrange - var data = Encoding.UTF8.GetBytes("Hello, !"); + var data = Encoding.UTF8.GetBytes("Hello, ����!"); var expected = Convert.ToBase64String(data); // Act @@ -38,7 +38,7 @@ public void ToBase64_TrimPadding_ReturnsTrimmedBase64() public void FromBase64_StandardBase64_ReturnsOriginalBytes() { // Arrange - var original = Encoding.UTF8.GetBytes("Hello, !"); + var original = Encoding.UTF8.GetBytes("Hello, ����!"); var base64 = Convert.ToBase64String(original); // Act @@ -53,7 +53,7 @@ public void FromBase64_TrimmedBase64_ReturnsOriginalBytes() { // Arrange var original = Encoding.UTF8.GetBytes("test"); - var trimmedBase64 = "dGVzdA"; // ȥ"==" + var trimmedBase64 = "dGVzdA"; // ȥ����"==" // Act var result = Base64.FromBase64(trimmedBase64); @@ -73,11 +73,10 @@ public void FromBase64_EmptyString_ReturnsEmptyArray() } [TestMethod] - [ExpectedException(typeof(FormatException))] public void FromBase64_InvalidString_ThrowsFormatException() { - // Act - Base64.FromBase64("!@#$"); + // Act & Assert + Assert.ThrowsException(() => Base64.FromBase64("!@#$")); } } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/EnumTests.cs b/tests/LuYao.Common.UnitTests/EnumTests.cs index 9bbf34e..0652edf 100644 --- a/tests/LuYao.Common.UnitTests/EnumTests.cs +++ b/tests/LuYao.Common.UnitTests/EnumTests.cs @@ -80,10 +80,9 @@ public void Parse_ValidString_ReturnsEnumValue() } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void Parse_InvalidString_ThrowsException() { - Enum.Parse("NonExistent"); + Assert.ThrowsException(() => Enum.Parse("NonExistent")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/GZipStringTests.cs b/tests/LuYao.Common.UnitTests/GZipStringTests.cs index 75ddc2b..1ec38d0 100644 --- a/tests/LuYao.Common.UnitTests/GZipStringTests.cs +++ b/tests/LuYao.Common.UnitTests/GZipStringTests.cs @@ -6,7 +6,7 @@ namespace LuYao; [TestClass] public class GZipStringTests { - private const string TestString = "һַ This is a test string 12345!@#$%"; + private const string TestString = "����һ�������ַ��� This is a test string 12345!@#$%"; [TestMethod] public void Compress_WithValidInputAndGzipBase64_ReturnsCompressedString() @@ -54,7 +54,6 @@ public void Compress_WithAlreadyCompressedString_ReturnsSameString() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Compress_WithNullCompressor_ThrowsArgumentNullException() { // Arrange @@ -62,12 +61,11 @@ public void Compress_WithNullCompressor_ThrowsArgumentNullException() string compressor = null; string encoder = "base64"; - // Act - GZipString.Compress(input, compressor, encoder); + // Act & Assert + Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Compress_WithNullEncoder_ThrowsArgumentNullException() { // Arrange @@ -75,12 +73,11 @@ public void Compress_WithNullEncoder_ThrowsArgumentNullException() string compressor = "gzip"; string encoder = null; - // Act - GZipString.Compress(input, compressor, encoder); + // Act & Assert + Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] - [ExpectedException(typeof(KeyNotFoundException))] public void Compress_WithInvalidCompressor_ThrowsKeyNotFoundException() { // Arrange @@ -88,12 +85,11 @@ public void Compress_WithInvalidCompressor_ThrowsKeyNotFoundException() string compressor = "invalid"; string encoder = "base64"; - // Act - GZipString.Compress(input, compressor, encoder); + // Act & Assert + Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] - [ExpectedException(typeof(KeyNotFoundException))] public void Compress_WithInvalidEncoder_ThrowsKeyNotFoundException() { // Arrange @@ -101,8 +97,8 @@ public void Compress_WithInvalidEncoder_ThrowsKeyNotFoundException() string compressor = "gzip"; string encoder = "invalid"; - // Act - GZipString.Compress(input, compressor, encoder); + // Act & Assert + Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -122,7 +118,6 @@ public void Compress_WithInterfaceImplementation_ReturnsCompressedString() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Compress_WithNullCompressorInterface_ThrowsArgumentNullException() { // Arrange @@ -130,12 +125,11 @@ public void Compress_WithNullCompressorInterface_ThrowsArgumentNullException() GZipString.ICompressor compressor = null; var encoder = GZipString.Base64; - // Act - GZipString.Compress(input, compressor, encoder); + // Act & Assert + Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Compress_WithNullEncoderInterface_ThrowsArgumentNullException() { // Arrange @@ -143,8 +137,8 @@ public void Compress_WithNullEncoderInterface_ThrowsArgumentNullException() var compressor = GZipString.GZip; GZipString.IEncoder encoder = null; - // Act - GZipString.Compress(input, compressor, encoder); + // Act & Assert + Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -211,24 +205,22 @@ public void Decompress_WithDifferentCompressorAndEncoder_ReturnsOriginalString() } [TestMethod] - [ExpectedException(typeof(KeyNotFoundException))] public void Decompress_WithInvalidCompressorIdentifier_ThrowsKeyNotFoundException() { // Arrange string invalidCompressedString = "data:text/x-invalid;base64,ABCDEF"; - // Act - GZipString.Decompress(invalidCompressedString); + // Act & Assert + Assert.ThrowsException(() => GZipString.Decompress(invalidCompressedString)); } [TestMethod] - [ExpectedException(typeof(KeyNotFoundException))] public void Decompress_WithInvalidEncoderIdentifier_ThrowsKeyNotFoundException() { // Arrange string invalidCompressedString = "data:text/x-gzip;invalid,ABCDEF"; - // Act - GZipString.Decompress(invalidCompressedString); + // Act & Assert + Assert.ThrowsException(() => GZipString.Decompress(invalidCompressedString)); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/Globalization/RmbHelperTests.cs b/tests/LuYao.Common.UnitTests/Globalization/RmbHelperTests.cs index 6d1a2e2..f7d4f54 100644 --- a/tests/LuYao.Common.UnitTests/Globalization/RmbHelperTests.cs +++ b/tests/LuYao.Common.UnitTests/Globalization/RmbHelperTests.cs @@ -43,29 +43,26 @@ public void ToRmbUpper_IntegerAmount_ReturnsCorrectUpperCase() /// 测试金额超出范围时,期望抛出 ArgumentOutOfRangeException /// [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ToRmbUpper_OutOfRangeAmount_ThrowsArgumentOutOfRangeException() { - RmbHelper.ToRmbUpper(10000000000000000M); + Assert.ThrowsException(() => RmbHelper.ToRmbUpper(10000000000000000M)); } /// /// 测试金额为负数时,期望抛出 ArgumentOutOfRangeException /// [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ToRmbUpper_NegativeAmount_ThrowsArgumentOutOfRangeException() { - RmbHelper.ToRmbUpper(-1M); + Assert.ThrowsException(() => RmbHelper.ToRmbUpper(-1M)); } /// /// 测试金额为最大值时,期望抛出 ArgumentOutOfRangeException /// [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ToRmbUpper_MaxValidAmount_ThrowsArgumentOutOfRangeException() { - RmbHelper.ToRmbUpper(9999999999999999.99M); + Assert.ThrowsException(() => RmbHelper.ToRmbUpper(9999999999999999.99M)); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs b/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs index 22245f7..848ea2f 100644 --- a/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs +++ b/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs @@ -23,10 +23,9 @@ public void Builder_WithCapacity_PositiveValue_SetsCapacity() } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void Builder_WithCapacity_NonPositive_ThrowsArgumentOutOfRangeException() { - TokenBuckets.Construct().WithCapacity(0); + Assert.ThrowsException(() => TokenBuckets.Construct().WithCapacity(0)); } [TestMethod] @@ -39,10 +38,9 @@ public void Builder_WithFixedIntervalRefillStrategy_ValidArgs_SetsStrategy() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Builder_WithRefillStrategy_Null_ThrowsArgumentNullException() { - TokenBuckets.Construct().WithRefillStrategy(null); + Assert.ThrowsException(() => TokenBuckets.Construct().WithRefillStrategy(null)); } [TestMethod] @@ -68,10 +66,9 @@ public void Builder_WithBusyWaitSleepStrategy_Always_SetsBusyWaitSleepStrategy() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Builder_WithSleepStrategy_Null_ThrowsArgumentNullException() { - TokenBuckets.Construct().WithSleepStrategy(null); + Assert.ThrowsException(() => TokenBuckets.Construct().WithSleepStrategy(null)); } [TestMethod] @@ -82,10 +79,9 @@ public void Builder_WithSleepStrategy_Valid_SetsSleepStrategy() } [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] public void Builder_Build_WithoutCapacity_ThrowsInvalidOperationException() { - TokenBuckets.Construct().Build(); + Assert.ThrowsException(() => TokenBuckets.Construct().Build()); } // Dummy implementations for test diff --git a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj index 4fe6108..b6a1537 100644 --- a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj +++ b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj @@ -16,9 +16,9 @@ - - - + + + diff --git a/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs b/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs index 19d1ccb..0e1116e 100644 --- a/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs +++ b/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs @@ -126,11 +126,10 @@ public void NamespaceScope_ValidName_AppendsNamespaceAndBraces() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void SetNamespace_NullOrWhitespace_ThrowsArgumentNullException() { var builder = new CSharpStringBuilder(); - builder.SetNamespace(" "); + Assert.ThrowsException(() => builder.SetNamespace(" ")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs b/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs index c926372..3fcab6d 100644 --- a/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs +++ b/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs @@ -44,11 +44,10 @@ public void Constructor_WithString_ShouldInitializeCorrectly() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Constructor_WithNullTextReader_ShouldThrowArgumentNullException() { // Act & Assert - new JsonReader((TextReader)null); + Assert.ThrowsException(() => new JsonReader((TextReader)null)); } [TestMethod] @@ -154,36 +153,33 @@ public void Read_StringWithUnicodeEscape_ShouldReadCorrectly() } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_StringWithInvalidUnicodeEscape_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("\"\\uGGGG\""); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_StringWithInvalidEscape_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("\"\\x\""); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_UnterminatedString_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("\"unterminated"); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] @@ -271,14 +267,13 @@ public void Read_NumberWithNegativeExponent_ShouldReadCorrectly() } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_InvalidNumber_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("-"); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] @@ -310,14 +305,13 @@ public void Read_BooleanFalse_ShouldReadCorrectly() } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_InvalidBoolean_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("tru"); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] @@ -335,14 +329,13 @@ public void Read_Null_ShouldReadCorrectly() } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_InvalidNull_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("nul"); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] @@ -457,26 +450,24 @@ public void LineAndColumn_ShouldUpdateCorrectly() } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_UnexpectedCharacter_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("@"); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] - [ExpectedException(typeof(ObjectDisposedException))] public void Read_AfterDispose_ShouldThrowObjectDisposedException() { // Arrange var jsonReader = new JsonReader("{}"); jsonReader.Dispose(); - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] @@ -537,14 +528,13 @@ public void Read_VeryLargeNumber_ShouldReadAsDouble() } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_StringWithUnescapedControlCharacter_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("\"\u0001\""); // 未转义的控制字符 - // Act - jsonReader.Read(); + // Act & Assert + Assert.ThrowsException(() => jsonReader.Read()); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs b/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs index f21dc44..aeb07ec 100644 --- a/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs +++ b/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs @@ -44,13 +44,12 @@ public void Transform_ValidXml_ShouldDeserializeCorrectly() } [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] public void Transform_NoResource_ShouldThrowException() { // Arrange var xml = "XML"; - // Act - TestXmlModelNoResource.Transform(xml); + // Act & Assert + Assert.ThrowsException(() => TestXmlModelNoResource.Transform(xml)); } } diff --git a/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj b/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj index 63155f0..ca0825e 100644 --- a/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj +++ b/tests/LuYao.Text.Json.UnitTests/LuYao.Text.Json.UnitTests.csproj @@ -19,8 +19,8 @@ - - + +