Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

style: fix imports ordering and use TestContext CancellationToken in tests

return {name:"chinchi-codes"}c955997c2ff2
diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
index d05655d0..8f2b9abc 100644
--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs
+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
@@ -5,12 +5,12 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
+using Filee.App.Services;
using Filee.Core.Formats;
using Filee.Core.Localization;
using Filee.Core.Presets;
-using Filee.Engines.Ocr;
-using Filee.App.Services;
using Filee.Core.Settings;
+using Filee.Engines.Ocr;
using Filee.Engines.Translation;
namespace Filee.App.ViewModels;
diff --git a/tests/Filee.Engines.Tests/TranslationIntegrationTests.cs b/tests/Filee.Engines.Tests/TranslationIntegrationTests.cs
index d3aae1cc..1dd17734 100644
--- a/tests/Filee.Engines.Tests/TranslationIntegrationTests.cs
+++ b/tests/Filee.Engines.Tests/TranslationIntegrationTests.cs
@@ -53,7 +53,7 @@ public class TranslationIntegrationTests
{
var inputFile = Path.Combine(tempDir, "sample_zh.md");
var inputContent = "# 桃园三结义\n\n东汉末年,天下大乱。\n\n- 刘备为兄\n- 关羽次之\n- 张飞为弟\n";
- await File.WriteAllTextAsync(inputFile, inputContent);
+ await File.WriteAllTextAsync(inputFile, inputContent, TestContext.Current.CancellationToken);
var preset = new Preset
{
@@ -73,13 +73,13 @@ public class TranslationIntegrationTests
);
var converter = new TranslatorConverter(new MockTranslationService());
- var outputs = await converter.ConvertAsync(step, null, default);
+ var outputs = await converter.ConvertAsync(step, null, TestContext.Current.CancellationToken);
Assert.Single(outputs);
var translatedPath = outputs[0];
Assert.True(File.Exists(translatedPath));
- var translatedContent = await File.ReadAllTextAsync(translatedPath);
+ var translatedContent = await File.ReadAllTextAsync(translatedPath, TestContext.Current.CancellationToken);
Assert.NotEmpty(translatedContent);
// Structure must have headings and list bullets
@@ -104,7 +104,7 @@ public class TranslationIntegrationTests
{
var inputFile = Path.Combine(tempDir, "sample_en.md");
var inputContent = "# The Great Journey\n\nEvery journey begins with a single step.\n\n- First step\n- Second step\n";
- await File.WriteAllTextAsync(inputFile, inputContent);
+ await File.WriteAllTextAsync(inputFile, inputContent, TestContext.Current.CancellationToken);
var preset = new Preset
{
@@ -124,13 +124,13 @@ public class TranslationIntegrationTests
);
var converter = new TranslatorConverter(new MockTranslationService());
- var outputs = await converter.ConvertAsync(step, null, default);
+ var outputs = await converter.ConvertAsync(step, null, TestContext.Current.CancellationToken);
Assert.Single(outputs);
var translatedPath = outputs[0];
Assert.True(File.Exists(translatedPath));
- var translatedContent = await File.ReadAllTextAsync(translatedPath);
+ var translatedContent = await File.ReadAllTextAsync(translatedPath, TestContext.Current.CancellationToken);
Assert.NotEmpty(translatedContent);
// Structure check
@@ -155,7 +155,7 @@ public class TranslationIntegrationTests
{
var inputFile = Path.Combine(tempDir, "document.txt");
var inputContent = "The Quick Brown Fox Jumps Over The Lazy Dog.\nThis is a sample document for translation into DOCX.\n";
- await File.WriteAllTextAsync(inputFile, inputContent);
+ await File.WriteAllTextAsync(inputFile, inputContent, TestContext.Current.CancellationToken);
var preset = new Preset
{
@@ -175,7 +175,7 @@ public class TranslationIntegrationTests
);
var converter = new TranslatorConverter(new MockTranslationService());
- var outputs = await converter.ConvertAsync(step, null, default);
+ var outputs = await converter.ConvertAsync(step, null, TestContext.Current.CancellationToken);
Assert.Single(outputs);
var docxPath = outputs[0];
diff --git a/tests/Filee.Engines.Tests/TranslationTests.cs b/tests/Filee.Engines.Tests/TranslationTests.cs
index 0528cfb3..84342ff5 100644
--- a/tests/Filee.Engines.Tests/TranslationTests.cs
+++ b/tests/Filee.Engines.Tests/TranslationTests.cs
@@ -59,7 +59,7 @@ public class TranslationTests
sec.Blocks.Add(p);
var service = new MockTranslationService();
- await DocumentTranslator.TranslateDocumentAsync(doc, "hi", "en", service, null, default);
+ await DocumentTranslator.TranslateDocumentAsync(doc, "hi", "en", service, null, TestContext.Current.CancellationToken);
Assert.Equal(2, p.Inlines.Count);
Assert.True(p.Inlines[0] is HText t0 && !string.IsNullOrEmpty(t0.Text));
@@ -69,9 +69,9 @@ public class TranslationTests
public async Task TranslationService_throws_when_no_local_engine_is_available()
{
var service = new TranslationService();
- if (!await TranslationService.IsLocalOllamaAvailableAsync())
+ if (!await TranslationService.IsLocalOllamaAvailableAsync(TestContext.Current.CancellationToken))
{
- await Assert.ThrowsAsync<InvalidOperationException>(() => service.TranslateTextAsync("Hello", "es", "en"));
+ await Assert.ThrowsAsync<InvalidOperationException>(() => service.TranslateTextAsync("Hello", "es", "en", cancellationToken: TestContext.Current.CancellationToken));
}
}
}