Skip to content

Refactor/framework optimization from review#33

Merged
MarsonShine merged 5 commits into
masterfrom
refactor/framework-optimization-from-review
Jun 29, 2026
Merged

Refactor/framework optimization from review#33
MarsonShine merged 5 commits into
masterfrom
refactor/framework-optimization-from-review

Conversation

@MarsonShine

Copy link
Copy Markdown
Owner

No description provided.

MarsonShine and others added 5 commits June 27, 2026 10:41
引入 Platform 抽象,解耦平台依赖,所有平台相关操作(目录检测、连接、断开、Sleep)均通过委托注入,便于单元测试 mock。新增 Execute/ExecuteAsync 静态方法,支持同步/异步委托自动管理连接。构造函数与连接流程支持注入 Platform,重试与断开流程优化。测试代码全面重构,移除真实网络依赖,覆盖所有关键分支和资源释放场景。代码风格与注释进一步规范,符合 Clean Architecture 分层要求。
…tion, audio format detection, event sourcing, and Excel utilities

- Implement LogHttpClientTests to verify GET and POST requests with logging.
- Create LoggingHttpClientHandlerTests to ensure request and response logging.
- Add SecretFieldBranchTests for sensitive information handling.
- Introduce SerializationConverterTests for custom JSON converters.
- Develop TextNormalizerTests for various text normalization scenarios.
- Implement AudioFileFormatDetectorTests for audio format detection from streams.
- Add OrderAggregateDecisionTests to validate order processing logic.
- Create PerformanceProbeTests for performance measurement utility.
- Implement DynamicExcelBuilderTests and ExcelHelperEdgeTests for Excel file handling.
- Add coverlet.runsettings for code coverage configuration.
- 新增 AI 模型解析器测试:显式/回退/大小写/缺省场景
- 新增 AI 生产就绪组件测试:限流、熔断、日志脱敏、SecretProvider、PayloadLimit
- 新增 OpenAI Provider 校验测试:disabled/missing key/invalid uri
- 新增 OpenAIMedia/TTS Provider 测试:content-type、content safety、retry、timeout
- 新增 OrderAggregate 决策与状态演进测试:重复操作、冲突、非法的 boundary
- 新增 EFCore ApplySpecification 测试:criteria-only、排序链、分页、投影
- 新增 NLog/Serilog HostBuilder 重载测试
- 新增 coverlet.runsettings 排除规则:DTO/Options/自动属性/生成代码
- 删除 3 个纯 get/set 无意义测试
- 重写 1 个弱断言测试为行为验证
…erage

opt: 提升单元测试覆盖率至 85%,补充 AI/Domain/EFCore/Logging 核心分支测试
Copilot AI review requested due to automatic review settings June 29, 2026 02:00
@MarsonShine MarsonShine merged commit 2b34c15 into master Jun 29, 2026
1 of 2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR focuses on refactoring a few core/infrastructure utilities for better testability and reliability, while significantly expanding automated test coverage and updating code-coverage tooling/configuration across the solution.

Changes:

  • Refactor NetworkShareAccessor to add Execute/ExecuteAsync helpers and a testable platform seam.
  • Add/expand tests across Core/Infrastructure/AI/Logging/Persistence to cover edge cases and previously uncovered branches.
  • Update coverage tooling (Coverlet collector version, runsettings, reportgenerator tool) and ignore generated artifacts.

Reviewed changes

Copilot reviewed 51 out of 62 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/MS.Microservice.Infrastructure.Tests/Utils/Excel/ExcelHelperTests.cs Formatting tweaks + adds pipe/stream-related tests
test/MS.Microservice.Infrastructure.Tests/Utils/Excel/ExcelHelperEdgeTests.cs New ExcelHelper edge-case import/export tests
test/MS.Microservice.Infrastructure.Tests/Utils/Excel/DynamicExcelBuilderTests.cs New DynamicExcelBuilder pipe/style/value tests
test/MS.Microservice.Infrastructure.Tests/Utils/Diagnostics/PerformanceProbeTests.cs New PerformanceProbe phase/report tests
test/MS.Microservice.Infrastructure.Tests/FileSystem/NetworkShareAccessorTests.cs Rewrite tests to use platform seam (no real creds)
test/MS.Microservice.Infrastructure.Tests/EventSourcing/OrderAggregateTests.cs Adds more Decide/Fold/Evolve test cases
test/MS.Microservice.Infrastructure.Tests/EventSourcing/OrderAggregateDecisionTests.cs New decision-focused aggregate tests
test/MS.Microservice.Infrastructure.Tests/Common/NAudio/AudioFileFormatDetectorTests.cs New audio format detection tests
test/MS.Microservice.Core.Tests/Text/TextNormalizerTests.cs New TextNormalizer punctuation/whitespace tests
test/MS.Microservice.Core.Tests/Serialization/SerializationConverterTests.cs New JSON converter behavior tests
test/MS.Microservice.Core.Tests/Security/SecretFieldBranchTests.cs New SecretField branch-coverage tests
test/MS.Microservice.Core.Tests/Net/Http/LogHttpClientTests.cs New LogHttpClient behavior tests
test/MS.Microservice.Core.Tests/Net/Http/LoggingHttpClientHandlerTests.cs New handler wrapping/logging tests
test/MS.Microservice.Core.Tests/Net/Http/HttpClientExtensionsTests.cs New query-string & JSON parsing tests
test/MS.Microservice.Core.Tests/Microsoft/System/Collection/DisposableStackTests.cs New DisposableStack tests
test/MS.Microservice.Core.Tests/Linq/ExpressionStarterTests.cs New expression composition tests
test/MS.Microservice.Core.Tests/Functional/ValidationExceptionalTests.cs Major expansion of Exceptional/Either behavior tests
test/MS.Microservice.Core.Tests/Functional/FAsyncTests.cs New async functional helper tests
test/MS.Microservice.Core.Tests/Functional/EitherValueTests.cs New Either equality/match tests
test/MS.Microservice.Core.Tests/Functional/EitherExtensionsMoreTests.cs New Either extension-method tests
test/MS.Microservice.Core.Tests/Functional/CountryCodeTests.cs New CountryCode/PhoneNumber tests
test/MS.Microservice.Core.Tests/Extensions/ListHelperTests.cs New ListHelper shuffle tests
test/MS.Microservice.Core.Tests/Extensions/CollectionExtensionsTest.cs Adds extra coverage for ordering/shuffle cases
test/MS.Microservice.Core.Tests/Dto/ResultTests.cs New Result tests
test/MS.Microservice.Core.Tests/Domain/Repository/IUnitOfWorkExtensionsTests.cs New UnitOfWork extension tests
test/MS.Microservice.Core.Tests/Domain/IdentityModel/UserTests.cs New domain User behavior tests
test/MS.Microservice.Core.Tests/Domain/IdentityModel/RoleTests.cs New Role/RoleComparer tests
test/MS.Microservice.Core.Tests/Domain/IdentityModel/PasswordSaltHelperTests.cs New password salt generation test
test/MS.Microservice.Core.Tests/Domain/EventSourcing/EventSourcingAbstractionsTests.cs New event-sourcing record/exception tests
test/MS.Microservice.Core.Tests/Domain/EntityHelperEdgeTests.cs New EntityHelper edge tests
test/MS.Microservice.Core.Tests/Cryptology/EncryptTest.cs Refactors/expands crypto tests (DES/AES/RSA)
test/MS.Microservice.Core.Tests/Coverage/ResultExtensionsAsyncTests.cs New async Result extensions coverage tests
test/MS.Microservice.Core.Tests/Coverage/LinkedListTests.cs New functional LinkedList coverage tests
test/MS.Microservice.Core.Tests/Coverage/ExtensionCoverageTests.cs New extension-method coverage tests
test/MS.Microservice.Core.Tests/Coverage/DtoAndSpecificationTests.cs New DTO/specification coverage tests
test/MS.Microservice.Core.Tests/Coverage/CoreFinalGapTests.cs New “final gap” coverage tests bundle
test/MS.Microservice.Core.Tests/Coverage/CoreFinalGap2Tests.cs Additional coverage tests for misc utilities
test/MS.Microservice.Core.Tests/Coverage/CoreExtensionsGapTests.cs Coverage tests for extensions/entities/md5
test/MS.Microservice.Core.Tests/Coverage/CoreEdgeGapTests.cs Coverage tests for error/core edge branches
test/MS.Microservice.Core.Tests/Coverage/CacheAndRetryTests.cs Coverage tests for cache and retry executor
test/MS.Microservice.Core.Tests/Coverage/BinaryTreeTests.cs Coverage tests for binary tree functional type
test/MS.Microservice.Core.Tests/Common/TextNormalizerTests.cs Additional TextNormalizer tests (file-scoped ns)
test/MS.Microservice.Core.Tests/Ceching/WeakEvictionCacheTests.cs New WeakEvictionCache tests
src/MS.Microservice.Infrastructure/FileSystem/NetworkShareAccessor.cs Adds platform seam + Execute helpers; refactors connect/disconnect
src/MS.Microservice.Core/Microsoft/System/Collection/DisposableStack.cs Adds XML documentation for DisposableStack
src/MS.Microservice.Core/Concurrent/SingleflightManager.cs Refactor/modernize syntax (needs correctness fix)
src/MS.Microservice.Core/Ceching/WeakEvictionCache.cs Refactor + detailed XML documentation
MS.Microservice.Persistence/MS.Microservice.Persistence.EFCore/test/MS.Microservice.Persistence.EFCore.Tests/MsPlatformDbContextSettingsTests.cs Removes/keeps selected settings tests
MS.Microservice.Persistence/MS.Microservice.Persistence.EFCore/test/MS.Microservice.Persistence.EFCore.Tests/EfCoreQueryableExtensionsTests.cs New ApplySpecification tests
MS.Microservice.Logging/test/MS.Microservice.Logging.Serilog.Tests/MsSerilogProviderTests.cs Adds HostBuilder overload test
MS.Microservice.Logging/test/MS.Microservice.Logging.NLog.Tests/MsNLogProviderTests.cs Adds HostBuilder overload + ambient context test
MS.Microservice.Logging/test/MS.Microservice.Logging.Core.Tests/LoggerExtensionsTests.cs Adds overload coverage tests
MS.Microservice.AI/test/MS.Microservice.AI.OpenAI.Tests/OpenAIMediaProviderTests.cs Adds TTS/ASR retry/timeout/content-type/error tests
MS.Microservice.AI/test/MS.Microservice.AI.OpenAI.Tests/OpenAIChatProviderTests.cs Adds OpenAI options validator tests
MS.Microservice.AI/test/MS.Microservice.AI.Core.Tests/DefaultAIModelResolverTests.cs Adds resolver edge-case tests
MS.Microservice.AI/test/MS.Microservice.AI.Core.Tests/AIRequestValidatorTests.cs New request validator tests
MS.Microservice.AI/test/MS.Microservice.AI.Core.Tests/AIProductionReadinessTests.cs Adds production options validator tests
dotnet-tools.json Add reportgenerator dotnet tool manifest
Directory.Packages.props Update coverlet.collector to 6.0.4
coverlet.runsettings Add centralized coverlet runsettings
.gitignore Ignore /.tools and TestResults

Comment on lines +9 to +10
using MS.Microservice.Infrastructure.Utils;
using MS.Microservice.Infrastructure.Utils.Excel;
Comment on lines +20 to 44
public async Task<T> ExecuteOnceAsync<T>(string key, Func<Task<T>> action)
{
var completionSource = new TaskCompletionSource<object>();
var existingTask = _inFlightRequests.GetOrAdd(key, completionSource);
try
{
if (existingTask == completionSource)
{
// 当前请求是第一个请求,执行对应的操作
T result = await action();
completionSource.SetResult(result!);
return result;
}
else
{
// 等待第一个请求完成,并使用其结果
return (T)(await (existingTask.Task));
}
}
finally
{
_inFlightRequests.TryRemove(key, out _);
}
}
}
return match.Success ? match.Value : null;
}

// ponytail: keep the test seam as delegates inside Infrastructure; add a wider abstraction only if another caller needs to swap the transport.
Comment on lines 165 to 168
lock (ConnectLock)
{
const int connectUpdateProfile = 0x00000001;
NativeMethods.WNetCancelConnection2(_networkName, connectUpdateProfile, force: true);
_platform.CancelConnection(_networkName, ConnectUpdateProfile, force: true);
}
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.

2 participants