Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests/InboundApiRepositoryTests.cs
T
Joseph Doherty 513fa1aa16 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.
2026-10-07 15:05:49 -04:00

68 lines
2.6 KiB
C#

using Microsoft.EntityFrameworkCore;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.InboundApi;
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
// Auth re-arch (C5): the SQL Server ApiKey entity and the repository's key methods
// (Add/Get/Update/Delete/GetApprovedKeysForMethod) were retired — inbound API keys
// now live in the shared ZB.MOM.WW.Auth.ApiKeys SQLite store. The former key
// round-trip, peppered-hasher, and ApprovedApiKeyIds CSV tests were removed with
// them; only the API-method catalogue remains here.
public class InboundApiRepositoryTests : IDisposable
{
private readonly ScadaBridgeDbContext _context;
private readonly InboundApiRepository _repository;
/// <summary>Initializes a new test instance with its own database context.</summary>
public InboundApiRepositoryTests()
{
_context = SqliteTestHelper.CreateInMemoryContext();
_repository = new InboundApiRepository(_context);
}
/// <summary>Releases the resources held by this instance.</summary>
public void Dispose()
{
_context.Database.CloseConnection();
_context.Dispose();
}
/// <summary>Verifies that an added API method can be retrieved by name.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task AddApiMethod_AndGetByName_RoundTrips()
{
var method = new ApiMethod("DoThing", "return 1;");
await _repository.AddApiMethodAsync(method);
await _repository.SaveChangesAsync();
var loaded = await _repository.GetMethodByNameAsync("DoThing");
Assert.NotNull(loaded);
Assert.Equal(method.Id, loaded!.Id);
}
/// <summary>Verifies that deleting an API method removes the entity.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task DeleteApiMethod_RemovesEntity()
{
var method = new ApiMethod("ToDelete", "return 1;");
await _repository.AddApiMethodAsync(method);
await _repository.SaveChangesAsync();
await _repository.DeleteApiMethodAsync(method.Id);
await _repository.SaveChangesAsync();
Assert.Null(await _repository.GetApiMethodByIdAsync(method.Id));
}
/// <summary>Verifies that constructing the repository with a null context throws.</summary>
[Fact]
public void Constructor_NullContext_Throws()
{
Assert.Throws<ArgumentNullException>(() => new InboundApiRepository(null!));
}
}