mirror of
https://github.com/cyanfish/naps2.git
synced 2024-10-03 19:07:17 +03:00
parent
33595be9dc
commit
a716ae979c
@ -199,6 +199,53 @@ public class AutoSaverTests : ContextualTests
|
||||
PdfAsserts.AssertImages(Path.Combine(FolderPath, "test2.pdf"), ImageResources.dog_h_n300);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PromptForFilePath()
|
||||
{
|
||||
var settings = new AutoSaveSettings
|
||||
{
|
||||
FilePath = Path.Combine(FolderPath, "test_a_$(n).pdf"),
|
||||
PromptForFilePath = true
|
||||
};
|
||||
_dialogHelper.PromptToSavePdfOrImage(Arg.Any<string>(), out Arg.Any<string>()).Returns(x =>
|
||||
{
|
||||
x[1] = Path.Combine(FolderPath, "test_b_$(n).pdf");
|
||||
return true;
|
||||
});
|
||||
|
||||
var scanned = CreateScannedImages(ImageResources.dog);
|
||||
var output = await _autoSaver.Save(settings, scanned.ToAsyncEnumerable()).ToListAsync();
|
||||
|
||||
Assert.Single(output);
|
||||
Assert.False(IsDisposed(output[0]));
|
||||
Assert.True(IsDisposed(scanned[0]));
|
||||
Assert.Single(Folder.GetFiles());
|
||||
PdfAsserts.AssertImages(Path.Combine(FolderPath, "test_b_1.pdf"), ImageResources.dog);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CancelPromptForFilePath()
|
||||
{
|
||||
var settings = new AutoSaveSettings
|
||||
{
|
||||
FilePath = Path.Combine(FolderPath, "test$(n).pdf"),
|
||||
PromptForFilePath = true
|
||||
};
|
||||
_dialogHelper.PromptToSavePdfOrImage(Arg.Any<string>(), out Arg.Any<string>()).Returns(x =>
|
||||
{
|
||||
x[1] = Path.Combine(FolderPath, "test$(n).pdf");
|
||||
return false;
|
||||
});
|
||||
|
||||
var scanned = CreateScannedImages(ImageResources.dog);
|
||||
var output = await _autoSaver.Save(settings, scanned.ToAsyncEnumerable()).ToListAsync();
|
||||
|
||||
Assert.Single(output);
|
||||
Assert.False(IsDisposed(output[0]));
|
||||
Assert.True(IsDisposed(scanned[0]));
|
||||
Assert.Empty(Folder.GetFiles());
|
||||
}
|
||||
|
||||
// TODO: Finish out tests
|
||||
|
||||
//
|
||||
|
@ -117,13 +117,15 @@ public class AutoSaver
|
||||
string subPath = placeholders.Substitute(settings.FilePath, true, i);
|
||||
if (settings.PromptForFilePath)
|
||||
{
|
||||
Invoker.Current.Invoke(() =>
|
||||
string? newPath = null!;
|
||||
if (Invoker.Current.InvokeGet(() => _dialogHelper.PromptToSavePdfOrImage(subPath, out newPath)))
|
||||
{
|
||||
if (_dialogHelper.PromptToSavePdfOrImage(subPath, out string? newPath))
|
||||
{
|
||||
subPath = placeholders.Substitute(newPath!, true, i);
|
||||
}
|
||||
});
|
||||
subPath = placeholders.Substitute(newPath!, true, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
}
|
||||
// TODO: This placeholder handling is complex and wrong in some cases (e.g. FilePerScan with ext = "jpg")
|
||||
// TODO: Maybe have initial placeholders that replace date, then rely on the ops to increment the file num
|
||||
|
Loading…
Reference in New Issue
Block a user