docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
This commit is contained in:
@@ -26,6 +26,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
private readonly FakeInboundApiKeyAdmin _admin = new();
|
||||
private readonly IAuditService _auditService = Substitute.For<IAuditService>();
|
||||
|
||||
/// <summary>Initializes the test with a fake key admin and a substituted audit service.</summary>
|
||||
public ApiKeyCreationTests()
|
||||
{
|
||||
_services.AddScoped<IInboundApiKeyAdmin>(_ => _admin);
|
||||
@@ -42,8 +43,10 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
new(new AuthenticatedUser("admin", "Admin User", roles, Array.Empty<string>()),
|
||||
command, Guid.NewGuid().ToString("N"));
|
||||
|
||||
/// <inheritdoc />
|
||||
void IDisposable.Dispose() => Shutdown();
|
||||
|
||||
/// <summary>Verifies that creating an API key returns the key id and a one-time token.</summary>
|
||||
[Fact]
|
||||
public void CreateApiKey_ReturnsKeyIdAndOneTimeToken()
|
||||
{
|
||||
@@ -69,6 +72,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Assert.Equal(new[] { "MethodA", "MethodB" }, created.Methods);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that creating an API key writes an audit entry.</summary>
|
||||
[Fact]
|
||||
public void CreateApiKey_AuditsTheCreate()
|
||||
{
|
||||
@@ -80,6 +84,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
"admin", "Create", "ApiKey", Arg.Any<string>(), "MES-Production", Arg.Any<object?>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the create response does not echo a hash of the key.</summary>
|
||||
[Fact]
|
||||
public void CreateApiKey_ResponseDoesNotEchoAHash()
|
||||
{
|
||||
@@ -93,6 +98,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Assert.DoesNotContain("hash", response.JsonData, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that listing API keys returns each key with its methods.</summary>
|
||||
[Fact]
|
||||
public void ListApiKeys_ReturnsKeysWithMethods()
|
||||
{
|
||||
@@ -119,6 +125,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Assert.DoesNotContain("hash", response.JsonData, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that updating an API key toggles its enabled flag and writes an audit entry.</summary>
|
||||
[Fact]
|
||||
public void UpdateApiKey_TogglesEnabled_AndAudits()
|
||||
{
|
||||
@@ -139,6 +146,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
"admin", "Update", "ApiKey", "key-1", Arg.Any<string>(), Arg.Any<object?>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting an API key removes it and writes an audit entry.</summary>
|
||||
[Fact]
|
||||
public void DeleteApiKey_RemovesKey_AndAudits()
|
||||
{
|
||||
@@ -156,6 +164,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
"admin", "Delete", "ApiKey", "key-1", "key-1", null);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting API key methods replaces the key's scopes and writes an audit entry.</summary>
|
||||
[Fact]
|
||||
public void SetApiKeyMethods_ReplacesScopes_AndAudits()
|
||||
{
|
||||
@@ -183,6 +192,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
// Fix 1 (review): not-found on mutating ops → ManagementError, no audit
|
||||
// =========================================================================
|
||||
|
||||
/// <summary>Verifies that updating an unknown API key returns a management error and writes no audit entry.</summary>
|
||||
[Fact]
|
||||
public void UpdateApiKey_UnknownKey_ReturnsManagementError_AndDoesNotAudit()
|
||||
{
|
||||
@@ -198,6 +208,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Arg.Any<string>(), "Update", "ApiKey", Arg.Any<string>(), Arg.Any<string>(), Arg.Any<object?>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting methods on an unknown API key returns a management error and writes no audit entry.</summary>
|
||||
[Fact]
|
||||
public void SetApiKeyMethods_UnknownKey_ReturnsManagementError_AndDoesNotAudit()
|
||||
{
|
||||
@@ -211,6 +222,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Arg.Any<string>(), "Update", "ApiKey", Arg.Any<string>(), Arg.Any<string>(), Arg.Any<object?>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deleting an unknown API key returns a management error and writes no audit entry.</summary>
|
||||
[Fact]
|
||||
public void DeleteApiKey_UnknownKey_ReturnsManagementError_AndDoesNotAudit()
|
||||
{
|
||||
@@ -228,6 +240,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
// Fix 2 (review): empty methods set is rejected before seam + audit
|
||||
// =========================================================================
|
||||
|
||||
/// <summary>Verifies that creating an API key with no methods returns a management error.</summary>
|
||||
[Fact]
|
||||
public void CreateApiKey_EmptyMethods_ReturnsManagementError()
|
||||
{
|
||||
@@ -243,6 +256,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Arg.Any<string>(), "Create", "ApiKey", Arg.Any<string>(), Arg.Any<string>(), Arg.Any<object?>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that setting an empty method list on an API key returns a management error.</summary>
|
||||
[Fact]
|
||||
public void SetApiKeyMethods_EmptyMethods_ReturnsManagementError()
|
||||
{
|
||||
@@ -260,6 +274,8 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Arg.Any<string>(), "Update", "ApiKey", Arg.Any<string>(), Arg.Any<string>(), Arg.Any<object?>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that every API key command is rejected for a caller without the Administrator role.</summary>
|
||||
/// <param name="command">The API key command under test.</param>
|
||||
[Theory]
|
||||
[MemberData(nameof(AllApiKeyCommands))]
|
||||
public void EveryApiKeyCommand_RequiresAdminRole(object command)
|
||||
@@ -272,6 +288,8 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
Assert.Contains("Administrator", response.Message);
|
||||
}
|
||||
|
||||
/// <summary>Supplies one instance of every API key command as test data.</summary>
|
||||
/// <returns>The commands, each wrapped as a single-element argument array.</returns>
|
||||
public static IEnumerable<object[]> AllApiKeyCommands() => new[]
|
||||
{
|
||||
new object[] { new ListApiKeysCommand() },
|
||||
@@ -291,11 +309,18 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
{
|
||||
public sealed record Entry(string KeyId, string Name, bool Enabled, IReadOnlyList<string> Methods);
|
||||
|
||||
/// <summary>Gets the keys currently held by the fake, indexed by key id.</summary>
|
||||
public Dictionary<string, Entry> Keys { get; } = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Adds or replaces a key in the fake.</summary>
|
||||
/// <param name="keyId">The key id.</param>
|
||||
/// <param name="name">The key name.</param>
|
||||
/// <param name="enabled">Whether the key is enabled.</param>
|
||||
/// <param name="methods">The methods the key may call.</param>
|
||||
public void Seed(string keyId, string name, bool enabled, params string[] methods) =>
|
||||
Keys[keyId] = new Entry(keyId, name, enabled, methods.ToList());
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<InboundApiKeyCreated> CreateAsync(
|
||||
string name, IReadOnlyCollection<string> methods, CancellationToken ct = default)
|
||||
{
|
||||
@@ -304,6 +329,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
return Task.FromResult(new InboundApiKeyCreated(keyId, $"sbk_{keyId}_secret"));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyList<InboundApiKeyInfo>> ListAsync(CancellationToken ct = default)
|
||||
{
|
||||
IReadOnlyList<InboundApiKeyInfo> result = Keys.Values
|
||||
@@ -314,6 +340,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> SetEnabledAsync(string keyId, bool enabled, CancellationToken ct = default)
|
||||
{
|
||||
if (!Keys.TryGetValue(keyId, out var e)) return Task.FromResult(false);
|
||||
@@ -321,6 +348,7 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> SetMethodsAsync(string keyId, IReadOnlyCollection<string> methods, CancellationToken ct = default)
|
||||
{
|
||||
if (!Keys.TryGetValue(keyId, out var e)) return Task.FromResult(false);
|
||||
@@ -328,15 +356,18 @@ public class ApiKeyCreationTests : TestKit, IDisposable
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> DeleteAsync(string keyId, CancellationToken ct = default) =>
|
||||
Task.FromResult(Keys.Remove(keyId));
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyList<string>> GetMethodsForKeyAsync(string keyId, CancellationToken ct = default)
|
||||
{
|
||||
IReadOnlyList<string> methods = Keys.TryGetValue(keyId, out var e) ? e.Methods : Array.Empty<string>();
|
||||
return Task.FromResult(methods);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyList<string>> GetKeysForMethodAsync(string methodName, CancellationToken ct = default)
|
||||
{
|
||||
IReadOnlyList<string> keys = Keys.Values
|
||||
|
||||
Reference in New Issue
Block a user