feat: add ProcessedUidStore with persistence and pruning
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
70
tests/SpamGuard.Tests/State/ProcessedUidStoreTests.cs
Normal file
70
tests/SpamGuard.Tests/State/ProcessedUidStoreTests.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
// tests/SpamGuard.Tests/State/ProcessedUidStoreTests.cs
|
||||
namespace SpamGuard.Tests.State;
|
||||
|
||||
using SpamGuard.State;
|
||||
|
||||
public class ProcessedUidStoreTests : IDisposable
|
||||
{
|
||||
private readonly string _tempDir;
|
||||
private readonly ProcessedUidStore _store;
|
||||
|
||||
public ProcessedUidStoreTests()
|
||||
{
|
||||
_tempDir = Path.Combine(Path.GetTempPath(), $"spamguard-test-{Guid.NewGuid()}");
|
||||
Directory.CreateDirectory(_tempDir);
|
||||
_store = new ProcessedUidStore(_tempDir);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_tempDir))
|
||||
Directory.Delete(_tempDir, true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Contains_ReturnsFalse_WhenUidNotAdded()
|
||||
{
|
||||
Assert.False(_store.Contains(42));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Contains_ReturnsTrue_AfterAdd()
|
||||
{
|
||||
_store.Add(42);
|
||||
Assert.True(_store.Contains(42));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Add_IsDuplicate_DoesNotThrow()
|
||||
{
|
||||
_store.Add(42);
|
||||
_store.Add(42);
|
||||
Assert.True(_store.Contains(42));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_And_Load_RoundTrips()
|
||||
{
|
||||
_store.Add(1);
|
||||
_store.Add(2);
|
||||
_store.Add(3);
|
||||
_store.Save();
|
||||
|
||||
var loaded = new ProcessedUidStore(_tempDir);
|
||||
Assert.True(loaded.Contains(1));
|
||||
Assert.True(loaded.Contains(2));
|
||||
Assert.True(loaded.Contains(3));
|
||||
Assert.False(loaded.Contains(4));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Prune_RemovesOldEntries()
|
||||
{
|
||||
_store.Add(1, DateTime.UtcNow.AddDays(-31));
|
||||
_store.Add(2, DateTime.UtcNow);
|
||||
_store.Prune(TimeSpan.FromDays(30));
|
||||
|
||||
Assert.False(_store.Contains(1));
|
||||
Assert.True(_store.Contains(2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user