mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-29 04:37:01 +08:00
全面用SkiaSharp替换ImageSharp进行图像处理,包括哈希、边框检测、水印、验证码、图片工具等模块。重构IImageTransformer及相关接口和实现,调整测试用例以适配SkiaSharp。移除ImageSharp依赖,新增SkiaSharp依赖。同步升级部分依赖包版本。优化部分算法性能,提升跨平台兼容性。
66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
using System;
|
|
using Masuit.Tools.Strings;
|
|
using Xunit;
|
|
|
|
namespace Masuit.Tools.Abstractions.Test.Strings;
|
|
|
|
public class ValidateCodeTests
|
|
{
|
|
[Fact]
|
|
public void CreateValidateCode_ShouldReturnStringOfSpecifiedLength()
|
|
{
|
|
// Arrange
|
|
int length = 6;
|
|
|
|
// Act
|
|
string result = ValidateCode.CreateValidateCode(length);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(length, result.Length);
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateValidateGraphic_ShouldReturnPooledMemoryStream()
|
|
{
|
|
// Arrange
|
|
string validateCode = "ABC123";
|
|
int fontSize = 28;
|
|
|
|
// Act
|
|
using var result = validateCode.CreateValidateGraphic(fontSize);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.True(result.Length > 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void StringWidth_ShouldReturnCorrectWidth()
|
|
{
|
|
// Arrange
|
|
string input = "Test";
|
|
int fontSize = 12;
|
|
|
|
// Act
|
|
float width = input.StringWidth(fontSize);
|
|
|
|
// Assert
|
|
Assert.True(width > 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void StringWidth_WithFontName_ShouldReturnCorrectWidth()
|
|
{
|
|
// Arrange
|
|
string input = "Test";
|
|
string fontName = "Microsoft YaHei UI";
|
|
int fontSize = 12;
|
|
|
|
// Act
|
|
float width = input.StringWidth(fontName, fontSize);
|
|
|
|
// Assert
|
|
Assert.True(width > 0);
|
|
}
|
|
} |