The notifications service has a resend operation by a list of external identifiers. Product requirements:
Accepted report — the number of actually sent unique identifiers;Skipped report — all input elements that were not sent: empty, whitespace-only, and duplicates after normalization;Below is a PR with changes in the reporting module. Need to review it and find defects in the after version.
API contract:
DispatchAsync(IEnumerable<string?> externalIds, CancellationToken cancellationToken = default) returns DispatchReport;Trim() and case-insensitive comparison;IAttemptLog.WasSent(string externalId) returns true if the identifier has already been sent in one of the previous calls;IMessageSender.SendAsync(string externalId, CancellationToken cancellationToken) must be called only for identifiers that are actually sent.Runtime environment: .NET SDK 8.0.204, C# 12, run as a regular library without ASP.NET. No dependencies other than the BCL.
How to reproduce the observed problem:
{" A ", "a", null, "B"}, and then only {"B"}.DispatchAsync with a new AttemptLog where WasSent always returns false.SendAsync calls and the report fields.{" X ", "x", "Y"} within a single call: a duplicate must not be counted as sent.Assumptions:
IMessageSender can be replaced with a test stub that counts calls;C# 12, .NET 8, SDK 8.0.204. Build: dotnet build. The test scenarios can be run from any .NET 8 console project, referencing these classes. Only types from System, System.Collections.Generic, System.Linq, System.Threading, System.Threading.Tasks are used.
Use line comments to explain the problem, its impact, the fix and how to test it.