Skip to content

Conversation

@Soar360
Copy link
Contributor

@Soar360 Soar360 commented Jan 16, 2026

将所有单元测试中的异常断言方式统一为 .NET 6+ 的 Assert.Throws/Assert.ThrowsAsync,移除 [ExpectedException] 特性,替换原有 Assert.ThrowsException/ThrowsExceptionAsync。同步升级 MSTest 相关 NuGet 包版本以支持新 API。此举提升了测试代码的现代性和可维护性,并兼容新版 MSTest 框架。

将所有单元测试中的异常断言方式统一为 .NET 6+ 的 Assert.Throws/Assert.ThrowsAsync,移除 [ExpectedException] 特性,替换原有 Assert.ThrowsException/ThrowsExceptionAsync。同步升级 MSTest 相关 NuGet 包版本以支持新 API。此举提升了测试代码的现代性和可维护性,并兼容新版 MSTest 框架。
Copilot AI review requested due to automatic review settings January 16, 2026 06:49
Copy link
Contributor

Copilot AI left a 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.ThrowsException with Assert.Throws and Assert.ThrowsExceptionAsync with Assert.ThrowsAsync
  • Removed [ExpectedException] attributes and wrapped test code in Assert.Throws lambdas
  • 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> ���͵Ĺ��ܡ�
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.
{
/// <summary>
/// 测试使用有效键获取锁对象时,锁对象应正确返回。
/// ����ʹ����Ч����ȡ������ʱ��������Ӧ��ȷ���ء�
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.

// Assert
Assert.IsNotNull(lockObject, "锁对象不应为 null");
Assert.IsNotNull(lockObject, "������ӦΪ null��");
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.

/// <summary>
/// 测试 PathHelper 类的功能。
/// ���� PathHelper ��Ĺ��ܡ�
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
/// ���� PathHelper ��Ĺ��ܡ�
/// 测试 PathHelper 类的功能。

Copilot uses AI. Check for mistakes.
{
// Arrange
var content = new StringContent("测试内容", Encoding.Unicode);
var content = new StringContent("��������", Encoding.Unicode);
Copy link

Copilot AI Jan 16, 2026

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.

Copilot uses AI. Check for mistakes.

// Assert: 期望抛出 ArgumentOutOfRangeException
// Arrange & Act & Assert
Assert.Throws<ArgumentOutOfRangeException>(() => { var item = _keyedList[-1]; });
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
Assert.Throws<ArgumentOutOfRangeException>(() => { var item = _keyedList[-1]; });
Assert.Throws<ArgumentOutOfRangeException>(() => _keyedList[-1]);

Copilot uses AI. Check for mistakes.
@Soar360 Soar360 merged commit 6dea7a1 into main Jan 16, 2026
6 of 7 checks passed
@Soar360 Soar360 deleted the chore/upgrade-testing-framework-version branch January 16, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant