Catalog/MaddoShared.Tests/ImageCreatorSharpTests.cs
Maddo d76e133f18
Some checks failed
Build Windows Avalonia / build (push) Failing after 1m47s
Completely removed GDI
2026-05-28 20:27:05 +02:00

63 lines
1.7 KiB
C#

using System.Reflection;
using MaddoShared;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using SixLabors.ImageSharp;
namespace MaddoShared.Tests;
[TestClass]
public class ImageCreatorSharpTests
{
[TestMethod]
public void CalculateThumbnailSize_Larghezza_UsesWidthScaling()
{
var size = CalculateThumbnailSize(400, 200, 200, "Larghezza");
size.Width.ShouldBe(200);
size.Height.ShouldBe(100);
}
[TestMethod]
public void CalculateThumbnailSize_Altezza_UsesHeightScaling()
{
var size = CalculateThumbnailSize(200, 400, 200, "Altezza");
size.Width.ShouldBe(100);
size.Height.ShouldBe(200);
}
[TestMethod]
public void FindBestFontSize_ConstrainsTextToBounds()
{
const string text = "A very long text that will not fit at the requested size";
var method = typeof(ImageCreatorImageSharp).GetMethod(
"FindBestFontSize",
BindingFlags.NonPublic | BindingFlags.Static);
method.ShouldNotBeNull();
var size = (float)method.Invoke(null, new object[]
{
text,
"Arial",
40,
50f,
20f,
6
})!;
size.ShouldBeInRange(6f, 40f);
(size * text.Length * 0.6f <= 50f || size <= 6f).ShouldBeTrue();
}
private static Size CalculateThumbnailSize(int width, int height, int maxPixel, string sizeMode)
{
var method = typeof(ImageCreatorImageSharp).GetMethod(
"CalculateThumbnailSize",
BindingFlags.NonPublic | BindingFlags.Static);
method.ShouldNotBeNull();
return (Size)method.Invoke(null, new object[] { width, height, maxPixel, sizeMode })!;
}
}