Testing File Storage¶
Deepstaging provides TestFileStore — a test double for IFileStore with call recording, seedable files, and a configurable presigned URL generator. No mocking libraries needed.
TestFileStore¶
Records every UploadAsync, DownloadAsync, DeleteAsync, ExistsAsync, GetMetadataAsync, and GetPresignedUrlAsync call. Seed files for download and existence checks.
var store = new TestFileStore();
// Seed a file
store.Seed("avatars/user-42.png", "image/png", imageBytes);
// ... run your handler that downloads files ...
// Assert the file was requested
await Assert.That(store.DownloadCalls).Contains("avatars/user-42.png");
Call Recording¶
| Property | Type | Description |
|---|---|---|
UploadCalls |
IReadOnlyList<UploadCall> |
All upload calls (key, content type, size) |
DownloadCalls |
IReadOnlyList<string> |
All keys passed to DownloadAsync |
DeleteCalls |
IReadOnlyList<string> |
All keys passed to DeleteAsync |
ExistsCalls |
IReadOnlyList<string> |
All keys passed to ExistsAsync |
MetadataCalls |
IReadOnlyList<string> |
All keys passed to GetMetadataAsync |
PresignedUrlCalls |
IReadOnlyList<(string Key, TimeSpan Expiry)> |
All presigned URL requests |
UploadCall Record¶
Each UploadAsync call is recorded as:
Seeding Files¶
store.Seed("reports/q1.pdf", "application/pdf", pdfBytes);
store.Seed("images/logo.svg", "image/svg+xml", svgBytes);
Seeded files are returned by DownloadAsync, ExistsAsync, and GetMetadataAsync.
Configurable Presigned URLs¶
var store = new TestFileStore();
// Custom URL generator
store.OnGetPresignedUrl = (key, expiry) =>
$"https://cdn.example.com/{key}?expires={expiry.TotalSeconds}";
var url = await store.GetPresignedUrlAsync("file.pdf", TimeSpan.FromHours(1));
// → "https://cdn.example.com/file.pdf?expires=3600"
Default generates memory:///{key}.
State Queries¶
// Check what's in the store
bool exists = store.Exists("avatars/user-42.png");
IReadOnlyCollection<string> allKeys = store.Keys();
Asserting Uploads¶
var store = new TestFileStore();
// ... run handler that uploads files ...
await Assert.That(store.UploadCalls).Count().IsEqualTo(1);
await Assert.That(store.UploadCalls[0].Key).IsEqualTo("avatars/user-42.png");
await Assert.That(store.UploadCalls[0].ContentType).IsEqualTo("image/png");