75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 瘚贝�颲�𨭌撌亙�嚗𡁜�撱?Mock �峕�霂閧鍂�曉�
|
|
/// </summary>
|
|
internal static class TestHelpers
|
|
{
|
|
public static readonly string[] DefaultKeys = { "Blur", "Sharpen", "Threshold" };
|
|
|
|
/// <summary>
|
|
/// �𥕦遣銝�銝?1x1 �讐��?BitmapSource嚗𣬚鍂鈭擧�霂?
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// �𥕦遣銝�銝芾�憭批㦛�𧶏��其�瘚贝�憸��蝻拇𦆮嚗?
|
|
/// </summary>
|
|
public static BitmapSource CreateLargeBitmap(int width = 4096, int height = 4096)
|
|
=> CreateTestBitmap(width, height);
|
|
|
|
/// <summary>
|
|
/// �𥕦遣��� Mock IImageProcessingService嚗峕釣�?DefaultKeys 銝剔�蝞堒�
|
|
/// </summary>
|
|
public static Mock<IImageProcessingService> CreateMockImageService(
|
|
string[]? keys = null,
|
|
ProcessorParameter[]? parameters = null)
|
|
{
|
|
keys ??= DefaultKeys;
|
|
parameters ??= Array.Empty<ProcessorParameter>();
|
|
|
|
var mock = new Mock<IImageProcessingService>();
|
|
mock.Setup(s => s.GetAvailableProcessors()).Returns(keys);
|
|
mock.Setup(s => s.GetProcessorDisplayName(It.IsAny<string>()))
|
|
.Returns<string>(k => k + "蝞堒�");
|
|
mock.Setup(s => s.GetProcessorParameters(It.IsAny<string>()))
|
|
.Returns(parameters);
|
|
mock.Setup(s => s.ProcessImageAsync(
|
|
It.IsAny<BitmapSource>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<IDictionary<string, object>>(),
|
|
It.IsAny<IProgress<double>>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync((BitmapSource src, string _, IDictionary<string, object> _, IProgress<double> _, CancellationToken ct) =>
|
|
{
|
|
ct.ThrowIfCancellationRequested();
|
|
return src;
|
|
});
|
|
return mock;
|
|
}
|
|
|
|
/// <summary>
|
|
/// �𥕦遣撣行㺭�澆��啁� ProcessorParameter
|
|
/// </summary>
|
|
public static ProcessorParameter MakeIntParam(string name, int value = 5, int min = 0, int max = 10)
|
|
=> new ProcessorParameter(name, name, typeof(int), value, min, max);
|
|
}
|
|
} |