-
Notifications
You must be signed in to change notification settings - Fork 1
统一异常断言为 Assert.Throws/ThrowsAsync 并升级 MSTest #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
将所有单元测试中的异常断言方式统一为 .NET 6+ 的 Assert.Throws/Assert.ThrowsAsync,移除 [ExpectedException] 特性,替换原有 Assert.ThrowsException/ThrowsExceptionAsync。同步升级 MSTest 相关 NuGet 包版本以支持新 API。此举提升了测试代码的现代性和可维护性,并兼容新版 MSTest 框架。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request modernizes the test suite by standardizing exception assertions and upgrading MSTest packages. The changes replace outdated [ExpectedException] attributes and Assert.ThrowsException/ThrowsExceptionAsync methods with the modern .NET 6+ compatible Assert.Throws/ThrowsAsync pattern across all unit tests.
Changes:
- Replaced all
Assert.ThrowsExceptionwithAssert.ThrowsandAssert.ThrowsExceptionAsyncwithAssert.ThrowsAsync - Removed
[ExpectedException]attributes and wrapped test code inAssert.Throwslambdas - Updated MSTest package versions to support the new assertion APIs
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| LuYao.Text.Json.UnitTests.csproj | Upgraded Microsoft.NET.Test.Sdk to 18.0.1 and MSTest to 4.0.2 |
| LuYao.Common.UnitTests.csproj | Upgraded MSTest packages to 4.0.2 and Microsoft.NET.Test.Sdk to 18.0.1 |
| TranslatableJsonModelTests.cs | Updated exception assertions to Assert.Throws |
| TranslatableXmlModelTests.cs | Removed [ExpectedException] and added Assert.Throws wrapper |
| TaskExtensionsTests.cs | Changed async exception assertion to Assert.ThrowsAsync |
| Multiple test files | Standardized exception assertion patterns throughout the test suite |
| KeyedLockerTests.cs, PathHelperTests.cs, etc. | Chinese comment encoding appears corrupted |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| /// <summary> | ||
| /// 测试 KeyedLocker<T> 类型的功能。 | ||
| /// ���� KeyedLocker<T> ���͵Ĺ��ܡ� |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chinese comments appear to be corrupted with encoding issues. The text shows garbled characters instead of proper Chinese text. This affects readability and documentation quality. Please verify the file encoding is UTF-8 and restore the original Chinese characters.
| { | ||
| /// <summary> | ||
| /// 测试使用有效键获取锁对象时,锁对象应正确返回。 | ||
| /// ����ʹ����Ч����ȡ������ʱ��������Ӧ��ȷ���ء� |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chinese comments appear to be corrupted with encoding issues. The text shows garbled characters instead of proper Chinese text. This affects readability and documentation quality. Please verify the file encoding is UTF-8 and restore the original Chinese characters.
|
|
||
| // Assert | ||
| Assert.IsNotNull(lockObject, "锁对象不应为 null。"); | ||
| Assert.IsNotNull(lockObject, "������ӦΪ null��"); |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chinese text in the assertion message appears to be corrupted with encoding issues. The text shows garbled characters instead of proper Chinese text. This affects test output readability. Please verify the file encoding is UTF-8 and restore the original Chinese characters.
|
|
||
| /// <summary> | ||
| /// 测试 PathHelper 类的功能。 | ||
| /// ���� PathHelper ��Ĺ��ܡ� |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chinese comments appear to be corrupted with encoding issues. The text shows garbled characters instead of proper Chinese text. This affects readability and documentation quality. Please verify the file encoding is UTF-8 and restore the original Chinese characters.
| /// ���� PathHelper ��Ĺ��ܡ� | |
| /// 测试 PathHelper 类的功能。 |
| { | ||
| // Arrange | ||
| var content = new StringContent("测试内容", Encoding.Unicode); | ||
| var content = new StringContent("��������", Encoding.Unicode); |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chinese text literal appears to be corrupted with encoding issues. The text shows garbled characters instead of proper Chinese text. This will cause test failures as the expected content won't match. Please verify the file encoding is UTF-8 and restore the original Chinese characters.
|
|
||
| // Assert: 期望抛出 ArgumentOutOfRangeException | ||
| // Arrange & Act & Assert | ||
| Assert.Throws<ArgumentOutOfRangeException>(() => { var item = _keyedList[-1]; }); |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to item is useless, since its value is never read.
| Assert.Throws<ArgumentOutOfRangeException>(() => { var item = _keyedList[-1]; }); | |
| Assert.Throws<ArgumentOutOfRangeException>(() => _keyedList[-1]); |
将所有单元测试中的异常断言方式统一为 .NET 6+ 的 Assert.Throws/Assert.ThrowsAsync,移除 [ExpectedException] 特性,替换原有 Assert.ThrowsException/ThrowsExceptionAsync。同步升级 MSTest 相关 NuGet 包版本以支持新 API。此举提升了测试代码的现代性和可维护性,并兼容新版 MSTest 框架。