From d0ccc09d27f0eb4eeee53366ffec55157166fe76 Mon Sep 17 00:00:00 2001 From: Soar360 Date: Wed, 12 Nov 2025 20:50:07 +0800 Subject: [PATCH 1/3] add dotnet 10.0 --- build/_build.csproj | 28 +++++++++---------- build/configureawait.props | 2 +- src/LuYao.Common/LuYao.Common.csproj | 2 +- .../LuYao.Text.Json.Jint.csproj | 10 +++---- src/LuYao.Text.Json/LuYao.Text.Json.csproj | 4 +-- .../LuYao.Common.UnitTests.csproj | 10 +++---- .../LuYao.Text.Json.UnitTests.csproj | 10 +++---- 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/build/_build.csproj b/build/_build.csproj index b1965fa..1ef2041 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -1,18 +1,18 @@ - + - - Exe - net8.0 - - CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 - .. - .. - 1 - false - + + Exe + net10.0 + + CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 + .. + .. + 1 + false + - - - + + + diff --git a/build/configureawait.props b/build/configureawait.props index b0aacc7..da15bcf 100644 --- a/build/configureawait.props +++ b/build/configureawait.props @@ -1,7 +1,7 @@ - + All runtime; build; native; contentfiles; analyzers diff --git a/src/LuYao.Common/LuYao.Common.csproj b/src/LuYao.Common/LuYao.Common.csproj index 5849dcd..b7d4475 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 + net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.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 8bdeb02..964751b 100644 --- a/src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj +++ b/src/LuYao.Text.Json.Jint/LuYao.Text.Json.Jint.csproj @@ -3,22 +3,20 @@ - net461;netstandard2.0;netstandard2.1;net6.0;net8.0 + net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0 latest True LuYao.Text.Json True ..\..\docs\luyao.snk - + - - - + + - diff --git a/src/LuYao.Text.Json/LuYao.Text.Json.csproj b/src/LuYao.Text.Json/LuYao.Text.Json.csproj index e7538f8..3a23aef 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 + net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0 latest True True @@ -15,7 +15,7 @@ - + diff --git a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj index d7e1f77..56cd0ed 100644 --- a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj +++ b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj @@ -1,6 +1,6 @@  - net8.0 + net10.0 latest enable LuYao @@ -16,15 +16,15 @@ - - - + + + - + 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 3b29bf0..f1665e5 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 @@  - net8.0 + net10.0 latest enable enable @@ -11,16 +11,16 @@ - + - + - - + + From 05f372fc237d3bc7faacfc15e56c3dd58c227fb6 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 21:37:21 +0800 Subject: [PATCH 2/3] Fix compilation errors: target .NET 9.0 and downgrade MSTest to v3.6.4 (#37) * Initial plan * 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> * Upgrade MSTest to v3.11.1 and refactor exception tests to use Assert.ThrowsException Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com> --- global.json | 4 + src/LuYao.Common/LuYao.Common.csproj | 2 +- .../LuYao.Text.Json.Jint.csproj | 2 +- src/LuYao.Text.Json/LuYao.Text.Json.csproj | 2 +- .../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 | 8 +- .../Text/CSharpStringBuilderTests.cs | 3 +- .../Text/Json/JsonReaderTest.cs | 48 ++++----- .../Xml/TranslatableXmlModelTests.cs | 5 +- .../LuYao.Text.Json.UnitTests.csproj | 6 +- 20 files changed, 131 insertions(+), 163 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/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 56cd0ed..b6a1537 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.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 f1665e5..ca0825e 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 570836e955536f0f017736e0a7642f30d3bccaa3 Mon Sep 17 00:00:00 2001 From: Soar360 Date: Wed, 12 Nov 2025 21:55:50 +0800 Subject: [PATCH 3/3] ThrowsExactly --- global.json | 2 +- src/LuYao.Common/LuYao.Common.csproj | 2 +- .../LuYao.Text.Json.Jint.csproj | 2 +- src/LuYao.Text.Json/LuYao.Text.Json.csproj | 2 +- .../Collections/Concurrent/AsyncQueueTests.cs | 2 +- .../Collections/EnumerableExtensionsTests.cs | 6 +- .../Collections/Generic/KeyedListTests.cs | 20 +-- .../Generic/WeakCollectionTests.cs | 20 +-- .../Data/GenericMethodTests.cs | 4 +- .../Data/RecordLoaderTests.cs | 2 +- .../Data/RecordObjectTests.cs | 6 +- .../Data/RecordRowTests.cs | 8 +- .../Data/RecordTests.cs | 116 +++++++++--------- .../DisposeActionTests.cs | 2 +- .../Encoders/Ascii85Tests.cs | 4 +- .../Encoders/Base16Tests.cs | 4 +- .../Encoders/Base32Tests.cs | 2 +- .../Encoders/Base62Tests.cs | 4 +- .../Encoders/Base64Tests.cs | 2 +- tests/LuYao.Common.UnitTests/EnumTests.cs | 4 +- .../LuYao.Common.UnitTests/GZipStringTests.cs | 16 +-- .../Globalization/RmbHelperTests.cs | 6 +- .../IO/AutoCleanTempFileTests.cs | 6 +- .../IO/Hashing/Crc32Tests.cs | 5 +- .../IO/Hashing/HashAgentTests.cs | 2 +- .../IO/PathHelperTests.cs | 2 +- .../Limiters/TokenBucket/TokenBucketsTests.cs | 8 +- .../LuYao.Common.UnitTests.csproj | 8 +- .../HttpResponseMessageExtensionsTests.cs | 2 +- .../StringExtensionsTests.cs | 2 +- .../Text/CSharpStringBuilderTests.cs | 2 +- .../Text/Json/JsonReaderTest.cs | 20 +-- .../Text/Json/JsonWriterTests.cs | 12 +- .../Text/StringHelperTests.cs | 6 +- .../Threading/AsyncLockTests.cs | 2 +- .../Threading/KeyedLockerTests.cs | 2 +- .../Threading/Tasks/TaskExtensionsTests.cs | 2 +- .../Xml/TranslatableXmlModelTests.cs | 2 +- .../LuYao.Text.Json.UnitTests.csproj | 6 +- .../TranslatableJsonModelTests.cs | 4 +- 40 files changed, 165 insertions(+), 164 deletions(-) diff --git a/global.json b/global.json index e23e021..1e7fdfa 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.0", + "version": "10.0.100", "rollForward": "latestMinor" } } diff --git a/src/LuYao.Common/LuYao.Common.csproj b/src/LuYao.Common/LuYao.Common.csproj index 831494b..7509be8 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;net9.0 + net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0;net10.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 a2aeb5a..4e5a3db 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;net9.0 + net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0;net10.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 a4dd638..a48e99d 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;net9.0 + net45;net461;netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0;net10.0 latest True True diff --git a/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs b/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs index 165b19d..1e0636a 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs @@ -53,7 +53,7 @@ public async Task DequeueAsync_NoItem_CancellationTokenTriggersException() cts.Cancel(); // Act & Assert - await Assert.ThrowsExceptionAsync(async () => + await Assert.ThrowsExactlyAsync(async () => { await queue.DequeueAsync(cts.Token); }); diff --git a/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs b/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs index cd93f60..6e4c894 100644 --- a/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/EnumerableExtensionsTests.cs @@ -66,20 +66,20 @@ public void SplitToBatch_ListWithRemainder_ReturnsLastBatchWithFewerItems() public void SplitToBatch_NullSource_ThrowsArgumentNullException() { List? input = null; - Assert.ThrowsException(() => input.SplitToBatch(2).ToList()); + Assert.ThrowsExactly(() => input.SplitToBatch(2).ToList()); } [TestMethod] public void SplitToBatch_BatchSizeZero_ThrowsArgumentOutOfRangeException() { var input = Enumerable.Range(1, 3); - Assert.ThrowsException(() => input.SplitToBatch(0).ToList()); + Assert.ThrowsExactly(() => input.SplitToBatch(0).ToList()); } [TestMethod] public void SplitToBatch_BatchSizeNegative_ThrowsArgumentOutOfRangeException() { var input = Enumerable.Range(1, 3); - Assert.ThrowsException(() => input.SplitToBatch(-1).ToList()); + Assert.ThrowsExactly(() => 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 c11eb32..8754b09 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs @@ -74,7 +74,7 @@ public void Constructor_WithNullKeySelector_ThrowsArgumentNullException() // Arrange, Act & Assert - Assert.ThrowsException(() => new KeyedList(null!)); + Assert.ThrowsExactly(() => new KeyedList(null!)); } @@ -105,7 +105,7 @@ public void Indexer_GetWithInvalidIndex_ThrowsArgumentOutOfRangeException() // Arrange, Act & Assert - Assert.ThrowsException(() => _keyedList[-1]); + Assert.ThrowsExactly(() => _keyedList[-1]); } @@ -142,7 +142,7 @@ public void Indexer_SetWithInvalidIndex_ThrowsArgumentOutOfRangeException() // Act & Assert - Assert.ThrowsException(() => _keyedList[10] = newItem); + Assert.ThrowsExactly(() => _keyedList[10] = newItem); } @@ -403,7 +403,7 @@ public void CopyTo_ValidArrayWithOffset_CopiesItemsWithOffset() public void CopyTo_NullArray_ThrowsArgumentNullException() { // Arrange, Act & Assert - Assert.ThrowsException(() => _keyedList.CopyTo(null!, 0)); + Assert.ThrowsExactly(() => _keyedList.CopyTo(null!, 0)); } [TestMethod] @@ -413,7 +413,7 @@ public void CopyTo_NegativeArrayIndex_ThrowsArgumentOutOfRangeException() var array = new TestItem[_keyedList.Count]; // Act & Assert - Assert.ThrowsException(() => _keyedList.CopyTo(array, -1)); + Assert.ThrowsExactly(() => _keyedList.CopyTo(array, -1)); } [TestMethod] @@ -423,7 +423,7 @@ public void CopyTo_InsufficientArraySpace_ThrowsArgumentException() var array = new TestItem[_keyedList.Count - 1]; // Act & Assert - Assert.ThrowsException(() => _keyedList.CopyTo(array, 0)); + Assert.ThrowsExactly(() => _keyedList.CopyTo(array, 0)); } #endregion @@ -504,7 +504,7 @@ public void Insert_NegativeIndex_ThrowsArgumentOutOfRangeException() var newItem = new TestItem { Id = 4, Name = "Item 4" }; // Act & Assert - Assert.ThrowsException(() => _keyedList.Insert(-1, newItem)); + Assert.ThrowsExactly(() => _keyedList.Insert(-1, newItem)); } [TestMethod] @@ -514,7 +514,7 @@ public void Insert_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException() var newItem = new TestItem { Id = 4, Name = "Item 4" }; // Act & Assert - Assert.ThrowsException(() => _keyedList.Insert(_keyedList.Count + 1, newItem)); + Assert.ThrowsExactly(() => _keyedList.Insert(_keyedList.Count + 1, newItem)); } #endregion @@ -575,14 +575,14 @@ public void RemoveAt_ValidIndex_RemovesItemAtIndex() public void RemoveAt_NegativeIndex_ThrowsArgumentOutOfRangeException() { // Act & Assert - Assert.ThrowsException(() => _keyedList.RemoveAt(-1)); + Assert.ThrowsExactly(() => _keyedList.RemoveAt(-1)); } [TestMethod] public void RemoveAt_IndexEqualToCount_ThrowsArgumentOutOfRangeException() { // Act & Assert - Assert.ThrowsException(() => _keyedList.RemoveAt(_keyedList.Count)); + Assert.ThrowsExactly(() => _keyedList.RemoveAt(_keyedList.Count)); } #endregion diff --git a/tests/LuYao.Common.UnitTests/Collections/Generic/WeakCollectionTests.cs b/tests/LuYao.Common.UnitTests/Collections/Generic/WeakCollectionTests.cs index 3420e20..1154fa6 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Generic/WeakCollectionTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Generic/WeakCollectionTests.cs @@ -16,7 +16,7 @@ public void Add_NullItem_ThrowsArgumentNullException() var collection = new WeakCollection(); // Act & Assert - Assert.ThrowsException(() => collection.Add(null)); + Assert.ThrowsExactly(() => collection.Add(null!)); } [TestMethod] @@ -31,7 +31,7 @@ public void Add_ValidItem_ItemAddedSuccessfully() // Assert var items = collection.TryGetItems(x => true); - Assert.AreEqual(1, items.Length); + Assert.HasCount(1, items); Assert.AreSame(item, items[0]); } @@ -48,7 +48,7 @@ public void Remove_ItemExists_ItemRemovedSuccessfully() // Assert Assert.IsTrue(result); - Assert.AreEqual(0, collection.TryGetItems(x => true).Length); + Assert.IsEmpty(collection.TryGetItems(x => true)); } [TestMethod] @@ -77,7 +77,7 @@ public void TryGetItems_FilterApplied_ReturnsFilteredItems() var items = collection.TryGetItems(x => x == "Item1"); // Assert - Assert.AreEqual(1, items.Length); + Assert.HasCount(1, items); Assert.AreEqual("Item1", items[0]); } @@ -93,9 +93,9 @@ public void TryGetItems_NoFilter_ReturnsAllItems() var items = collection.TryGetItems(); // Assert - Assert.AreEqual(2, items.Length); - CollectionAssert.Contains(items, "Item1"); - CollectionAssert.Contains(items, "Item2"); + Assert.HasCount(2, items); + Assert.Contains(items, "Item1"); + Assert.Contains(items, "Item2"); } [TestMethod] @@ -124,7 +124,7 @@ public void GetOrAdd_ItemDoesNotExist_AddsAndReturnsNewItem() // Assert Assert.AreEqual("NewItem", item); var items = collection.TryGetItems(); - Assert.AreEqual(1, items.Length); + Assert.HasCount(1, items); Assert.AreEqual("NewItem", items[0]); } @@ -140,7 +140,7 @@ public void Clear_CollectionCleared_NoItemsRemain() collection.Clear(); // Assert - Assert.AreEqual(0, collection.TryGetItems(x => true).Length); + Assert.IsEmpty(collection.TryGetItems(x => true)); } [TestMethod] @@ -159,7 +159,7 @@ public void GarbageCollection_WeakReferencesCollected_RemainingItemsCorrect() // Assert var items = collection.TryGetItems(x => true); - Assert.AreEqual(2, items.Length); + Assert.HasCount(2, items); Assert.AreSame(strongReference, items[1]); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs b/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs index cfdae7b..aee4605 100644 --- a/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs @@ -159,10 +159,10 @@ public void GenericSet_InvalidIndex_ShouldThrowException() record.AddRow(); // 只有一行,有效索引是 0 // Act & Assert - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => intColumn.Set(42, 1)); // 无效索引 - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => intColumn.Set(42, -1)); // 负索引 } diff --git a/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs index 7fb0fc7..d4c7880 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs @@ -474,7 +474,7 @@ public void WriteHeader_CalledTwice_ShouldThrowException() // Act & Assert // 第二次调用应该抛出异常,因为列已经存在 - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => { RecordLoader.WriteHeader(record); }); diff --git a/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs index d7210eb..fa0e664 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs @@ -90,7 +90,7 @@ public void Add_NullObject_ShouldThrowArgumentNullException() var record = new Record(); // Act & Assert - Assert.ThrowsException(() => record.Add(null!)); + Assert.ThrowsExactly(() => record.Add(null!)); } /// @@ -156,7 +156,7 @@ public void From_SingleObject_ShouldCreateRecordWithData() public void From_SingleObject_Null_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => Record.From((TestModel)null!)); + Assert.ThrowsExactly(() => Record.From((TestModel)null!)); } /// @@ -298,7 +298,7 @@ public void From_CollectionWithNulls_ShouldSkipNullItems() public void From_NullCollection_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => Record.FromList((TestModel[])null!)); + Assert.ThrowsExactly(() => Record.FromList((TestModel[])null!)); } #endregion diff --git a/tests/LuYao.Common.UnitTests/Data/RecordRowTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordRowTests.cs index 681fbe7..d483e9b 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordRowTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordRowTests.cs @@ -59,7 +59,7 @@ public void Constructor_ValidParameters_ShouldInitializeCorrectly() public void Constructor_NullRecord_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => new RecordRow(null!, 0)); + Assert.ThrowsExactly(() => new RecordRow(null!, 0)); } /// @@ -72,7 +72,7 @@ public void Constructor_NegativeRowIndex_ShouldThrowArgumentOutOfRangeException( var (record, _, _, _) = CreateTestRecord(); // Act & Assert - Assert.ThrowsException(() => new RecordRow(record, -1)); + Assert.ThrowsExactly(() => new RecordRow(record, -1)); } /// @@ -85,8 +85,8 @@ public void Constructor_RowIndexOutOfRange_ShouldThrowArgumentOutOfRangeExceptio var (record, _, _, _) = CreateTestRecord(); // Act & Assert - Assert.ThrowsException(() => new RecordRow(record, record.Count)); - Assert.ThrowsException(() => new RecordRow(record, record.Count + 1)); + Assert.ThrowsExactly(() => new RecordRow(record, record.Count)); + Assert.ThrowsExactly(() => new RecordRow(record, record.Count + 1)); } #endregion diff --git a/tests/LuYao.Common.UnitTests/Data/RecordTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordTests.cs index 29f074b..f412996 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordTests.cs @@ -692,7 +692,7 @@ public void GetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.GetValue(-1)); + var exception = Assert.ThrowsExactly(() => col.GetValue(-1)); Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); } @@ -705,7 +705,7 @@ public void GetValue_RowIndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.GetValue(1)); + var exception = Assert.ThrowsExactly(() => col.GetValue(1)); Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); } @@ -718,7 +718,7 @@ public void GetValue_RowIndexGreaterThanCount_ThrowsArgumentOutOfRangeException( table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.GetValue(5)); + var exception = Assert.ThrowsExactly(() => col.GetValue(5)); Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围")); } @@ -731,7 +731,7 @@ public void SetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.SetValue("test", -1)); + var exception = Assert.ThrowsExactly(() => col.SetValue("test", -1)); Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); } @@ -744,7 +744,7 @@ public void SetValue_RowIndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.SetValue("test", 1)); + var exception = Assert.ThrowsExactly(() => col.SetValue("test", 1)); Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); } @@ -757,7 +757,7 @@ public void SetValue_RowIndexGreaterThanCount_ThrowsArgumentOutOfRangeException( table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.SetValue("test", 5)); + var exception = Assert.ThrowsExactly(() => col.SetValue("test", 5)); Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围")); } @@ -770,7 +770,7 @@ public void SetBoolean_NegativeIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Set(true, -1)); + var exception = Assert.ThrowsExactly(() => col.Set(true, -1)); Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); } @@ -783,7 +783,7 @@ public void SetBoolean_IndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Set(true, 1)); + var exception = Assert.ThrowsExactly(() => col.Set(true, 1)); Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); } @@ -796,7 +796,7 @@ public void SetInt32_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Set(42, 5)); + var exception = Assert.ThrowsExactly(() => col.Set(42, 5)); Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围")); } @@ -809,7 +809,7 @@ public void ToBoolean_NegativeIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Get(-1)); + var exception = Assert.ThrowsExactly(() => col.Get(-1)); Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); } @@ -822,7 +822,7 @@ public void ToInt32_IndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Get(1)); + var exception = Assert.ThrowsExactly(() => col.Get(1)); Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); } @@ -835,7 +835,7 @@ public void ToString_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Get(10)); + var exception = Assert.ThrowsExactly(() => col.Get(10)); Assert.IsTrue(exception.Message.Contains("行索引 10 超出有效范围")); } @@ -881,8 +881,8 @@ public void BoundaryCheck_AfterCapacityExpansion_StillEnforcesBounds() Assert.AreEqual("test2", col.GetValue(2)); // Invalid indices should still throw - Assert.ThrowsException(() => col.GetValue(3)); - Assert.ThrowsException(() => col.SetValue("invalid", 4)); + Assert.ThrowsExactly(() => col.GetValue(3)); + Assert.ThrowsExactly(() => col.SetValue("invalid", 4)); } [TestMethod] @@ -909,21 +909,21 @@ public void AllTypedSetMethods_InvalidIndex_ThrowArgumentOutOfRangeException() table.AddRow(); // Only one row, valid index is 0 // Act & Assert - Test all Set methods with invalid index - Assert.ThrowsException(() => boolCol.Set(true, 1)); - Assert.ThrowsException(() => byteCol.Set((byte)1, 1)); - Assert.ThrowsException(() => charCol.Set('A', 1)); - Assert.ThrowsException(() => dateTimeCol.Set(DateTime.Now, 1)); - Assert.ThrowsException(() => decimalCol.Set(1.0m, 1)); - Assert.ThrowsException(() => doubleCol.Set(1.0, 1)); - Assert.ThrowsException(() => int16Col.Set((short)1, 1)); - Assert.ThrowsException(() => int32Col.Set(1, 1)); - Assert.ThrowsException(() => int64Col.Set(1L, 1)); - Assert.ThrowsException(() => sbyteCol.Set((sbyte)1, 1)); - Assert.ThrowsException(() => singleCol.Set(1.0f, 1)); - Assert.ThrowsException(() => stringCol.Set("test", 1)); - Assert.ThrowsException(() => uint16Col.Set((ushort)1, 1)); - Assert.ThrowsException(() => uint32Col.Set(1u, 1)); - Assert.ThrowsException(() => uint64Col.Set(1ul, 1)); + Assert.ThrowsExactly(() => boolCol.Set(true, 1)); + Assert.ThrowsExactly(() => byteCol.Set((byte)1, 1)); + Assert.ThrowsExactly(() => charCol.Set('A', 1)); + Assert.ThrowsExactly(() => dateTimeCol.Set(DateTime.Now, 1)); + Assert.ThrowsExactly(() => decimalCol.Set(1.0m, 1)); + Assert.ThrowsExactly(() => doubleCol.Set(1.0, 1)); + Assert.ThrowsExactly(() => int16Col.Set((short)1, 1)); + Assert.ThrowsExactly(() => int32Col.Set(1, 1)); + Assert.ThrowsExactly(() => int64Col.Set(1L, 1)); + Assert.ThrowsExactly(() => sbyteCol.Set((sbyte)1, 1)); + Assert.ThrowsExactly(() => singleCol.Set(1.0f, 1)); + Assert.ThrowsExactly(() => stringCol.Set("test", 1)); + Assert.ThrowsExactly(() => uint16Col.Set((ushort)1, 1)); + Assert.ThrowsExactly(() => uint32Col.Set(1u, 1)); + Assert.ThrowsExactly(() => uint64Col.Set(1ul, 1)); } [TestMethod] @@ -950,25 +950,25 @@ public void AllTypedToMethods_InvalidIndex_ThrowArgumentOutOfRangeException() table.AddRow(); // Only one row, valid index is 0 // Act & Assert - Test all To methods with invalid index - Assert.ThrowsException(() => boolCol.Get(1)); - Assert.ThrowsException(() => byteCol.Get(1)); - Assert.ThrowsException(() => charCol.Get(1)); - Assert.ThrowsException(() => dateTimeCol.Get(1)); - Assert.ThrowsException(() => decimalCol.Get(1)); - Assert.ThrowsException(() => doubleCol.Get(1)); - Assert.ThrowsException(() => int16Col.Get(1)); - Assert.ThrowsException(() => int32Col.Get(1)); - Assert.ThrowsException(() => int64Col.Get(1)); - Assert.ThrowsException(() => sbyteCol.Get(1)); - Assert.ThrowsException(() => singleCol.Get(1)); - Assert.ThrowsException(() => stringCol.Get(1)); - Assert.ThrowsException(() => uint16Col.Get(1)); - Assert.ThrowsException(() => uint32Col.Get(1)); - Assert.ThrowsException(() => uint64Col.Get(1)); + Assert.ThrowsExactly(() => boolCol.Get(1)); + Assert.ThrowsExactly(() => byteCol.Get(1)); + Assert.ThrowsExactly(() => charCol.Get(1)); + Assert.ThrowsExactly(() => dateTimeCol.Get(1)); + Assert.ThrowsExactly(() => decimalCol.Get(1)); + Assert.ThrowsExactly(() => doubleCol.Get(1)); + Assert.ThrowsExactly(() => int16Col.Get(1)); + Assert.ThrowsExactly(() => int32Col.Get(1)); + Assert.ThrowsExactly(() => int64Col.Get(1)); + Assert.ThrowsExactly(() => sbyteCol.Get(1)); + Assert.ThrowsExactly(() => singleCol.Get(1)); + Assert.ThrowsExactly(() => stringCol.Get(1)); + Assert.ThrowsExactly(() => uint16Col.Get(1)); + Assert.ThrowsExactly(() => uint32Col.Get(1)); + Assert.ThrowsExactly(() => uint64Col.Get(1)); } [TestMethod] - public void BoundaryCheck_EmptyTable_AnyIndexThrowsException() + public void BoundaryCheck_EmptyTable_AnyIndexThrowsExactly() { // Arrange var table = new Record(); @@ -976,12 +976,12 @@ public void BoundaryCheck_EmptyTable_AnyIndexThrowsException() // No rows added, Count = 0 // Act & Assert - Assert.ThrowsException(() => col.GetValue(0)); - Assert.ThrowsException(() => col.Get(0)); + Assert.ThrowsExactly(() => col.GetValue(0)); + Assert.ThrowsExactly(() => col.Get(0)); } [TestMethod] - public void BoundaryCheck_EmptyTable_NegativeIndexStillThrowsException() + public void BoundaryCheck_EmptyTable_NegativeIndexStillThrowsExactly() { // Arrange var table = new Record(); @@ -989,12 +989,12 @@ public void BoundaryCheck_EmptyTable_NegativeIndexStillThrowsException() // No rows added, Count = 0 // Act & Assert - Negative indices should always throw - Assert.ThrowsException(() => col.GetValue(-1)); - Assert.ThrowsException(() => col.SetValue("test", -1)); + Assert.ThrowsExactly(() => col.GetValue(-1)); + Assert.ThrowsExactly(() => col.SetValue("test", -1)); } [TestMethod] - public void BoundaryCheck_EmptyTable_IndexGreaterThanZeroThrowsException() + public void BoundaryCheck_EmptyTable_IndexGreaterThanZeroThrowsExactly() { // Arrange var table = new Record(); @@ -1002,30 +1002,30 @@ public void BoundaryCheck_EmptyTable_IndexGreaterThanZeroThrowsException() // No rows added, Count = 0 // Act & Assert - Indices > 0 should throw even with auto-row creation - Assert.ThrowsException(() => col.Set("test", 1)); - Assert.ThrowsException(() => col.Set("test", 2)); + Assert.ThrowsExactly(() => col.Set("test", 1)); + Assert.ThrowsExactly(() => col.Set("test", 2)); } [TestMethod] - public void Columns_AddDuplicateName_ThrowsException() + public void Columns_AddDuplicateName_ThrowsExactly() { // Arrange var table = new Record(); table.Columns.Add("TestColumn"); // Act & Assert - Assert.ThrowsException(() => table.Columns.Add("TestColumn")); // 应该抛出异常 + Assert.ThrowsExactly(() => table.Columns.Add("TestColumn")); // 应该抛出异常 } [TestMethod] - public void Columns_AddDuplicateNameDifferentType_ThrowsException() + public void Columns_AddDuplicateNameDifferentType_ThrowsExactly() { // Arrange var table = new Record(); table.Columns.Add("TestColumn"); // Act & Assert - Assert.ThrowsException(() => table.Columns.Add("TestColumn")); // 应该抛出异常 + Assert.ThrowsExactly(() => table.Columns.Add("TestColumn")); // 应该抛出异常 } public class Student @@ -1061,6 +1061,6 @@ public void Columns_SetObjectNotMatchType_ThrowsInvalidCastException() var id = re.Columns.Add("Id"); var row = re.AddRow(); // Act & Assert - Assert.ThrowsException(() => raw.SetValue(1, row.Row)); + Assert.ThrowsExactly(() => raw.SetValue(1, row.Row)); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/DisposeActionTests.cs b/tests/LuYao.Common.UnitTests/DisposeActionTests.cs index 8483e47..45fcfc9 100644 --- a/tests/LuYao.Common.UnitTests/DisposeActionTests.cs +++ b/tests/LuYao.Common.UnitTests/DisposeActionTests.cs @@ -8,7 +8,7 @@ public class DisposeActionTests [TestMethod] public void Constructor_WhenActionIsNull_ShouldThrowArgumentNullException() { - Assert.ThrowsException(() => new DisposeAction(null!)); + Assert.ThrowsExactly(() => new DisposeAction(null!)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs index b683024..4d372dd 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs @@ -46,11 +46,11 @@ public void Encode_EnforceMarksFalse_DoesNotIncludePrefixAndSuffix() } [TestMethod] - public void Decode_EnforceMarksTrue_MissingMarks_ThrowsException() + public void Decode_EnforceMarksTrue_MissingMarks_ThrowsExactly() { var ascii85 = new Ascii85 { EnforceMarks = true }; string encoded = "87cURD_*#4DfTZ"; - Assert.ThrowsException(() => ascii85.Decode(encoded)); + Assert.ThrowsExactly(() => ascii85.Decode(encoded)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs index 3a8825e..b2c6ec7 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs @@ -45,14 +45,14 @@ public void FromBase16_EmptyString_ReturnsEmptyArray() public void FromBase16_InvalidHex_ThrowsFormatException() { string input = "ZZ"; - Assert.ThrowsException(() => Base16.FromBase16(input)); + Assert.ThrowsExactly(() => Base16.FromBase16(input)); } [TestMethod] public void FromBase16_OddLength_ThrowsArgumentOutOfRangeException() { string input = "ABC"; - Assert.ThrowsException(() => Base16.FromBase16(input)); + Assert.ThrowsExactly(() => 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 72b4a47..e7478eb 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base32Tests.cs @@ -45,7 +45,7 @@ public void FromBase32_SampleString_ReturnsExpectedBytes() [TestMethod] public void FromBase32_InvalidCharacter_ThrowsArgumentException() { - Assert.ThrowsException(() => Base32.FromBase32("INVALID*")); + Assert.ThrowsExactly(() => Base32.FromBase32("INVALID*")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs index 65ca2fe..8965c2a 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs @@ -53,7 +53,7 @@ public void FromBase62_EmptyString_ThrowsArgumentNullException() string input = ""; // Act & Assert - Assert.ThrowsException(() => Base62.FromBase62(input)); + Assert.ThrowsExactly(() => Base62.FromBase62(input)); } [TestMethod] @@ -63,7 +63,7 @@ public void FromBase62_WhitespaceString_ThrowsArgumentNullException() string input = " "; // Act & Assert - Assert.ThrowsException(() => Base62.FromBase62(input)); + Assert.ThrowsExactly(() => Base62.FromBase62(input)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs index 30bc34e..dd7dfb2 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs @@ -76,7 +76,7 @@ public void FromBase64_EmptyString_ReturnsEmptyArray() public void FromBase64_InvalidString_ThrowsFormatException() { // Act & Assert - Assert.ThrowsException(() => Base64.FromBase64("!@#$")); + Assert.ThrowsExactly(() => 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 0652edf..c24eaeb 100644 --- a/tests/LuYao.Common.UnitTests/EnumTests.cs +++ b/tests/LuYao.Common.UnitTests/EnumTests.cs @@ -80,9 +80,9 @@ public void Parse_ValidString_ReturnsEnumValue() } [TestMethod] - public void Parse_InvalidString_ThrowsException() + public void Parse_InvalidString_ThrowsExactly() { - Assert.ThrowsException(() => Enum.Parse("NonExistent")); + Assert.ThrowsExactly(() => Enum.Parse("NonExistent")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/GZipStringTests.cs b/tests/LuYao.Common.UnitTests/GZipStringTests.cs index 1ec38d0..7098e6b 100644 --- a/tests/LuYao.Common.UnitTests/GZipStringTests.cs +++ b/tests/LuYao.Common.UnitTests/GZipStringTests.cs @@ -62,7 +62,7 @@ public void Compress_WithNullCompressor_ThrowsArgumentNullException() string encoder = "base64"; // Act & Assert - Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); + Assert.ThrowsExactly(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -74,7 +74,7 @@ public void Compress_WithNullEncoder_ThrowsArgumentNullException() string encoder = null; // Act & Assert - Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); + Assert.ThrowsExactly(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -86,7 +86,7 @@ public void Compress_WithInvalidCompressor_ThrowsKeyNotFoundException() string encoder = "base64"; // Act & Assert - Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); + Assert.ThrowsExactly(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -98,7 +98,7 @@ public void Compress_WithInvalidEncoder_ThrowsKeyNotFoundException() string encoder = "invalid"; // Act & Assert - Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); + Assert.ThrowsExactly(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -126,7 +126,7 @@ public void Compress_WithNullCompressorInterface_ThrowsArgumentNullException() var encoder = GZipString.Base64; // Act & Assert - Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); + Assert.ThrowsExactly(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -138,7 +138,7 @@ public void Compress_WithNullEncoderInterface_ThrowsArgumentNullException() GZipString.IEncoder encoder = null; // Act & Assert - Assert.ThrowsException(() => GZipString.Compress(input, compressor, encoder)); + Assert.ThrowsExactly(() => GZipString.Compress(input, compressor, encoder)); } [TestMethod] @@ -211,7 +211,7 @@ public void Decompress_WithInvalidCompressorIdentifier_ThrowsKeyNotFoundExceptio string invalidCompressedString = "data:text/x-invalid;base64,ABCDEF"; // Act & Assert - Assert.ThrowsException(() => GZipString.Decompress(invalidCompressedString)); + Assert.ThrowsExactly(() => GZipString.Decompress(invalidCompressedString)); } [TestMethod] @@ -221,6 +221,6 @@ public void Decompress_WithInvalidEncoderIdentifier_ThrowsKeyNotFoundException() string invalidCompressedString = "data:text/x-gzip;invalid,ABCDEF"; // Act & Assert - Assert.ThrowsException(() => GZipString.Decompress(invalidCompressedString)); + Assert.ThrowsExactly(() => 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 f7d4f54..4fe430d 100644 --- a/tests/LuYao.Common.UnitTests/Globalization/RmbHelperTests.cs +++ b/tests/LuYao.Common.UnitTests/Globalization/RmbHelperTests.cs @@ -45,7 +45,7 @@ public void ToRmbUpper_IntegerAmount_ReturnsCorrectUpperCase() [TestMethod] public void ToRmbUpper_OutOfRangeAmount_ThrowsArgumentOutOfRangeException() { - Assert.ThrowsException(() => RmbHelper.ToRmbUpper(10000000000000000M)); + Assert.ThrowsExactly(() => RmbHelper.ToRmbUpper(10000000000000000M)); } /// @@ -54,7 +54,7 @@ public void ToRmbUpper_OutOfRangeAmount_ThrowsArgumentOutOfRangeException() [TestMethod] public void ToRmbUpper_NegativeAmount_ThrowsArgumentOutOfRangeException() { - Assert.ThrowsException(() => RmbHelper.ToRmbUpper(-1M)); + Assert.ThrowsExactly(() => RmbHelper.ToRmbUpper(-1M)); } /// @@ -63,6 +63,6 @@ public void ToRmbUpper_NegativeAmount_ThrowsArgumentOutOfRangeException() [TestMethod] public void ToRmbUpper_MaxValidAmount_ThrowsArgumentOutOfRangeException() { - Assert.ThrowsException(() => RmbHelper.ToRmbUpper(9999999999999999.99M)); + Assert.ThrowsExactly(() => RmbHelper.ToRmbUpper(9999999999999999.99M)); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/IO/AutoCleanTempFileTests.cs b/tests/LuYao.Common.UnitTests/IO/AutoCleanTempFileTests.cs index 01127f4..6ecfb11 100644 --- a/tests/LuYao.Common.UnitTests/IO/AutoCleanTempFileTests.cs +++ b/tests/LuYao.Common.UnitTests/IO/AutoCleanTempFileTests.cs @@ -8,9 +8,9 @@ public class AutoCleanTempFileTests [TestMethod] public void Constructor_FileNameIsNullOrWhiteSpace_ThrowsArgumentException() { - Assert.ThrowsException(() => new AutoCleanTempFile(null)); - Assert.ThrowsException(() => new AutoCleanTempFile("")); - Assert.ThrowsException(() => new AutoCleanTempFile(" ")); + Assert.ThrowsExactly(() => new AutoCleanTempFile(null)); + Assert.ThrowsExactly(() => new AutoCleanTempFile("")); + Assert.ThrowsExactly(() => new AutoCleanTempFile(" ")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs b/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs index 3ba0a78..8fd847b 100644 --- a/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs +++ b/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs @@ -66,7 +66,8 @@ public void HashAlgorithm_StreamInput_ReturnsExpectedCrc() // 结果应为 0xCBF43926 Assert.IsNotNull(hash); Assert.AreEqual(4, hash.Length); - var value = BitConverter.ToUInt32(hash.Reverse().ToArray(), 0); + Array.Reverse(hash); + var value = BitConverter.ToUInt32(hash, 0); Assert.AreEqual(0xCBF43926u, value); } } @@ -77,7 +78,7 @@ public void Constructor_BigEndian_ThrowsPlatformNotSupportedException() // 仅在非小端平台抛出异常,通常不会触发 if (!BitConverter.IsLittleEndian) { - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => { var crc32 = new Crc32(); }); diff --git a/tests/LuYao.Common.UnitTests/IO/Hashing/HashAgentTests.cs b/tests/LuYao.Common.UnitTests/IO/Hashing/HashAgentTests.cs index 383497c..2c3d72d 100644 --- a/tests/LuYao.Common.UnitTests/IO/Hashing/HashAgentTests.cs +++ b/tests/LuYao.Common.UnitTests/IO/Hashing/HashAgentTests.cs @@ -92,6 +92,6 @@ public void Hash_EmptyString_ReturnsCorrectHash() public void HashFile_FileNotExist_ThrowsFileNotFoundException() { // Act & Assert - Assert.ThrowsException(() => _md5Agent.HashFile("not_exist_file.txt")); + Assert.ThrowsExactly(() => _md5Agent.HashFile("not_exist_file.txt")); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/IO/PathHelperTests.cs b/tests/LuYao.Common.UnitTests/IO/PathHelperTests.cs index 8219c89..79aa1fe 100644 --- a/tests/LuYao.Common.UnitTests/IO/PathHelperTests.cs +++ b/tests/LuYao.Common.UnitTests/IO/PathHelperTests.cs @@ -82,7 +82,7 @@ public void GetMimeType_ShouldThrowArgumentException_ForNullOrEmptyExtension() // Arrange string extension = string.Empty; // Act & Assert - Assert.ThrowsException(() => PathHelper.GetMimeType(extension)); + Assert.ThrowsExactly(() => PathHelper.GetMimeType(extension)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs b/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs index 848ea2f..5bdae95 100644 --- a/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs +++ b/tests/LuYao.Common.UnitTests/Limiters/TokenBucket/TokenBucketsTests.cs @@ -25,7 +25,7 @@ public void Builder_WithCapacity_PositiveValue_SetsCapacity() [TestMethod] public void Builder_WithCapacity_NonPositive_ThrowsArgumentOutOfRangeException() { - Assert.ThrowsException(() => TokenBuckets.Construct().WithCapacity(0)); + Assert.ThrowsExactly(() => TokenBuckets.Construct().WithCapacity(0)); } [TestMethod] @@ -40,7 +40,7 @@ public void Builder_WithFixedIntervalRefillStrategy_ValidArgs_SetsStrategy() [TestMethod] public void Builder_WithRefillStrategy_Null_ThrowsArgumentNullException() { - Assert.ThrowsException(() => TokenBuckets.Construct().WithRefillStrategy(null)); + Assert.ThrowsExactly(() => TokenBuckets.Construct().WithRefillStrategy(null)); } [TestMethod] @@ -68,7 +68,7 @@ public void Builder_WithBusyWaitSleepStrategy_Always_SetsBusyWaitSleepStrategy() [TestMethod] public void Builder_WithSleepStrategy_Null_ThrowsArgumentNullException() { - Assert.ThrowsException(() => TokenBuckets.Construct().WithSleepStrategy(null)); + Assert.ThrowsExactly(() => TokenBuckets.Construct().WithSleepStrategy(null)); } [TestMethod] @@ -81,7 +81,7 @@ public void Builder_WithSleepStrategy_Valid_SetsSleepStrategy() [TestMethod] public void Builder_Build_WithoutCapacity_ThrowsInvalidOperationException() { - Assert.ThrowsException(() => TokenBuckets.Construct().Build()); + Assert.ThrowsExactly(() => 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 b6a1537..56cd0ed 100644 --- a/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj +++ b/tests/LuYao.Common.UnitTests/LuYao.Common.UnitTests.csproj @@ -1,6 +1,6 @@  - net9.0 + net10.0 latest enable LuYao @@ -16,9 +16,9 @@ - - - + + + diff --git a/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs b/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs index 5978e09..edd0062 100644 --- a/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs +++ b/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs @@ -18,7 +18,7 @@ public async Task ReadAsHtmlAsync_ResponseIsNull_ThrowsArgumentNullException() HttpResponseMessage? response = null; // Act & Assert - await Assert.ThrowsExceptionAsync(async () => + await Assert.ThrowsExactlyAsync(async () => { await HttpResponseMessageExtensions.ReadAsHtmlAsync(response); }); diff --git a/tests/LuYao.Common.UnitTests/StringExtensionsTests.cs b/tests/LuYao.Common.UnitTests/StringExtensionsTests.cs index e311544..55a3d94 100644 --- a/tests/LuYao.Common.UnitTests/StringExtensionsTests.cs +++ b/tests/LuYao.Common.UnitTests/StringExtensionsTests.cs @@ -79,7 +79,7 @@ public void FindAll_ReturnsEmptyCollection_WhenPatternNotFound() var slices = text.FindAll("
", "
").ToArray(); // Assert - Assert.AreEqual(0, slices.Length); + Assert.IsEmpty(slices); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs b/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs index 0e1116e..3959466 100644 --- a/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs +++ b/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs @@ -129,7 +129,7 @@ public void NamespaceScope_ValidName_AppendsNamespaceAndBraces() public void SetNamespace_NullOrWhitespace_ThrowsArgumentNullException() { var builder = new CSharpStringBuilder(); - Assert.ThrowsException(() => builder.SetNamespace(" ")); + Assert.ThrowsExactly(() => builder.SetNamespace(" ")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs b/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs index 3fcab6d..37367c8 100644 --- a/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs +++ b/tests/LuYao.Common.UnitTests/Text/Json/JsonReaderTest.cs @@ -47,7 +47,7 @@ public void Constructor_WithString_ShouldInitializeCorrectly() public void Constructor_WithNullTextReader_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => new JsonReader((TextReader)null)); + Assert.ThrowsExactly(() => new JsonReader((TextReader)null)); } [TestMethod] @@ -159,7 +159,7 @@ public void Read_StringWithInvalidUnicodeEscape_ShouldThrowException() using var jsonReader = new JsonReader("\"\\uGGGG\""); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -169,7 +169,7 @@ public void Read_StringWithInvalidEscape_ShouldThrowException() using var jsonReader = new JsonReader("\"\\x\""); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -179,7 +179,7 @@ public void Read_UnterminatedString_ShouldThrowException() using var jsonReader = new JsonReader("\"unterminated"); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -273,7 +273,7 @@ public void Read_InvalidNumber_ShouldThrowException() using var jsonReader = new JsonReader("-"); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -311,7 +311,7 @@ public void Read_InvalidBoolean_ShouldThrowException() using var jsonReader = new JsonReader("tru"); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -335,7 +335,7 @@ public void Read_InvalidNull_ShouldThrowException() using var jsonReader = new JsonReader("nul"); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -456,7 +456,7 @@ public void Read_UnexpectedCharacter_ShouldThrowException() using var jsonReader = new JsonReader("@"); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -467,7 +467,7 @@ public void Read_AfterDispose_ShouldThrowObjectDisposedException() jsonReader.Dispose(); // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] @@ -534,7 +534,7 @@ public void Read_StringWithUnescapedControlCharacter_ShouldThrowException() using var jsonReader = new JsonReader("\"\u0001\""); // 未转义的控制字符 // Act & Assert - Assert.ThrowsException(() => jsonReader.Read()); + Assert.ThrowsExactly(() => jsonReader.Read()); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Text/Json/JsonWriterTests.cs b/tests/LuYao.Common.UnitTests/Text/Json/JsonWriterTests.cs index c668e31..76977e6 100644 --- a/tests/LuYao.Common.UnitTests/Text/Json/JsonWriterTests.cs +++ b/tests/LuYao.Common.UnitTests/Text/Json/JsonWriterTests.cs @@ -57,7 +57,7 @@ public void Constructor_WithStringBuilder_ShouldCreateWriter() public void Constructor_WithNullTextWriter_ShouldThrowArgumentNullException() { // Arrange & Act & Assert - Assert.ThrowsException(() => new JsonWriter((TextWriter)null)); + Assert.ThrowsExactly(() => new JsonWriter((TextWriter)null)); } [TestMethod] @@ -125,7 +125,7 @@ public void WriteObject_WithIndentation_ShouldFormatCorrectly() public void WriteEndObject_WithoutStartObject_ShouldThrowInvalidOperationException() { // Act & Assert - Assert.ThrowsException(() => _writer.WriteEndObject()); + Assert.ThrowsExactly(() => _writer.WriteEndObject()); } #endregion @@ -181,7 +181,7 @@ public void WriteArray_WithIndentation_ShouldFormatCorrectly() public void WriteEndArray_WithoutStartArray_ShouldThrowInvalidOperationException() { // Act & Assert - Assert.ThrowsException(() => _writer.WriteEndArray()); + Assert.ThrowsExactly(() => _writer.WriteEndArray()); } #endregion @@ -221,7 +221,7 @@ public void WritePropertyName_WithIndentation_ShouldIncludeSpace() public void WritePropertyName_NullName_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => _writer.WritePropertyName(null)); + Assert.ThrowsExactly(() => _writer.WritePropertyName(null)); } #endregion @@ -421,7 +421,7 @@ public void WriteRaw_ValidJson_ShouldWriteRawValue() public void WriteRaw_NullValue_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => _writer.WriteRaw(null)); + Assert.ThrowsExactly(() => _writer.WriteRaw(null)); } #endregion @@ -600,7 +600,7 @@ public void WriteInvalidStructure_ShouldThrowInvalidOperationException() { // Act & Assert _writer.WriteStartObject(); - Assert.ThrowsException(() => _writer.WriteEndArray()); + Assert.ThrowsExactly(() => _writer.WriteEndArray()); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Text/StringHelperTests.cs b/tests/LuYao.Common.UnitTests/Text/StringHelperTests.cs index b9ff219..eeb48d0 100644 --- a/tests/LuYao.Common.UnitTests/Text/StringHelperTests.cs +++ b/tests/LuYao.Common.UnitTests/Text/StringHelperTests.cs @@ -12,15 +12,15 @@ public class StringHelperTests public void Truncate_ThrowsArgumentNullException_WhenTextIsNull() { // Act & Assert - Assert.ThrowsException(() => StringHelper.Truncate(null, 10, out _)); + Assert.ThrowsExactly(() => StringHelper.Truncate(null, 10, out _)); } [TestMethod] public void Truncate_ThrowsArgumentOutOfRangeException_WhenMaxLengthIsLessThanOne() { // Act & Assert - Assert.ThrowsException(() => StringHelper.Truncate("test", 0, out _)); - Assert.ThrowsException(() => StringHelper.Truncate("test", -1, out _)); + Assert.ThrowsExactly(() => StringHelper.Truncate("test", 0, out _)); + Assert.ThrowsExactly(() => StringHelper.Truncate("test", -1, out _)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Threading/AsyncLockTests.cs b/tests/LuYao.Common.UnitTests/Threading/AsyncLockTests.cs index 6cbefd1..c177791 100644 --- a/tests/LuYao.Common.UnitTests/Threading/AsyncLockTests.cs +++ b/tests/LuYao.Common.UnitTests/Threading/AsyncLockTests.cs @@ -11,7 +11,7 @@ public class AsyncLockTests [TestMethod] public async Task LockAsync_WithNullKey_ThrowsArgumentNullException() { - await Assert.ThrowsExceptionAsync( + await Assert.ThrowsExactlyAsync( async () => await AsyncLock.LockAsync(null)); } diff --git a/tests/LuYao.Common.UnitTests/Threading/KeyedLockerTests.cs b/tests/LuYao.Common.UnitTests/Threading/KeyedLockerTests.cs index 8309da0..45427fb 100644 --- a/tests/LuYao.Common.UnitTests/Threading/KeyedLockerTests.cs +++ b/tests/LuYao.Common.UnitTests/Threading/KeyedLockerTests.cs @@ -34,7 +34,7 @@ public void GetLock_NullKey_ThrowsArgumentNullException() string? key = null; // Act & Assert - Assert.ThrowsException(() => KeyedLocker.GetLock(key), "应抛出 ArgumentNullException。"); + Assert.ThrowsExactly(() => KeyedLocker.GetLock(key), "应抛出 ArgumentNullException。"); } /// diff --git a/tests/LuYao.Common.UnitTests/Threading/Tasks/TaskExtensionsTests.cs b/tests/LuYao.Common.UnitTests/Threading/Tasks/TaskExtensionsTests.cs index a449af7..ca4bba8 100644 --- a/tests/LuYao.Common.UnitTests/Threading/Tasks/TaskExtensionsTests.cs +++ b/tests/LuYao.Common.UnitTests/Threading/Tasks/TaskExtensionsTests.cs @@ -27,7 +27,7 @@ public async Task IsCompletedSuccessfully_WhenTaskFaulted_ShouldReturnFalse() var task = Task.Run(() => throw new Exception("Test Exception")); // Act & Assert - await Assert.ThrowsExceptionAsync(() => task); + await Assert.ThrowsExactlyAsync(() => task); Assert.IsFalse(task.IsCompletedSuccessfully()); } diff --git a/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs b/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs index aeb07ec..4afbb4b 100644 --- a/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs +++ b/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs @@ -50,6 +50,6 @@ public void Transform_NoResource_ShouldThrowException() var xml = "XML"; // Act & Assert - Assert.ThrowsException(() => TestXmlModelNoResource.Transform(xml)); + Assert.ThrowsExactly(() => 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 ca0825e..f1665e5 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 @@  - net9.0 + net10.0 latest enable enable @@ -19,8 +19,8 @@ - - + + diff --git a/tests/LuYao.Text.Json.UnitTests/TranslatableJsonModelTests.cs b/tests/LuYao.Text.Json.UnitTests/TranslatableJsonModelTests.cs index 2d2692a..df35b2b 100644 --- a/tests/LuYao.Text.Json.UnitTests/TranslatableJsonModelTests.cs +++ b/tests/LuYao.Text.Json.UnitTests/TranslatableJsonModelTests.cs @@ -37,7 +37,7 @@ public void Transform_EmptyJsonString_ThrowsArgumentException() string json = ""; // Act & Assert - Assert.ThrowsException(() => TestJsonModel.Transform(json)); + Assert.ThrowsExactly(() => TestJsonModel.Transform(json)); } /// @@ -68,6 +68,6 @@ public void Transform_NullObject_ThrowsArgumentNullException() object? model = null; // Act & Assert - Assert.ThrowsException(() => TestJsonModel.Transform(model)); + Assert.ThrowsExactly(() => TestJsonModel.Transform(model)); } }