- Implemented EmailChannelTestProvider to generate email preview payloads. - Implemented SlackChannelTestProvider to create Slack message previews. - Implemented TeamsChannelTestProvider for generating Teams Adaptive Card previews. - Implemented WebhookChannelTestProvider to create webhook payloads. - Added INotifyChannelTestProvider interface for channel-specific preview generation. - Created ChannelTestPreviewContracts for request and response models. - Developed NotifyChannelTestService to handle test send requests and generate previews. - Added rate limit policies for test sends and delivery history. - Implemented unit tests for service registration and binding. - Updated project files to include necessary dependencies and configurations.
83 lines
3.2 KiB
C#
83 lines
3.2 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using MongoDB.Driver;
|
|
using StellaOps.Excititor.Core;
|
|
using StellaOps.Excititor.Export;
|
|
using StellaOps.Excititor.Storage.Mongo;
|
|
|
|
namespace StellaOps.Excititor.Export.Tests;
|
|
|
|
public sealed class VexExportCacheServiceTests
|
|
{
|
|
[Fact]
|
|
public async Task InvalidateAsync_RemovesEntry()
|
|
{
|
|
var cacheIndex = new RecordingIndex();
|
|
var maintenance = new StubMaintenance();
|
|
var service = new VexExportCacheService(cacheIndex, maintenance, NullLogger<VexExportCacheService>.Instance);
|
|
|
|
var signature = new VexQuerySignature("format=json|provider=vendor");
|
|
await service.InvalidateAsync(signature, VexExportFormat.Json, CancellationToken.None);
|
|
|
|
Assert.Equal(signature.Value, cacheIndex.LastSignature?.Value);
|
|
Assert.Equal(VexExportFormat.Json, cacheIndex.LastFormat);
|
|
Assert.Equal(1, cacheIndex.RemoveCalls);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PruneExpiredAsync_ReturnsCount()
|
|
{
|
|
var cacheIndex = new RecordingIndex();
|
|
var maintenance = new StubMaintenance { ExpiredCount = 3 };
|
|
var service = new VexExportCacheService(cacheIndex, maintenance, NullLogger<VexExportCacheService>.Instance);
|
|
|
|
var removed = await service.PruneExpiredAsync(DateTimeOffset.UtcNow, CancellationToken.None);
|
|
|
|
Assert.Equal(3, removed);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PruneDanglingAsync_ReturnsCount()
|
|
{
|
|
var cacheIndex = new RecordingIndex();
|
|
var maintenance = new StubMaintenance { DanglingCount = 2 };
|
|
var service = new VexExportCacheService(cacheIndex, maintenance, NullLogger<VexExportCacheService>.Instance);
|
|
|
|
var removed = await service.PruneDanglingAsync(CancellationToken.None);
|
|
|
|
Assert.Equal(2, removed);
|
|
}
|
|
|
|
private sealed class RecordingIndex : IVexCacheIndex
|
|
{
|
|
public VexQuerySignature? LastSignature { get; private set; }
|
|
public VexExportFormat LastFormat { get; private set; }
|
|
public int RemoveCalls { get; private set; }
|
|
|
|
public ValueTask<VexCacheEntry?> FindAsync(VexQuerySignature signature, VexExportFormat format, CancellationToken cancellationToken)
|
|
=> ValueTask.FromResult<VexCacheEntry?>(null);
|
|
|
|
public ValueTask SaveAsync(VexCacheEntry entry, CancellationToken cancellationToken)
|
|
=> ValueTask.CompletedTask;
|
|
|
|
public ValueTask RemoveAsync(VexQuerySignature signature, VexExportFormat format, CancellationToken cancellationToken)
|
|
{
|
|
LastSignature = signature;
|
|
LastFormat = format;
|
|
RemoveCalls++;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|
|
|
|
private sealed class StubMaintenance : IVexCacheMaintenance
|
|
{
|
|
public int ExpiredCount { get; set; }
|
|
public int DanglingCount { get; set; }
|
|
|
|
public ValueTask<int> RemoveExpiredAsync(DateTimeOffset asOf, CancellationToken cancellationToken, IClientSessionHandle? session = null)
|
|
=> ValueTask.FromResult(ExpiredCount);
|
|
|
|
public ValueTask<int> RemoveMissingManifestReferencesAsync(CancellationToken cancellationToken, IClientSessionHandle? session = null)
|
|
=> ValueTask.FromResult(DanglingCount);
|
|
}
|
|
}
|