diff --git a/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs b/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs index 165b19d..a5d4812 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Concurrent/AsyncQueueTests.cs @@ -1,4 +1,4 @@ -namespace LuYao.Collections.Concurrent; +namespace LuYao.Collections.Concurrent; [TestClass] public class AsyncQueueTests @@ -53,7 +53,7 @@ public async Task DequeueAsync_NoItem_CancellationTokenTriggersException() cts.Cancel(); // Act & Assert - await Assert.ThrowsExceptionAsync(async () => + await Assert.ThrowsAsync(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 d6d3c07..4e6e9e8 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.Throws(() => _ = input.SplitToBatch(2).ToList()); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SplitToBatch_BatchSizeZero_ThrowsArgumentOutOfRangeException() { var input = Enumerable.Range(1, 3); - _ = input.SplitToBatch(0).ToList(); + Assert.Throws(() => _ = input.SplitToBatch(0).ToList()); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SplitToBatch_BatchSizeNegative_ThrowsArgumentOutOfRangeException() { var input = Enumerable.Range(1, 3); - _ = input.SplitToBatch(-1).ToList(); + Assert.Throws(() => _ = 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..23c94df 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Generic/KeyedListTests.cs @@ -63,13 +63,10 @@ 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.Throws(() => new KeyedList(null!)); } #endregion @@ -87,13 +84,10 @@ 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.Throws(() => { var item = _keyedList[-1]; }); } [TestMethod] @@ -110,16 +104,13 @@ 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.Throws(() => _keyedList[10] = newItem); } #endregion @@ -375,39 +366,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.Throws(() => _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.Throws(() => _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.Throws(() => _keyedList.CopyTo(array, 0)); } #endregion @@ -482,29 +464,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.Throws(() => _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.Throws(() => _keyedList.Insert(_keyedList.Count + 1, newItem)); } #endregion @@ -562,23 +538,17 @@ public void RemoveAt_ValidIndex_RemovesItemAtIndex() } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RemoveAt_NegativeIndex_ThrowsArgumentOutOfRangeException() { - // Act - _keyedList.RemoveAt(-1); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.Throws(() => _keyedList.RemoveAt(-1)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RemoveAt_IndexEqualToCount_ThrowsArgumentOutOfRangeException() { - // Act - _keyedList.RemoveAt(_keyedList.Count); - - // Assert: 期望抛出 ArgumentOutOfRangeException + // Act & Assert + Assert.Throws(() => _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..031420e 100644 --- a/tests/LuYao.Common.UnitTests/Collections/Generic/WeakCollectionTests.cs +++ b/tests/LuYao.Common.UnitTests/Collections/Generic/WeakCollectionTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -16,7 +16,7 @@ public void Add_NullItem_ThrowsArgumentNullException() var collection = new WeakCollection(); // Act & Assert - Assert.ThrowsException(() => collection.Add(null)); + Assert.Throws(() => collection.Add(null)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs b/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs index cfdae7b..9e5780d 100644 --- a/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/GenericMethodTests.cs @@ -1,16 +1,16 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; namespace LuYao.Data; /// -/// 测试泛型 Set 和 To 方法的功能和性能 +/// Է Set To Ĺܺ /// [TestClass] public class GenericMethodTests { /// - /// 测试 RecordColumn 的泛型 Set 方法 + /// RecordColumn ķ Set /// [TestMethod] public void RecordColumn_GenericSet_ShouldWorkWithAllTypes() @@ -26,7 +26,7 @@ public void RecordColumn_GenericSet_ShouldWorkWithAllTypes() var row = record.AddRow(); var rowIndex = 0; - // Act & Assert - 测试所有基础类型 + // Act & Assert - л intColumn.Set(42, rowIndex); Assert.AreEqual(42, intColumn.Get(rowIndex)); @@ -45,7 +45,7 @@ public void RecordColumn_GenericSet_ShouldWorkWithAllTypes() } /// - /// 测试 RecordRow 的泛型 Set 方法 + /// RecordRow ķ Set /// [TestMethod] public void RecordRow_GenericSet_ShouldWorkWithAllTypes() @@ -70,7 +70,7 @@ public void RecordRow_GenericSet_ShouldWorkWithAllTypes() /// - /// 测试 To 泛型方法 + /// To ͷ /// [TestMethod] public void GenericTo_ShouldReturnCorrectTypes() @@ -81,7 +81,7 @@ public void GenericTo_ShouldReturnCorrectTypes() var stringColumn = record.Columns.Add("StringColumn"); var row = record.AddRow(); - // 设置一些测试数据 + // һЩ intColumn.Set(42); stringColumn.Set("Hello"); @@ -92,11 +92,11 @@ public void GenericTo_ShouldReturnCorrectTypes() string stringValue = stringColumn.Get(0); Assert.AreEqual("Hello", stringValue); - // 测试类型转换 + // ת string intAsString = intColumn.Get(0); Assert.AreEqual("42", intAsString); - // 通过 RecordRow 测试 + // ͨ RecordRow int intFromRow = row.Get(intColumn); Assert.AreEqual(42, intFromRow); @@ -105,7 +105,7 @@ public void GenericTo_ShouldReturnCorrectTypes() } /// - /// 测试可空类型支持 + /// Կɿ֧ /// [TestMethod] public void GenericMethods_NullableTypes_ShouldWork() @@ -115,19 +115,19 @@ public void GenericMethods_NullableTypes_ShouldWork() var intColumn = record.Columns.Add("IntColumn"); var row = record.AddRow(); - // Act & Assert - 测试可空类型 + // Act & Assert - Կɿ int? nullableValue = 42; intColumn.SetValue(nullableValue, 0); Assert.AreEqual(42, intColumn.Get(0)); - // 测试 null 值处理 + // null ֵ intColumn.SetValue(null, 0); int defaultValue = intColumn.Get(0); - Assert.AreEqual(0, defaultValue); // 默认值 + Assert.AreEqual(0, defaultValue); // Ĭֵ } /// - /// 测试边界情况 + /// Ա߽ /// [TestMethod] public void GenericMethods_EdgeCases_ShouldHandleCorrectly() @@ -137,18 +137,18 @@ public void GenericMethods_EdgeCases_ShouldHandleCorrectly() var stringColumn = record.Columns.Add("StringColumn"); var row = record.AddRow(); - // Act & Assert - 测试空字符串 + // Act & Assert - Կַ stringColumn.Set("", 0); Assert.AreEqual("", stringColumn.Get(0)); - // 测试 null 字符串 + // null ַ stringColumn.Set(null, 0); string result = stringColumn.Get(0); - Assert.IsNull(result); // 应该返回 null + Assert.IsNull(result); // Ӧ÷ null } /// - /// 测试索引验证 + /// ֤ /// [TestMethod] public void GenericSet_InvalidIndex_ShouldThrowException() @@ -156,18 +156,18 @@ public void GenericSet_InvalidIndex_ShouldThrowException() // Arrange var record = new Record("TestTable", 1); var intColumn = record.Columns.Add("IntColumn"); - record.AddRow(); // 只有一行,有效索引是 0 + record.AddRow(); // ֻһУЧ 0 // Act & Assert - Assert.ThrowsException(() => - intColumn.Set(42, 1)); // 无效索引 + Assert.Throws(() => + intColumn.Set(42, 1)); // Ч - Assert.ThrowsException(() => - intColumn.Set(42, -1)); // 负索引 + Assert.Throws(() => + intColumn.Set(42, -1)); // } /// - /// 性能对比测试 - 展示泛型方法相对于通用方法的优势 + /// ܶԱȲ - չʾͷͨ÷ /// [TestMethod] public void GenericMethods_PerformanceComparison() @@ -176,19 +176,19 @@ public void GenericMethods_PerformanceComparison() var record = new Record("PerfTest", 1000); var intColumn = record.Columns.Add("IntColumn"); - // 添加 1000 行 + // 1000 for (int i = 0; i < 1000; i++) { record.AddRow(); } - //预热 + //Ԥ intColumn.Set(0, 0); intColumn.SetValue(1, 1); var sw = System.Diagnostics.Stopwatch.StartNew(); - // 测试泛型方法性能 + // Էͷ sw.Restart(); for (int i = 0; i < 1000; i++) { @@ -196,7 +196,7 @@ public void GenericMethods_PerformanceComparison() } var genericTime = sw.ElapsedTicks; - // 测试通用方法性能 + // ͨ÷ sw.Restart(); for (int i = 0; i < 1000; i++) { @@ -206,24 +206,24 @@ public void GenericMethods_PerformanceComparison() sw.Stop(); - // 验证结果正确性 + // ֤ȷ for (int i = 0; i < 1000; i++) { Assert.AreEqual(i, intColumn.Get(i)); } - // 输出性能对比(调试信息) - System.Diagnostics.Debug.WriteLine($"泛型方法耗时: {genericTime} ticks"); - System.Diagnostics.Debug.WriteLine($"通用方法耗时: {objectTime} ticks"); - System.Diagnostics.Debug.WriteLine($"性能提升: {(double)objectTime / genericTime:F2}x"); + // ܶԱȣϢ + System.Diagnostics.Debug.WriteLine($"ͷʱ: {genericTime} ticks"); + System.Diagnostics.Debug.WriteLine($"ͨ÷ʱ: {objectTime} ticks"); + System.Diagnostics.Debug.WriteLine($": {(double)objectTime / genericTime:F2}x"); - // 泛型方法应该更快(允许一定的测量误差) + // ͷӦø죨һIJ Assert.IsTrue(genericTime <= objectTime * 1.5, - $"泛型方法性能应该优于或接近通用方法。泛型: {genericTime}, 通用: {objectTime}"); + $"ͷӦڻӽͨ÷: {genericTime}, ͨ: {objectTime}"); } /// - /// 测试不同数据类型的转换矩阵 + /// Բͬ͵ת /// [TestMethod] public void GenericMethods_TypeConversionMatrix_ShouldWork() @@ -237,25 +237,25 @@ public void GenericMethods_TypeConversionMatrix_ShouldWork() var row = record.AddRow(); - // Act & Assert - 测试各种类型转换 + // Act & Assert - Ըת - // int -> 其他类型 + // int -> intColumn.Set(42, 0); Assert.AreEqual(42.0, intColumn.Get(0), 0.001); Assert.AreEqual("42", intColumn.Get(0)); - Assert.AreEqual(true, intColumn.Get(0)); // 非零值为 true + Assert.AreEqual(true, intColumn.Get(0)); // ֵΪ true - // double -> 其他类型 + // double -> doubleColumn.Set(3.14, 0); - Assert.AreEqual(3, doubleColumn.Get(0)); // 截断 + Assert.AreEqual(3, doubleColumn.Get(0)); // ض Assert.AreEqual("3.14", doubleColumn.Get(0)); - // string -> 其他类型 + // string -> stringColumn.Set("123", 0); Assert.AreEqual(123, stringColumn.Get(0)); Assert.AreEqual(123.0, stringColumn.Get(0), 0.001); - // bool -> 其他类型 + // bool -> boolColumn.Set(true, 0); Assert.AreEqual(1, boolColumn.Get(0)); Assert.AreEqual("True", boolColumn.Get(0)); diff --git a/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs index 7fb0fc7..aae2815 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordLoaderTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -11,7 +11,7 @@ namespace LuYao.Data; public class RecordLoaderTests { /// - /// 测试用的实体类 + /// õʵ /// public class TestEntity { @@ -29,7 +29,7 @@ public class TestEntity } /// - /// 测试用的简单实体类 + /// õļʵ /// public class SimpleEntity { @@ -38,13 +38,13 @@ public class SimpleEntity } /// - /// 创建测试用的 Record 和数据 + /// õ Record /// private (Record record, RecordRow row) CreateTestRecord() { var record = new Record("TestTable", 1); - // 添加列 + // var idColumn = record.Columns.Add("Id"); var nameColumn = record.Columns.Add("Name"); var createTimeColumn = record.Columns.Add("CreateTime"); @@ -54,16 +54,16 @@ public class SimpleEntity var nullableIntColumn = record.Columns.Add("NullableInt"); var nullableDateTimeColumn = record.Columns.Add("NullableDateTime"); - // 添加一行数据 + // һ var row = record.AddRow(); - // 设置数据 + // idColumn.Set(123); - nameColumn.Set("测试名称"); + nameColumn.Set(""); createTimeColumn.Set(new DateTime(2023, 7, 28, 10, 30, 0)); isActiveColumn.Set(true); scoreColumn.Set(95.5); - customColumn.Set("自定义值"); + customColumn.Set("Զֵ"); nullableIntColumn.Set(456); nullableDateTimeColumn.Set(new DateTime(2023, 8, 1)); @@ -71,7 +71,7 @@ public class SimpleEntity } /// - /// 测试 Populate 方法 - 基本数据类型填充 + /// Populate - /// [TestMethod] public void Populate_BasicDataTypes_ShouldFillEntityCorrectly() @@ -85,17 +85,17 @@ public void Populate_BasicDataTypes_ShouldFillEntityCorrectly() // Assert Assert.AreEqual(123, entity.Id); - Assert.AreEqual("测试名称", entity.Name); + Assert.AreEqual("", entity.Name); Assert.AreEqual(new DateTime(2023, 7, 28, 10, 30, 0), entity.CreateTime); Assert.AreEqual(true, entity.IsActive); - Assert.AreEqual(95.5, entity.Score, 0.001); // 浮点数比较 - Assert.AreEqual("自定义值", entity.CustomField); + Assert.AreEqual(95.5, entity.Score, 0.001); // Ƚ + Assert.AreEqual("Զֵ", entity.CustomField); Assert.AreEqual(456, entity.NullableInt); Assert.AreEqual(new DateTime(2023, 8, 1), entity.NullableDateTime); } /// - /// 测试 Populate 方法 - 列不存在的情况 + /// Populate - вڵ /// [TestMethod] public void Populate_MissingColumns_ShouldNotThrowException() @@ -108,7 +108,7 @@ public void Populate_MissingColumns_ShouldNotThrowException() var entity = new TestEntity { - Name = "原始名称", + Name = "ԭʼ", Score = 50.0 }; @@ -116,13 +116,13 @@ public void Populate_MissingColumns_ShouldNotThrowException() RecordLoader.Populate(row, entity); // Assert - Assert.AreEqual(100, entity.Id); // Id 列存在,应该被填充 - Assert.AreEqual("原始名称", entity.Name); // Name 列不存在,保持原值 - Assert.AreEqual(50.0, entity.Score); // Score 列不存在,保持原值 + Assert.AreEqual(100, entity.Id); // Id дڣӦñ + Assert.AreEqual("ԭʼ", entity.Name); // Name вڣԭֵ + Assert.AreEqual(50.0, entity.Score); // Score вڣԭֵ } /// - /// 测试 WriteData 方法 - 基本数据写入 + /// WriteData - д /// [TestMethod] public void WriteData_BasicDataTypes_ShouldWriteToRecordCorrectly() @@ -130,7 +130,7 @@ public void WriteData_BasicDataTypes_ShouldWriteToRecordCorrectly() // Arrange var record = new Record("TestTable", 1); - // 添加列 + // var idColumn = record.Columns.Add("Id"); var nameColumn = record.Columns.Add("Name"); var createTimeColumn = record.Columns.Add("CreateTime"); @@ -144,11 +144,11 @@ public void WriteData_BasicDataTypes_ShouldWriteToRecordCorrectly() var entity = new TestEntity { Id = 789, - Name = "写入测试", + Name = "д", CreateTime = new DateTime(2023, 9, 15, 14, 20, 30), IsActive = false, Score = 88.8, - CustomField = "写入自定义", + CustomField = "дԶ", NullableInt = 999 }; @@ -157,16 +157,16 @@ public void WriteData_BasicDataTypes_ShouldWriteToRecordCorrectly() // Assert Assert.AreEqual(789, row.Get(idColumn)); - Assert.AreEqual("写入测试", row.Get(nameColumn)); + Assert.AreEqual("д", row.Get(nameColumn)); Assert.AreEqual(new DateTime(2023, 9, 15, 14, 20, 30), row.Get(createTimeColumn)); Assert.AreEqual(false, row.Get(isActiveColumn)); Assert.AreEqual(88.8, row.Get(scoreColumn), 0.001); - Assert.AreEqual("写入自定义", row.Get(customColumn)); + Assert.AreEqual("дԶ", row.Get(customColumn)); Assert.AreEqual(999, row.Get(nullableIntColumn)); } /// - /// 测试 WriteData 方法 - 列不存在的情况 + /// WriteData - вڵ /// [TestMethod] public void WriteData_MissingColumns_ShouldNotThrowException() @@ -179,28 +179,28 @@ public void WriteData_MissingColumns_ShouldNotThrowException() var entity = new TestEntity { Id = 555, - Name = "部分写入", + Name = "д", Score = 77.7 }; - // Act & Assert - 不应该抛出异常 + // Act & Assert - Ӧ׳쳣 RecordLoader.WriteToRow(entity, row); - // 验证存在的列被正确写入 + // ֤ڵбȷд Assert.AreEqual(555, row.Get(idColumn)); } /// - /// 测试 RecordColumnNameAttribute 特性 + /// RecordColumnNameAttribute /// [TestMethod] public void Populate_WithRecordColumnNameAttribute_ShouldUseAttributeName() { // Arrange var record = new Record("TestTable", 1); - var customColumn = record.Columns.Add("custom_column"); // 使用特性指定的名称 + var customColumn = record.Columns.Add("custom_column"); // ʹָ var row = record.AddRow(); - customColumn.Set("特性测试值"); + customColumn.Set("Բֵ"); var entity = new TestEntity(); @@ -208,11 +208,11 @@ public void Populate_WithRecordColumnNameAttribute_ShouldUseAttributeName() RecordLoader.Populate(row, entity); // Assert - Assert.AreEqual("特性测试值", entity.CustomField); + Assert.AreEqual("Բֵ", entity.CustomField); } /// - /// 测试可空类型的处理 + /// Կɿ͵Ĵ /// [TestMethod] public void Populate_NullableTypes_ShouldHandleNullValues() @@ -223,26 +223,26 @@ public void Populate_NullableTypes_ShouldHandleNullValues() var nullableDateTimeColumn = record.Columns.Add("NullableDateTime"); var row = record.AddRow(); - // 设置为 null 值(通过不设置任何值来模拟 null) + // Ϊ null ֵͨκֵģ null var entity = new TestEntity { - NullableInt = 100, // 设置初始值 - NullableDateTime = DateTime.Now // 设置初始值 + NullableInt = 100, // óʼֵ + NullableDateTime = DateTime.Now // óʼֵ }; // Act RecordLoader.Populate(row, entity); // Assert - // 注意:由于 Record 系统的实现可能不直接支持 null 值, - // 这里主要测试不会抛出异常 - // 具体的 null 处理逻辑取决于底层 ColumnData 的实现 - Assert.IsNotNull(entity); // 基本的非空验证 + // ע⣺ Record ϵͳʵֱֿ֧ܲ null ֵ + // ҪԲ׳쳣 + // null ߼ȡڵײ ColumnData ʵ + Assert.IsNotNull(entity); // ķǿ֤ } /// - /// 测试往返转换(Round-trip) + /// תRound-trip /// [TestMethod] public void PopulateAndWriteData_RoundTrip_ShouldMaintainDataIntegrity() @@ -251,25 +251,25 @@ public void PopulateAndWriteData_RoundTrip_ShouldMaintainDataIntegrity() var originalEntity = new TestEntity { Id = 999, - Name = "往返测试", + Name = "", CreateTime = new DateTime(2023, 12, 25, 18, 30, 45), IsActive = true, Score = 92.3, - CustomField = "往返自定义", + CustomField = "Զ", NullableInt = 777 }; var record = new Record("TestTable", 1); - // 使用 WriteHeader 方法添加列 + // ʹ WriteHeader RecordLoader.WriteHeader(record); var row = record.AddRow(); - // Act - 写入 Record + // Act - д Record RecordLoader.WriteToRow(originalEntity, row); - // Act - 从 Record 读取到新实体 + // Act - Record ȡʵ var newEntity = new TestEntity(); RecordLoader.Populate(row, newEntity); @@ -284,7 +284,7 @@ public void PopulateAndWriteData_RoundTrip_ShouldMaintainDataIntegrity() } /// - /// 测试简单实体类 + /// Լʵ /// [TestMethod] public void SimpleEntity_PopulateAndWrite_ShouldWorkCorrectly() @@ -296,7 +296,7 @@ public void SimpleEntity_PopulateAndWrite_ShouldWorkCorrectly() var row = record.AddRow(); valueColumn.Set(42); - textColumn.Set("简单测试"); + textColumn.Set("򵥲"); var entity = new SimpleEntity(); @@ -305,35 +305,35 @@ public void SimpleEntity_PopulateAndWrite_ShouldWorkCorrectly() // Assert Assert.AreEqual(42, entity.Value); - Assert.AreEqual("简单测试", entity.Text); + Assert.AreEqual("򵥲", entity.Text); } /// - /// 测试静态构造函数只执行一次 + /// Ծ̬캯ִֻһ /// [TestMethod] public void StaticConstructor_ShouldExecuteOnlyOnce() { // Arrange & Act var record = new Record("TestTable", 1); - var idColumn = record.Columns.Add("Value"); // 修正列名 + var idColumn = record.Columns.Add("Value"); // var row = record.AddRow(); idColumn.Set(1); var entity1 = new SimpleEntity(); var entity2 = new SimpleEntity(); - // Act - 多次调用应该使用同一个编译后的委托 + // Act - εӦʹͬһί RecordLoader.Populate(row, entity1); RecordLoader.Populate(row, entity2); - // Assert - 验证两次调用都成功(间接验证静态构造函数正确执行) + // Assert - ֤εöɹ֤̬캯ȷִУ Assert.AreEqual(1, entity1.Value); Assert.AreEqual(1, entity2.Value); } /// - /// 测试 WriteHeader 方法 + /// WriteHeader /// [TestMethod] public void WriteHeader_ShouldCreateCorrectColumns() @@ -350,13 +350,13 @@ public void WriteHeader_ShouldCreateCorrectColumns() Assert.IsTrue(record.Columns.Contains("CreateTime")); Assert.IsTrue(record.Columns.Contains("IsActive")); Assert.IsTrue(record.Columns.Contains("Score")); - Assert.IsTrue(record.Columns.Contains("custom_column")); // 使用特性指定的名称 + Assert.IsTrue(record.Columns.Contains("custom_column")); // ʹָ Assert.IsTrue(record.Columns.Contains("NullableInt")); Assert.IsTrue(record.Columns.Contains("NullableDateTime")); } /// - /// 测试 WriteHeader 方法 - 验证列的数据类型 + /// WriteHeader - ֤е /// [TestMethod] public void WriteHeader_ShouldCreateColumnsWithCorrectTypes() @@ -402,7 +402,7 @@ public void WriteHeader_ShouldCreateColumnsWithCorrectTypes() } /// - /// 测试 WriteHeader 方法 - 验证列的数量 + /// WriteHeader - ֤е /// [TestMethod] public void WriteHeader_ShouldCreateCorrectNumberOfColumns() @@ -414,12 +414,12 @@ public void WriteHeader_ShouldCreateCorrectNumberOfColumns() RecordLoader.WriteHeader(record); // Assert - // TestEntity 有 8 个可读写属性 + // TestEntity 8 ɶд Assert.AreEqual(8, record.Columns.Count); } /// - /// 测试 WriteHeader 方法 - 简单实体类 + /// WriteHeader - ʵ /// [TestMethod] public void WriteHeader_SimpleEntity_ShouldCreateCorrectColumns() @@ -445,7 +445,7 @@ public void WriteHeader_SimpleEntity_ShouldCreateCorrectColumns() } /// - /// 测试 WriteHeader 方法 - 空 Record + /// WriteHeader - Record /// [TestMethod] public void WriteHeader_EmptyRecord_ShouldPopulateColumns() @@ -463,7 +463,7 @@ public void WriteHeader_EmptyRecord_ShouldPopulateColumns() } /// - /// 测试 WriteHeader 方法 - 多次调用不会重复添加列 + /// WriteHeader - εòظ /// [TestMethod] public void WriteHeader_CalledTwice_ShouldThrowException() @@ -473,15 +473,15 @@ public void WriteHeader_CalledTwice_ShouldThrowException() RecordLoader.WriteHeader(record); // Act & Assert - // 第二次调用应该抛出异常,因为列已经存在 - Assert.ThrowsException(() => + // ڶεӦ׳쳣ΪѾ + Assert.Throws(() => { RecordLoader.WriteHeader(record); }); } /// - /// 测试用的只读属性实体类 + /// õֻʵ /// public class ReadOnlyEntity { @@ -491,7 +491,7 @@ public int WriteOnlyProperty { set { } } } /// - /// 测试 WriteHeader 方法 - 只包含可读写属性 + /// WriteHeader - ֻɶд /// [TestMethod] public void WriteHeader_ReadOnlyEntity_ShouldOnlyIncludeReadWriteProperties() @@ -503,15 +503,15 @@ public void WriteHeader_ReadOnlyEntity_ShouldOnlyIncludeReadWriteProperties() RecordLoader.WriteHeader(record); // Assert - // 只有 Name 属性是可读写的 + // ֻ Name ǿɶд Assert.AreEqual(1, record.Columns.Count); Assert.IsTrue(record.Columns.Contains("Name")); - Assert.IsFalse(record.Columns.Contains("Id")); // 只读属性 - Assert.IsFalse(record.Columns.Contains("WriteOnlyProperty")); // 只写属性 + Assert.IsFalse(record.Columns.Contains("Id")); // ֻ + Assert.IsFalse(record.Columns.Contains("WriteOnlyProperty")); // ֻд } /// - /// 测试用的复杂类型实体类 + /// õĸʵ /// public class ComplexTypeEntity { @@ -522,7 +522,7 @@ public class ComplexTypeEntity } /// - /// 测试 WriteHeader 方法 - 复杂数据类型 + /// WriteHeader - /// [TestMethod] public void WriteHeader_ComplexTypeEntity_ShouldHandleComplexTypes() @@ -558,7 +558,7 @@ public void WriteHeader_ComplexTypeEntity_ShouldHandleComplexTypes() } /// - /// 测试 WriteHeader 方法与 WriteData 方法的兼容性 + /// WriteHeader WriteData ļ /// [TestMethod] public void WriteHeader_WithWriteData_ShouldBeCompatible() @@ -568,11 +568,11 @@ public void WriteHeader_WithWriteData_ShouldBeCompatible() var entity = new TestEntity { Id = 123, - Name = "兼容性测试", + Name = "Բ", CreateTime = DateTime.Now, IsActive = true, Score = 95.5, - CustomField = "自定义值", + CustomField = "Զֵ", NullableInt = 456 }; @@ -582,7 +582,7 @@ public void WriteHeader_WithWriteData_ShouldBeCompatible() RecordLoader.WriteToRow(entity, row); // Assert - // 验证所有列都能正确写入数据 + // ֤жȷд Assert.AreEqual(entity.Id, row.Get("Id")); Assert.AreEqual(entity.Name, row.Get(("Name")!)); Assert.AreEqual(entity.CreateTime, row.Get(("CreateTime")!)); diff --git a/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordObjectTests.cs index 9c32601..8988abb 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.Throws(() => 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.Throws(() => 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.Throws(() => 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..2b6a170 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordRowTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordRowTests.cs @@ -1,16 +1,16 @@ -using System; +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace LuYao.Data; /// -/// RecordRow 结构体的单元测试类 +/// RecordRow ṹĵԪ /// [TestClass] public class RecordRowTests { /// - /// 创建测试用的 Record 和相关数据 + /// õ Record /// private (Record record, RecordColumn intColumn, RecordColumn stringColumn, RecordColumn boolColumn) CreateTestRecord() { @@ -19,7 +19,7 @@ public class RecordRowTests var stringColumn = record.Columns.Add("StringColumn"); var boolColumn = record.Columns.Add("BoolColumn"); - // 添加测试数据 + // Ӳ var row1 = record.AddRow(); var row2 = record.AddRow(); @@ -33,10 +33,10 @@ public class RecordRowTests return (record, intColumn, stringColumn, boolColumn); } - #region 构造函数测试 + #region 캯 /// - /// 测试构造函数 - 正常参数 + /// Թ캯 - /// [TestMethod] public void Constructor_ValidParameters_ShouldInitializeCorrectly() @@ -53,17 +53,17 @@ public void Constructor_ValidParameters_ShouldInitializeCorrectly() } /// - /// 测试构造函数 - Record 为 null + /// Թ캯 - Record Ϊ null /// [TestMethod] public void Constructor_NullRecord_ShouldThrowArgumentNullException() { // Act & Assert - Assert.ThrowsException(() => new RecordRow(null!, 0)); + Assert.Throws(() => new RecordRow(null!, 0)); } /// - /// 测试构造函数 - 行索引小于0 + /// Թ캯 - С0 /// [TestMethod] public void Constructor_NegativeRowIndex_ShouldThrowArgumentOutOfRangeException() @@ -72,11 +72,11 @@ public void Constructor_NegativeRowIndex_ShouldThrowArgumentOutOfRangeException( var (record, _, _, _) = CreateTestRecord(); // Act & Assert - Assert.ThrowsException(() => new RecordRow(record, -1)); + Assert.Throws(() => new RecordRow(record, -1)); } /// - /// 测试构造函数 - 行索引等于或大于 Record.Count + /// Թ캯 - ڻ Record.Count /// [TestMethod] public void Constructor_RowIndexOutOfRange_ShouldThrowArgumentOutOfRangeException() @@ -85,16 +85,16 @@ 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.Throws(() => new RecordRow(record, record.Count)); + Assert.Throws(() => new RecordRow(record, record.Count + 1)); } #endregion - #region 属性测试 + #region Բ /// - /// 测试 Record 属性 + /// Record /// [TestMethod] public void Record_Property_ShouldReturnCorrectRecord() @@ -111,7 +111,7 @@ public void Record_Property_ShouldReturnCorrectRecord() } /// - /// 测试 Row 属性 + /// Row /// [TestMethod] public void Row_Property_ShouldReturnCorrectRowIndex() @@ -129,10 +129,10 @@ public void Row_Property_ShouldReturnCorrectRowIndex() #endregion - #region 隐式转换测试 + #region ʽת /// - /// 测试隐式转换到 int + /// ʽת int /// [TestMethod] public void ImplicitConversion_ToInt_ShouldReturnRowIndex() @@ -150,10 +150,10 @@ public void ImplicitConversion_ToInt_ShouldReturnRowIndex() #endregion - #region GetBoolean 测试 + #region GetBoolean /// - /// 测试 GetBoolean(string name) - 列存在 + /// GetBoolean(string name) - д /// [TestMethod] public void GetBoolean_ByName_ColumnExists_ShouldReturnCorrectValue() @@ -170,7 +170,7 @@ public void GetBoolean_ByName_ColumnExists_ShouldReturnCorrectValue() } /// - /// 测试 GetBoolean(string name) - 列不存在 + /// GetBoolean(string name) - в /// [TestMethod] public void GetBoolean_ByName_ColumnNotExists_ShouldReturnDefault() @@ -187,7 +187,7 @@ public void GetBoolean_ByName_ColumnNotExists_ShouldReturnDefault() } /// - /// 测试 GetBoolean(RecordColumn col) - 列属于当前记录 + /// GetBoolean(RecordColumn col) - ڵǰ¼ /// [TestMethod] public void GetBoolean_ByColumn_SameRecord_ShouldReturnCorrectValue() @@ -204,7 +204,7 @@ public void GetBoolean_ByColumn_SameRecord_ShouldReturnCorrectValue() } /// - /// 测试 GetBoolean(RecordColumn col) - 列属于不同记录 + /// GetBoolean(RecordColumn col) - ڲͬ¼ /// [TestMethod] public void GetBoolean_ByColumn_DifferentRecord_ShouldFallbackToNameSearch() @@ -218,15 +218,15 @@ public void GetBoolean_ByColumn_DifferentRecord_ShouldFallbackToNameSearch() var result = recordRow.Get(boolColumn2); // Assert - Assert.AreEqual(true, result); // 应该通过列名查找到 record1 中的 BoolColumn + Assert.AreEqual(true, result); // Ӧͨҵ record1 е BoolColumn } #endregion - #region GetString 测试 + #region GetString /// - /// 测试 GetString(string name) - 列存在 + /// GetString(string name) - д /// [TestMethod] public void GetString_ByName_ColumnExists_ShouldReturnCorrectValue() @@ -243,7 +243,7 @@ public void GetString_ByName_ColumnExists_ShouldReturnCorrectValue() } /// - /// 测试 GetString(string name) - 列不存在 + /// GetString(string name) - в /// [TestMethod] public void GetString_ByName_ColumnNotExists_ShouldReturnDefault() @@ -260,7 +260,7 @@ public void GetString_ByName_ColumnNotExists_ShouldReturnDefault() } /// - /// 测试 GetString(RecordColumn col) - 列属于当前记录 + /// GetString(RecordColumn col) - ڵǰ¼ /// [TestMethod] public void GetString_ByColumn_SameRecord_ShouldReturnCorrectValue() @@ -278,10 +278,10 @@ public void GetString_ByColumn_SameRecord_ShouldReturnCorrectValue() #endregion - #region GetInt32 测试 + #region GetInt32 /// - /// 测试 GetInt32(string name) - 列存在 + /// GetInt32(string name) - д /// [TestMethod] public void GetInt32_ByName_ColumnExists_ShouldReturnCorrectValue() @@ -298,7 +298,7 @@ public void GetInt32_ByName_ColumnExists_ShouldReturnCorrectValue() } /// - /// 测试 GetInt32(string name) - 列不存在 + /// GetInt32(string name) - в /// [TestMethod] public void GetInt32_ByName_ColumnNotExists_ShouldReturnDefault() @@ -315,7 +315,7 @@ public void GetInt32_ByName_ColumnNotExists_ShouldReturnDefault() } /// - /// 测试 GetInt32(RecordColumn col) - 列属于当前记录 + /// GetInt32(RecordColumn col) - ڵǰ¼ /// [TestMethod] public void GetInt32_ByColumn_SameRecord_ShouldReturnCorrectValue() @@ -333,10 +333,10 @@ public void GetInt32_ByColumn_SameRecord_ShouldReturnCorrectValue() #endregion - #region 泛型 Get 测试 + #region Get /// - /// 测试 Get(string name) - 列存在 + /// Get(string name) - д /// [TestMethod] public void GetGeneric_ByName_ColumnExists_ShouldReturnCorrectValue() @@ -353,7 +353,7 @@ public void GetGeneric_ByName_ColumnExists_ShouldReturnCorrectValue() } /// - /// 测试 Get(string name) - 列不存在 + /// Get(string name) - в /// [TestMethod] public void GetGeneric_ByName_ColumnNotExists_ShouldReturnDefault() @@ -370,7 +370,7 @@ public void GetGeneric_ByName_ColumnNotExists_ShouldReturnDefault() } /// - /// 测试 Get(RecordColumn col) - 列属于当前记录 + /// Get(RecordColumn col) - ڵǰ¼ /// [TestMethod] public void GetGeneric_ByColumn_SameRecord_ShouldReturnCorrectValue() @@ -389,10 +389,10 @@ public void GetGeneric_ByColumn_SameRecord_ShouldReturnCorrectValue() #endregion - #region 数值类型测试 (抽样测试) + #region ֵͲ () /// - /// 测试 GetByte 方法 + /// GetByte /// [TestMethod] public void GetByte_ByName_ShouldWork() @@ -412,7 +412,7 @@ public void GetByte_ByName_ShouldWork() } /// - /// 测试 GetDouble 方法 + /// GetDouble /// [TestMethod] public void GetDouble_ByName_ShouldWork() @@ -432,7 +432,7 @@ public void GetDouble_ByName_ShouldWork() } /// - /// 测试 GetDateTime 方法 + /// GetDateTime /// [TestMethod] public void GetDateTime_ByName_ShouldWork() @@ -454,10 +454,10 @@ public void GetDateTime_ByName_ShouldWork() #endregion - #region 边界情况和异常测试 + #region ߽쳣 /// - /// 测试空字符串列名 + /// Կַ /// [TestMethod] public void GetMethods_EmptyColumnName_ShouldReturnDefault() @@ -473,7 +473,7 @@ public void GetMethods_EmptyColumnName_ShouldReturnDefault() } /// - /// 测试多行数据的正确性 + /// Զݵȷ /// [TestMethod] public void GetMethods_MultipleRows_ShouldReturnCorrectValues() @@ -481,7 +481,7 @@ public void GetMethods_MultipleRows_ShouldReturnCorrectValues() // Arrange var (record, intColumn, stringColumn, boolColumn) = CreateTestRecord(); - // 添加更多测试数据 + // Ӹ var row3 = record.AddRow(); intColumn.Set(300); stringColumn.Set("Test3"); @@ -507,10 +507,10 @@ public void GetMethods_MultipleRows_ShouldReturnCorrectValues() #endregion - #region 性能和一致性测试 + #region ܺһԲ /// - /// 测试相同数据的重复访问应该返回相同结果 + /// ͬݵظӦ÷ͬ /// [TestMethod] public void GetMethods_RepeatedAccess_ShouldReturnConsistentResults() @@ -531,7 +531,7 @@ public void GetMethods_RepeatedAccess_ShouldReturnConsistentResults() } /// - /// 测试不同获取方式(按名称 vs 按列对象)的结果一致性 + /// Բͬȡʽ( vs ж)Ľһ /// [TestMethod] public void GetMethods_ByNameVsByColumn_ShouldReturnSameResults() diff --git a/tests/LuYao.Common.UnitTests/Data/RecordTests.cs b/tests/LuYao.Common.UnitTests/Data/RecordTests.cs index 90c1752..1e8386d 100644 --- a/tests/LuYao.Common.UnitTests/Data/RecordTests.cs +++ b/tests/LuYao.Common.UnitTests/Data/RecordTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -27,8 +27,8 @@ public void AddRowAndSetColumnValue_WorksCorrectly() { // Arrange var table = new Record(); - var colId = table.Columns.Add("Id"); // 替换 Add 为 Add - var colName = table.Columns.Add("Name"); // 替换 Add 为 Add + var colId = table.Columns.Add("Id"); // 滻 Add Ϊ Add + var colName = table.Columns.Add("Name"); // 滻 Add Ϊ Add // Act var row = table.AddRow(); @@ -38,8 +38,8 @@ public void AddRowAndSetColumnValue_WorksCorrectly() // Assert Assert.AreEqual(1, table.Count); Assert.AreEqual(2, table.Columns.Count); - Assert.AreEqual(1, colId.Get(row.Row)); // 替换 GetValue 为 Get - Assert.AreEqual("Test", colName.Get(row.Row)); // 替换 GetValue 为 Get + Assert.AreEqual(1, colId.Get(row.Row)); // 滻 GetValue Ϊ Get + Assert.AreEqual("Test", colName.Get(row.Row)); // 滻 GetValue Ϊ Get } [TestMethod] @@ -60,9 +60,9 @@ public void AddMultipleRowsAndColumns_WorksCorrectly() { // Arrange var table = new Record(); - var colId = table.Columns.Add("Id"); // 替换 Add 为 Add - var colName = table.Columns.Add("Name"); // 替换 Add 为 Add - var colAge = table.Columns.Add("Age"); // 替换 Add 为 Add + var colId = table.Columns.Add("Id"); // 滻 Add Ϊ Add + var colName = table.Columns.Add("Name"); // 滻 Add Ϊ Add + var colAge = table.Columns.Add("Age"); // 滻 Add Ϊ Add // Act var row1 = table.AddRow(); @@ -79,13 +79,13 @@ public void AddMultipleRowsAndColumns_WorksCorrectly() Assert.AreEqual(2, table.Count); Assert.AreEqual(3, table.Columns.Count); - Assert.AreEqual(1, colId.Get(row1.Row)); // 替换 GetValue 为 Get - Assert.AreEqual("Alice", colName.Get(row1.Row)); // 替换 GetValue 为 Get - Assert.AreEqual(25, colAge.Get(row1.Row)); // 替换 GetValue 为 Get + Assert.AreEqual(1, colId.Get(row1.Row)); // 滻 GetValue Ϊ Get + Assert.AreEqual("Alice", colName.Get(row1.Row)); // 滻 GetValue Ϊ Get + Assert.AreEqual(25, colAge.Get(row1.Row)); // 滻 GetValue Ϊ Get - Assert.AreEqual(2, colId.Get(row2.Row)); // 替换 GetValue 为 Get - Assert.AreEqual("Bob", colName.Get(row2.Row)); // 替换 GetValue 为 Get - Assert.AreEqual(30, colAge.Get(row2.Row)); // 替换 GetValue 为 Get + Assert.AreEqual(2, colId.Get(row2.Row)); // 滻 GetValue Ϊ Get + Assert.AreEqual("Bob", colName.Get(row2.Row)); // 滻 GetValue Ϊ Get + Assert.AreEqual(30, colAge.Get(row2.Row)); // 滻 GetValue Ϊ Get } [TestMethod] @@ -277,7 +277,7 @@ public void RowImplicitConversion_WorksCorrectly() var row = rows[1]; // Act - int rowIndex = row; // 隐式转换 + int rowIndex = row; // ʽת // Assert Assert.AreEqual(1, rowIndex); @@ -681,7 +681,7 @@ public void ToString_LongStringValue_TruncatesWithEllipsis() Assert.IsTrue(result.Contains("..") || result.Contains("LongStringTest")); } - // 新增的边界检查测试方法 + // ı߽Է [TestMethod] public void GetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException() @@ -692,8 +692,8 @@ public void GetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.GetValue(-1)); - Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); + var exception = Assert.Throws(() => col.GetValue(-1)); + Assert.IsTrue(exception.Message.Contains(" -1 ЧΧ")); } [TestMethod] @@ -705,8 +705,8 @@ public void GetValue_RowIndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.GetValue(1)); - Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); + var exception = Assert.Throws(() => col.GetValue(1)); + Assert.IsTrue(exception.Message.Contains(" 1 ЧΧ")); } [TestMethod] @@ -718,8 +718,8 @@ public void GetValue_RowIndexGreaterThanCount_ThrowsArgumentOutOfRangeException( table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.GetValue(5)); - Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围")); + var exception = Assert.Throws(() => col.GetValue(5)); + Assert.IsTrue(exception.Message.Contains(" 5 ЧΧ")); } [TestMethod] @@ -731,8 +731,8 @@ public void SetValue_NegativeRowIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.SetValue("test", -1)); - Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); + var exception = Assert.Throws(() => col.SetValue("test", -1)); + Assert.IsTrue(exception.Message.Contains(" -1 ЧΧ")); } [TestMethod] @@ -744,8 +744,8 @@ public void SetValue_RowIndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.SetValue("test", 1)); - Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); + var exception = Assert.Throws(() => col.SetValue("test", 1)); + Assert.IsTrue(exception.Message.Contains(" 1 ЧΧ")); } [TestMethod] @@ -757,8 +757,8 @@ public void SetValue_RowIndexGreaterThanCount_ThrowsArgumentOutOfRangeException( table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.SetValue("test", 5)); - Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围")); + var exception = Assert.Throws(() => col.SetValue("test", 5)); + Assert.IsTrue(exception.Message.Contains(" 5 ЧΧ")); } [TestMethod] @@ -770,8 +770,8 @@ public void SetBoolean_NegativeIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Set(true, -1)); - Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); + var exception = Assert.Throws(() => col.Set(true, -1)); + Assert.IsTrue(exception.Message.Contains(" -1 ЧΧ")); } [TestMethod] @@ -783,8 +783,8 @@ public void SetBoolean_IndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Set(true, 1)); - Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); + var exception = Assert.Throws(() => col.Set(true, 1)); + Assert.IsTrue(exception.Message.Contains(" 1 ЧΧ")); } [TestMethod] @@ -796,8 +796,8 @@ public void SetInt32_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Set(42, 5)); - Assert.IsTrue(exception.Message.Contains("行索引 5 超出有效范围")); + var exception = Assert.Throws(() => col.Set(42, 5)); + Assert.IsTrue(exception.Message.Contains(" 5 ЧΧ")); } [TestMethod] @@ -809,8 +809,8 @@ public void ToBoolean_NegativeIndex_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Get(-1)); - Assert.IsTrue(exception.Message.Contains("行索引 -1 超出有效范围")); + var exception = Assert.Throws(() => col.Get(-1)); + Assert.IsTrue(exception.Message.Contains(" -1 ЧΧ")); } [TestMethod] @@ -822,8 +822,8 @@ public void ToInt32_IndexEqualToCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Get(1)); - Assert.IsTrue(exception.Message.Contains("行索引 1 超出有效范围")); + var exception = Assert.Throws(() => col.Get(1)); + Assert.IsTrue(exception.Message.Contains(" 1 ЧΧ")); } [TestMethod] @@ -835,8 +835,8 @@ public void ToString_IndexGreaterThanCount_ThrowsArgumentOutOfRangeException() table.AddRow(); // Act & Assert - var exception = Assert.ThrowsException(() => col.Get(10)); - Assert.IsTrue(exception.Message.Contains("行索引 10 超出有效范围")); + var exception = Assert.Throws(() => col.Get(10)); + Assert.IsTrue(exception.Message.Contains(" 10 ЧΧ")); } [TestMethod] @@ -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.Throws(() => col.GetValue(3)); + Assert.Throws(() => 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.Throws(() => boolCol.Set(true, 1)); + Assert.Throws(() => byteCol.Set((byte)1, 1)); + Assert.Throws(() => charCol.Set('A', 1)); + Assert.Throws(() => dateTimeCol.Set(DateTime.Now, 1)); + Assert.Throws(() => decimalCol.Set(1.0m, 1)); + Assert.Throws(() => doubleCol.Set(1.0, 1)); + Assert.Throws(() => int16Col.Set((short)1, 1)); + Assert.Throws(() => int32Col.Set(1, 1)); + Assert.Throws(() => int64Col.Set(1L, 1)); + Assert.Throws(() => sbyteCol.Set((sbyte)1, 1)); + Assert.Throws(() => singleCol.Set(1.0f, 1)); + Assert.Throws(() => stringCol.Set("test", 1)); + Assert.Throws(() => uint16Col.Set((ushort)1, 1)); + Assert.Throws(() => uint32Col.Set(1u, 1)); + Assert.Throws(() => uint64Col.Set(1ul, 1)); } [TestMethod] @@ -950,21 +950,21 @@ 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.Throws(() => boolCol.Get(1)); + Assert.Throws(() => byteCol.Get(1)); + Assert.Throws(() => charCol.Get(1)); + Assert.Throws(() => dateTimeCol.Get(1)); + Assert.Throws(() => decimalCol.Get(1)); + Assert.Throws(() => doubleCol.Get(1)); + Assert.Throws(() => int16Col.Get(1)); + Assert.Throws(() => int32Col.Get(1)); + Assert.Throws(() => int64Col.Get(1)); + Assert.Throws(() => sbyteCol.Get(1)); + Assert.Throws(() => singleCol.Get(1)); + Assert.Throws(() => stringCol.Get(1)); + Assert.Throws(() => uint16Col.Get(1)); + Assert.Throws(() => uint32Col.Get(1)); + Assert.Throws(() => uint64Col.Get(1)); } [TestMethod] @@ -976,8 +976,8 @@ public void BoundaryCheck_EmptyTable_AnyIndexThrowsException() // No rows added, Count = 0 // Act & Assert - Assert.ThrowsException(() => col.GetValue(0)); - Assert.ThrowsException(() => col.Get(0)); + Assert.Throws(() => col.GetValue(0)); + Assert.Throws(() => col.Get(0)); } [TestMethod] @@ -989,8 +989,8 @@ 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.Throws(() => col.GetValue(-1)); + Assert.Throws(() => col.SetValue("test", -1)); } [TestMethod] @@ -1002,12 +1002,11 @@ 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.Throws(() => col.Set("test", 1)); + Assert.Throws(() => col.Set("test", 2)); } [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.Throws(() => 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.Throws(() => table.Columns.Add("TestColumn")); // Ӧ׳쳣 } public class Student @@ -1063,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.Throws(() => 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..2785d32 100644 --- a/tests/LuYao.Common.UnitTests/DisposeActionTests.cs +++ b/tests/LuYao.Common.UnitTests/DisposeActionTests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace LuYao; @@ -8,7 +8,7 @@ public class DisposeActionTests [TestMethod] public void Constructor_WhenActionIsNull_ShouldThrowArgumentNullException() { - Assert.ThrowsException(() => new DisposeAction(null!)); + Assert.Throws(() => new DisposeAction(null!)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs index b683024..6aa08a6 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Ascii85Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Text; namespace LuYao.Encoders; @@ -50,7 +50,7 @@ public void Decode_EnforceMarksTrue_MissingMarks_ThrowsException() { var ascii85 = new Ascii85 { EnforceMarks = true }; string encoded = "87cURD_*#4DfTZ"; - Assert.ThrowsException(() => ascii85.Decode(encoded)); + Assert.Throws(() => ascii85.Decode(encoded)); } [TestMethod] @@ -59,7 +59,7 @@ public void Decode_EnforceMarksFalse_WithoutMarks_Works() var ascii85 = new Ascii85 { EnforceMarks = false }; byte[] original = Encoding.UTF8.GetBytes("data"); string encoded = ascii85.Encode(original); - // 去掉前后缀 + // ȥǰ׺ encoded = encoded.TrimStart('<', '~').TrimEnd('~', '>'); byte[] decoded = ascii85.Decode(encoded); CollectionAssert.AreEqual(original, decoded); diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base16Tests.cs index 46f4569..67ff769 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.Throws(() => Base16.FromBase16(input)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void FromBase16_OddLength_ThrowsArgumentOutOfRangeException() { string input = "ABC"; - Base16.FromBase16(input); + Assert.Throws(() => 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..57d0dc0 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.Throws(() => Base32.FromBase32("INVALID*")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs index 65ca2fe..07ec3f3 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base62Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace LuYao.Encoders; @@ -28,7 +28,7 @@ public void ToBase62_SimpleBytes_ReturnsExpectedBase62String() string result = Base62.ToBase62(input); // Assert - // 预期值可通过 FromBase62 验证 + // Ԥֵͨ FromBase62 ֤ CollectionAssert.AreEqual(input, Base62.FromBase62(result)); } @@ -53,7 +53,7 @@ public void FromBase62_EmptyString_ThrowsArgumentNullException() string input = ""; // Act & Assert - Assert.ThrowsException(() => Base62.FromBase62(input)); + Assert.Throws(() => Base62.FromBase62(input)); } [TestMethod] @@ -63,7 +63,7 @@ public void FromBase62_WhitespaceString_ThrowsArgumentNullException() string input = " "; // Act & Assert - Assert.ThrowsException(() => Base62.FromBase62(input)); + Assert.Throws(() => Base62.FromBase62(input)); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs b/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs index 33dfebb..36682de 100644 --- a/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs +++ b/tests/LuYao.Common.UnitTests/Encoders/Base64Tests.cs @@ -73,11 +73,10 @@ public void FromBase64_EmptyString_ReturnsEmptyArray() } [TestMethod] - [ExpectedException(typeof(FormatException))] public void FromBase64_InvalidString_ThrowsFormatException() { - // Act - Base64.FromBase64("!@#$"); + // Act & Assert + Assert.Throws(() => 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..13bce78 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.Throws(() => Enum.Parse("NonExistent")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/GZipStringTests.cs b/tests/LuYao.Common.UnitTests/GZipStringTests.cs index 75ddc2b..44bc075 100644 --- a/tests/LuYao.Common.UnitTests/GZipStringTests.cs +++ b/tests/LuYao.Common.UnitTests/GZipStringTests.cs @@ -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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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..96ec4a4 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.Throws(() => RmbHelper.ToRmbUpper(10000000000000000M)); } /// /// 测试金额为负数时,期望抛出 ArgumentOutOfRangeException /// [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ToRmbUpper_NegativeAmount_ThrowsArgumentOutOfRangeException() { - RmbHelper.ToRmbUpper(-1M); + Assert.Throws(() => RmbHelper.ToRmbUpper(-1M)); } /// /// 测试金额为最大值时,期望抛出 ArgumentOutOfRangeException /// [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ToRmbUpper_MaxValidAmount_ThrowsArgumentOutOfRangeException() { - RmbHelper.ToRmbUpper(9999999999999999.99M); + Assert.Throws(() => 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..b8fc7a2 100644 --- a/tests/LuYao.Common.UnitTests/IO/AutoCleanTempFileTests.cs +++ b/tests/LuYao.Common.UnitTests/IO/AutoCleanTempFileTests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace LuYao.IO; @@ -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.Throws(() => new AutoCleanTempFile(null)); + Assert.Throws(() => new AutoCleanTempFile("")); + Assert.Throws(() => new AutoCleanTempFile(" ")); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs b/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs index f5ff4fb..e3fa872 100644 --- a/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs +++ b/tests/LuYao.Common.UnitTests/IO/Hashing/Crc32Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Text; namespace LuYao.IO.Hashing; @@ -9,7 +9,7 @@ public class Crc32Tests [TestMethod] public void Compute_EmptyBuffer_ReturnsZero() { - // 空数组 CRC32 结果应为 0 + // CRC32 ӦΪ 0 var buffer = Array.Empty(); var crc = Crc32.Compute(buffer); Assert.AreEqual(0u, crc); @@ -18,7 +18,7 @@ public void Compute_EmptyBuffer_ReturnsZero() [TestMethod] public void Compute_KnownAsciiString_ReturnsExpectedCrc() { - // "123456789" 的 CRC32 标准值为 0xCBF43926 + // "123456789" CRC32 ׼ֵΪ 0xCBF43926 var buffer = Encoding.ASCII.GetBytes("123456789"); var crc = Crc32.Compute(buffer); Assert.AreEqual(0xCBF43926u, crc); @@ -45,7 +45,7 @@ public void Compute_CustomPolynomial_ReturnsDifferentResult() [TestMethod] public void Reflect_KnownValue_ReturnsExpectedResult() { - // 0x3A (00111010) 反射 8 位应为 0x5C (01011100) + // 0x3A (00111010) 8 λӦΪ 0x5C (01011100) uint input = 0x3A; uint expected = 0x5C; var reflected = Crc32.reflect(input, 8); @@ -55,7 +55,7 @@ public void Reflect_KnownValue_ReturnsExpectedResult() [TestMethod] public void HashAlgorithm_StreamInput_ReturnsExpectedCrc() { - // 使用 HashAlgorithm 接口处理流式数据 + // ʹ HashAlgorithm ӿڴʽ var buffer = Encoding.ASCII.GetBytes("123456789"); using (var crc32 = new Crc32()) { @@ -63,7 +63,7 @@ public void HashAlgorithm_StreamInput_ReturnsExpectedCrc() crc32.TransformBlock(buffer, 0, buffer.Length, buffer, 0); crc32.TransformFinalBlock(Array.Empty(), 0, 0); var hash = crc32.Hash; - // 结果应为 0xCBF43926 + // ӦΪ 0xCBF43926 Assert.IsNotNull(hash); Assert.AreEqual(4, hash.Length); Array.Reverse(hash); @@ -75,10 +75,10 @@ public void HashAlgorithm_StreamInput_ReturnsExpectedCrc() [TestMethod] public void Constructor_BigEndian_ThrowsPlatformNotSupportedException() { - // 仅在非小端平台抛出异常,通常不会触发 + // ڷСƽ̨׳쳣ͨᴥ if (!BitConverter.IsLittleEndian) { - Assert.ThrowsException(() => + Assert.Throws(() => { 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..fd44c67 100644 --- a/tests/LuYao.Common.UnitTests/IO/Hashing/HashAgentTests.cs +++ b/tests/LuYao.Common.UnitTests/IO/Hashing/HashAgentTests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Text; namespace LuYao.IO.Hashing; @@ -13,7 +13,7 @@ public void Hash_String_NormalText_ReturnsCorrectHash() { // Arrange string input = "hello"; - // 预期值可通过在线工具或 .NET 计算得出 + // Ԥֵͨ߹߻ .NET ó string expected = "5d41402abc4b2a76b9719d911017c592"; // Act @@ -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.Throws(() => _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..5af2cfc 100644 --- a/tests/LuYao.Common.UnitTests/IO/PathHelperTests.cs +++ b/tests/LuYao.Common.UnitTests/IO/PathHelperTests.cs @@ -1,9 +1,9 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace LuYao.IO; /// -/// 测试 PathHelper 类的功能。 +/// PathHelper Ĺܡ /// [TestClass] public class PathHelperTests @@ -82,7 +82,7 @@ public void GetMimeType_ShouldThrowArgumentException_ForNullOrEmptyExtension() // Arrange string extension = string.Empty; // Act & Assert - Assert.ThrowsException(() => PathHelper.GetMimeType(extension)); + Assert.Throws(() => 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 22245f7..30116a4 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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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 479165c..d66a85e 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/Net/Http/HttpResponseMessageExtensionsTests.cs b/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs index 5978e09..7bd519e 100644 --- a/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs +++ b/tests/LuYao.Common.UnitTests/Net/Http/HttpResponseMessageExtensionsTests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Linq; @@ -18,7 +18,7 @@ public async Task ReadAsHtmlAsync_ResponseIsNull_ThrowsArgumentNullException() HttpResponseMessage? response = null; // Act & Assert - await Assert.ThrowsExceptionAsync(async () => + await Assert.ThrowsAsync(async () => { await HttpResponseMessageExtensions.ReadAsHtmlAsync(response); }); @@ -28,7 +28,7 @@ await Assert.ThrowsExceptionAsync(async () => public async Task ReadAsHtmlAsync_CharsetInHeader_UsesHeaderEncoding() { // Arrange - var content = new StringContent("测试内容", Encoding.Unicode); + var content = new StringContent("", Encoding.Unicode); if (content.Headers.ContentType != null) { content.Headers.ContentType.CharSet = "utf-16"; @@ -42,14 +42,14 @@ public async Task ReadAsHtmlAsync_CharsetInHeader_UsesHeaderEncoding() var result = await response.ReadAsHtmlAsync(); // Assert - Assert.AreEqual("测试内容", result); + Assert.AreEqual("", result); } [TestMethod] public async Task ReadAsHtmlAsync_CharsetInHtml_UsesHtmlEncoding() { // Arrange - var html = "
中文内容
"; + var html = "
"; var bytes = Encoding.GetEncoding("gb2312").GetBytes(html); var content = new ByteArrayContent(bytes); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"); @@ -62,14 +62,14 @@ public async Task ReadAsHtmlAsync_CharsetInHtml_UsesHtmlEncoding() var result = await response.ReadAsHtmlAsync(); // Assert - Assert.IsTrue(result.Contains("中文内容")); + Assert.IsTrue(result.Contains("")); } [TestMethod] public async Task ReadAsHtmlAsync_NoCharset_UsesUtf8ByDefault() { // Arrange - var text = "默认UTF8内容"; + var text = "ĬUTF8"; var bytes = Encoding.UTF8.GetBytes(text); var content = new ByteArrayContent(bytes); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/plain"); diff --git a/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs b/tests/LuYao.Common.UnitTests/Text/CSharpStringBuilderTests.cs index 19d1ccb..d4785e0 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.Throws(() => 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..2dfc15d 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.Throws(() => 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.Throws(() => jsonReader.Read()); } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_StringWithInvalidEscape_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("\"\\x\""); - // Act - jsonReader.Read(); + // Act & Assert + Assert.Throws(() => jsonReader.Read()); } [TestMethod] - [ExpectedException(typeof(JsonException))] public void Read_UnterminatedString_ShouldThrowException() { // Arrange using var jsonReader = new JsonReader("\"unterminated"); - // Act - jsonReader.Read(); + // Act & Assert + Assert.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => 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.Throws(() => jsonReader.Read()); } [TestMethod] - [ExpectedException(typeof(ObjectDisposedException))] public void Read_AfterDispose_ShouldThrowObjectDisposedException() { // Arrange var jsonReader = new JsonReader("{}"); jsonReader.Dispose(); - // Act - jsonReader.Read(); + // Act & Assert + Assert.Throws(() => 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.Throws(() => 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..3569e6a 100644 --- a/tests/LuYao.Common.UnitTests/Text/Json/JsonWriterTests.cs +++ b/tests/LuYao.Common.UnitTests/Text/Json/JsonWriterTests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Globalization; using System.IO; @@ -57,7 +57,7 @@ public void Constructor_WithStringBuilder_ShouldCreateWriter() public void Constructor_WithNullTextWriter_ShouldThrowArgumentNullException() { // Arrange & Act & Assert - Assert.ThrowsException(() => new JsonWriter((TextWriter)null)); + Assert.Throws(() => 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.Throws(() => _writer.WriteEndObject()); } #endregion @@ -181,7 +181,7 @@ public void WriteArray_WithIndentation_ShouldFormatCorrectly() public void WriteEndArray_WithoutStartArray_ShouldThrowInvalidOperationException() { // Act & Assert - Assert.ThrowsException(() => _writer.WriteEndArray()); + Assert.Throws(() => _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.Throws(() => _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.Throws(() => _writer.WriteRaw(null)); } #endregion @@ -600,7 +600,7 @@ public void WriteInvalidStructure_ShouldThrowInvalidOperationException() { // Act & Assert _writer.WriteStartObject(); - Assert.ThrowsException(() => _writer.WriteEndArray()); + Assert.Throws(() => _writer.WriteEndArray()); } [TestMethod] diff --git a/tests/LuYao.Common.UnitTests/Text/StringHelperTests.cs b/tests/LuYao.Common.UnitTests/Text/StringHelperTests.cs index b9ff219..738bca6 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.Throws(() => 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.Throws(() => StringHelper.Truncate("test", 0, out _)); + Assert.Throws(() => 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..afdf44d 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.ThrowsAsync( 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..64f2b15 100644 --- a/tests/LuYao.Common.UnitTests/Threading/KeyedLockerTests.cs +++ b/tests/LuYao.Common.UnitTests/Threading/KeyedLockerTests.cs @@ -1,15 +1,15 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace LuYao.Threading; /// -/// 测试 KeyedLocker 类型的功能。 +/// KeyedLocker ͵Ĺܡ /// [TestClass] public class KeyedLockerTests { /// - /// 测试使用有效键获取锁对象时,锁对象应正确返回。 + /// ʹЧȡʱӦȷء /// [TestMethod] public void GetLock_ValidKey_ReturnsLockObject() @@ -21,11 +21,11 @@ public void GetLock_ValidKey_ReturnsLockObject() var lockObject = KeyedLocker.GetLock(key); // Assert - Assert.IsNotNull(lockObject, "锁对象不应为 null。"); + Assert.IsNotNull(lockObject, "ӦΪ null"); } /// - /// 测试使用 null 键获取锁对象时,应抛出 ArgumentNullException。 + /// ʹ null ȡʱӦ׳ ArgumentNullException /// [TestMethod] public void GetLock_NullKey_ThrowsArgumentNullException() @@ -34,11 +34,11 @@ public void GetLock_NullKey_ThrowsArgumentNullException() string? key = null; // Act & Assert - Assert.ThrowsException(() => KeyedLocker.GetLock(key), "应抛出 ArgumentNullException。"); + Assert.Throws(() => KeyedLocker.GetLock(key), "Ӧ׳ ArgumentNullException"); } /// - /// 测试使用相同的键获取锁对象时,应返回相同的锁对象。 + /// ʹͬļȡʱӦͬ /// [TestMethod] public void GetLock_SameKey_ReturnsSameLockObject() @@ -51,6 +51,6 @@ public void GetLock_SameKey_ReturnsSameLockObject() var lockObject2 = KeyedLocker.GetLock(key); // Assert - Assert.AreSame(lockObject1, lockObject2, "相同的键应返回相同的锁对象。"); + Assert.AreSame(lockObject1, lockObject2, "ͬļӦͬ"); } } \ No newline at end of file diff --git a/tests/LuYao.Common.UnitTests/Threading/Tasks/TaskExtensionsTests.cs b/tests/LuYao.Common.UnitTests/Threading/Tasks/TaskExtensionsTests.cs index a449af7..a0fa93c 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.ThrowsAsync(() => task); Assert.IsFalse(task.IsCompletedSuccessfully()); } diff --git a/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs b/tests/LuYao.Common.UnitTests/Xml/TranslatableXmlModelTests.cs index f21dc44..bda0499 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.Throws(() => 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 487d7d5..95699dd 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 @@ - - + + diff --git a/tests/LuYao.Text.Json.UnitTests/TranslatableJsonModelTests.cs b/tests/LuYao.Text.Json.UnitTests/TranslatableJsonModelTests.cs index 2d2692a..ec4a7d3 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.Throws(() => TestJsonModel.Transform(json)); } /// @@ -68,6 +68,6 @@ public void Transform_NullObject_ThrowsArgumentNullException() object? model = null; // Act & Assert - Assert.ThrowsException(() => TestJsonModel.Transform(model)); + Assert.Throws(() => TestJsonModel.Transform(model)); } }