using Moq; using System; using System.Collections.Generic; using System.Threading; using System.Windows.Media; using System.Windows.Media.Imaging; using XP.ImageProcessing.Core; using XplorePlane.Services; namespace XplorePlane.Tests.Helpers { /// /// 测试辅助工具:创�?Mock 和测试用图像 /// internal static class TestHelpers { public static readonly string[] DefaultKeys = { "Blur", "Sharpen", "Threshold" }; /// /// 创建一�?1x1 像素�?BitmapSource,用于测�? /// public static BitmapSource CreateTestBitmap(int width = 4, int height = 4) { var pixels = new byte[width * height * 4]; var bitmap = BitmapSource.Create( width, height, 96, 96, PixelFormats.Bgra32, null, pixels, width * 4); bitmap.Freeze(); return bitmap; } /// /// 创建一个超大图像(用于测试预览缩放�? /// public static BitmapSource CreateLargeBitmap(int width = 4096, int height = 4096) => CreateTestBitmap(width, height); /// /// 创建标准 Mock IImageProcessingService,注�?DefaultKeys 中的算子 /// public static Mock CreateMockImageService( string[]? keys = null, ProcessorParameter[]? parameters = null) { keys ??= DefaultKeys; parameters ??= Array.Empty(); var mock = new Mock(); mock.Setup(s => s.GetAvailableProcessors()).Returns(keys); mock.Setup(s => s.GetProcessorDisplayName(It.IsAny())) .Returns(k => k + "算子"); mock.Setup(s => s.GetProcessorParameters(It.IsAny())) .Returns(parameters); mock.Setup(s => s.ProcessImageAsync( It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny())) .ReturnsAsync((BitmapSource src, string _, IDictionary _, IProgress _, CancellationToken ct) => { ct.ThrowIfCancellationRequested(); return src; }); return mock; } /// /// 创建带数值参数的 ProcessorParameter /// public static ProcessorParameter MakeIntParam(string name, int value = 5, int min = 0, int max = 10) => new ProcessorParameter(name, name, typeof(int), value, min, max); } }