Conversation
…iatr-to-mediator-main # Conflicts: # docs/superpowers/plans/2026-03-29-migrate-mediatr-to-mediator.md # docs/superpowers/specs/2026-03-29-migrate-mediatr-to-mediator-design.md # tests/Application.IntegrationTests/Common/MediatorCompatibility/MediatorCompatibilityTests.cs # tests/Application.UnitTests/Common/MediatorCompatibility/ParallelNoWaitPublisherTests.cs # tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs
|
|
|
||
| if (request is PingQuery) | ||
| { | ||
| return new ValueTask<TResponse>((TResponse)(object)"pong"); |
Check warning
Code scanning / CodeQL
Useless upcast Warning test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 21 days ago
In general, to fix a “Useless upcast” warning, you remove the unnecessary explicit cast and rely on C#’s implicit conversion from the expression’s type to the target type. This keeps the code simpler and clearer, without changing runtime behavior.
Here, the method Send<TResponse>(IRequest<TResponse> request, ...) returns ValueTask<TResponse>. When the request is a PingQuery, it currently returns new ValueTask<TResponse>((TResponse)(object)"pong"). The inner (object) cast is the useless upcast: "pong" is a string, which already implicitly converts to object. The outer (TResponse) cast is still needed to satisfy the generic return type in this fake/test implementation. So the best fix, without changing any behavior or public surface, is to remove only the (object) cast and leave (TResponse)"pong".
Concretely:
- In
tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs, within theFakeMediator.Send<TResponse>(IRequest<TResponse> request, ...)method, edit line 110 to change((TResponse)(object)"pong")to((TResponse)"pong"). - No new methods, imports, or definitions are required.
| @@ -107,7 +107,7 @@ | ||
|
|
||
| if (request is PingQuery) | ||
| { | ||
| return new ValueTask<TResponse>((TResponse)(object)"pong"); | ||
| return new ValueTask<TResponse>((TResponse)"pong"); | ||
| } | ||
|
|
||
| throw new NotSupportedException($"Unexpected request type: {request.GetType().Name}"); |


Summary
Mediator.Abstractionsand wire runtime registration throughMediator.SourceGeneratorTest Plan
dotnet test tests/Application.UnitTests/Application.UnitTests.csproj -v minimal -p:UseSharedCompilation=falsedotnet test tests/Application.IntegrationTests/Application.IntegrationTests.csproj --filter FullyQualifiedName~MediatorCompatibilityTests -v minimal -p:UseSharedCompilation=false