Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions Directory.Build.props

This file was deleted.

8 changes: 4 additions & 4 deletions PaperlessREST.Tests/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public sealed class DocumentBuilder
private const string DefaultStoragePathFormat = "documents/{0:yyyy-MM}/{1}.pdf";
private const string DefaultExtractedContent = "Extracted content";
private string? _content;
private DateTimeOffset _createdAt = DateTimeOffset.UtcNow;
private DateTimeOffset _createdAt = TimeProvider.System.GetUtcNow();
private string _fileName = DefaultFileName;

private Guid _id = Guid.CreateVersion7();
Expand Down Expand Up @@ -68,7 +68,7 @@ public DocumentBuilder WithProcessedAt(DateTimeOffset? processedAt)
public DocumentBuilder WithSummary(string? summary, DateTimeOffset? generatedAt = null)
{
_summary = summary;
_summaryGeneratedAt = generatedAt ?? (_summary is not null ? DateTimeOffset.UtcNow : null);
_summaryGeneratedAt = generatedAt ?? (_summary is not null ? TimeProvider.System.GetUtcNow() : null);
return this;
}

Expand All @@ -84,15 +84,15 @@ public DocumentBuilder AsCompleted(string content = DefaultExtractedContent)
{
_status = DocumentStatus.Completed;
_content = content;
_processedAt = DateTimeOffset.UtcNow;
_processedAt = TimeProvider.System.GetUtcNow();
return this;
}

public DocumentBuilder AsFailed()
{
_status = DocumentStatus.Failed;
_content = null;
_processedAt = DateTimeOffset.UtcNow;
_processedAt = TimeProvider.System.GetUtcNow();
return this;
}

Expand Down
1 change: 1 addition & 0 deletions PaperlessREST.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// System namespaces

global using System.Diagnostics.CodeAnalysis;
global using System.IO.Abstractions;
global using System.Net;
global using System.Net.Http.Headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Archive).Should().ContainSingle();
Expand All @@ -57,7 +57,7 @@ await _fileSystem.File.WriteAllTextAsync(

#region Fields

private static readonly IJobCancellationToken TestToken = new TestJobCancellationToken();
private static readonly IJobCancellationToken s_testToken = new TestJobCancellationToken();

private readonly IDbContextFactory<DocumentPersistence> _dbFactory;
private readonly IFileSystem _fileSystem;
Expand Down Expand Up @@ -97,7 +97,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Archive)
Expand All @@ -111,7 +111,7 @@ public async Task ProcessAsync_OrphanClaimedFile_Processes()
{
// Arrange
Guid docId = await SeedDocumentAsync($"{TestFilePrefix}-orphan.pdf");
string xmlContent = CreateXmlContent(DateOnly.FromDateTime(DateTime.UtcNow), (docId, 25));
string xmlContent = CreateXmlContent(DateOnly.FromDateTime(TimeProvider.System.GetUtcNow().UtcDateTime), (docId, 25));

string claimedPath = _fileSystem.Path.Combine(_paths.Input, "orphan.xml.processing");
await _fileSystem.File.WriteAllTextAsync(
Expand All @@ -120,7 +120,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Input).Should().BeEmpty("orphan should be processed");
Expand All @@ -140,7 +140,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Input)
Expand All @@ -157,7 +157,7 @@ public async Task ProcessAsync_InputDirectoryMissing_CreatesDirectoryAndContinue
_fileSystem.Directory.Exists(_paths.Input).Should().BeFalse("precondition: input dir should be deleted");

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.Exists(_paths.Input).Should().BeTrue("orchestrator should create input dir if missing");
Expand All @@ -171,7 +171,7 @@ public async Task ProcessAsync_ValidXmlFile_MovesToArchive()
await CreateXmlFileAsync("daily-report.xml", (docId, 15));

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Input).Should().BeEmpty("file should be moved out of input");
Expand All @@ -194,7 +194,7 @@ public async Task ProcessAsync_MultipleDocumentsInOneFile_AggregatesAndUpserts()
await CreateXmlFileAsync("multi-doc.xml", (doc1, 10), (doc2, 20));

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Archive).Should().ContainSingle();
Expand All @@ -210,7 +210,7 @@ public async Task ProcessAsync_DuplicateDocumentIdInSameFile_Aggregates()
await CreateXmlFileAsync("duplicates.xml", (docId, 5), (docId, 8));

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Archive).Should().ContainSingle();
Expand All @@ -224,10 +224,10 @@ public async Task ProcessAsync_SameDocumentProcessedTwice_AccumulatesCounts()
Guid docId = await SeedDocumentAsync($"{TestFilePrefix}-monthly.pdf");

await CreateXmlFileAsync("morning.xml", (docId, 5));
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

await CreateXmlFileAsync("afternoon.xml", (docId, 8));
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
await VerifyAccessRecordAsync(docId, 13, "should accumulate 5 + 8");
Expand All @@ -248,7 +248,7 @@ public async Task ProcessAsync_UnknownDocumentId_FiltersAndArchives()
await CreateXmlFileAsync("mixed.xml", (knownId, 10), (unknownId, 99));

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Archive).Should().ContainSingle("file should still archive");
Expand All @@ -270,7 +270,7 @@ public async Task ProcessAsync_AllDocumentsUnknown_StillArchives()
await CreateXmlFileAsync("all-unknown.xml", (unknownId1, 10), (unknownId2, 20));

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Archive).Should().ContainSingle("file should archive");
Expand All @@ -296,7 +296,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Error).Should().ContainSingle("malformed XML should go to error");
Expand All @@ -313,7 +313,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Error).Should().ContainSingle();
Expand All @@ -338,7 +338,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Error).Should().ContainSingle();
Expand All @@ -362,7 +362,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Error).Should().ContainSingle();
Expand All @@ -386,7 +386,7 @@ await _fileSystem.File.WriteAllTextAsync(
TestContext.Current.CancellationToken);

// Act
await _orchestrator.ProcessAsync(TestToken);
await _orchestrator.ProcessAsync(s_testToken);

// Assert
_fileSystem.Directory.GetFiles(_paths.Error).Should().ContainSingle();
Expand All @@ -413,7 +413,7 @@ private async Task<Guid> SeedDocumentAsync(string fileName)

private async Task CreateXmlFileAsync(string fileName, params (Guid id, int count)[] documents)
{
DateOnly date = DateOnly.FromDateTime(DateTime.UtcNow);
DateOnly date = DateOnly.FromDateTime(TimeProvider.System.GetUtcNow().UtcDateTime);
string xmlContent = CreateXmlContent(date, documents);
await _fileSystem.File.WriteAllTextAsync(
_fileSystem.Path.Combine(_paths.Input, fileName),
Expand All @@ -438,15 +438,15 @@ private async Task VerifyAccessRecordAsync(Guid documentId, long expectedCount,
{
await using DocumentPersistence db = await _dbFactory.CreateDbContextAsync(
TestContext.Current.CancellationToken);
DateOnly date = DateOnly.FromDateTime(DateTime.UtcNow);
DateOnly date = DateOnly.FromDateTime(TimeProvider.System.GetUtcNow().UtcDateTime);

DailyDocumentAccess? access = await db.DailyDocumentAccesses
.FirstOrDefaultAsync(
a => a.DocumentId == documentId && a.LogDate == date,
TestContext.Current.CancellationToken);

access.Should().NotBeNull(because ?? "record should exist");
access!.AccessCount.Should().Be(expectedCount, because ?? "access count should match");
access.AccessCount.Should().Be(expectedCount, because ?? "access count should match");
}

private void EnsureCleanDirectories()
Expand Down
Loading