42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using ErsatzTV.Core.Images;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
using SkiaSharp;
|
|
|
|
namespace ErsatzTV.Core.Tests.Images;
|
|
|
|
[TestFixture]
|
|
public class ChannelLogoGeneratorTests
|
|
{
|
|
[TestCase("News", 100, 200)]
|
|
[TestCase("A Very Long Channel Name That Should Force Font Shrinking", 100, 200)]
|
|
[TestCase("Tall Logo", 180, 120)]
|
|
public void GenerateChannelLogo_WithInjectedAssets_ReturnsValidPngWithRequestedDimensions(
|
|
string text,
|
|
int logoHeight,
|
|
int logoWidth)
|
|
{
|
|
var generator = new ChannelLogoGenerator(
|
|
NullLogger<ChannelLogoGenerator>.Instance,
|
|
TestAssetPath("Resources", "Images", "ersatztv-500.png"),
|
|
TestAssetPath("Resources", "Fonts", "Sen.ttf"));
|
|
|
|
byte[] bytes = generator.GenerateChannelLogo(text, logoHeight, logoWidth, CancellationToken.None)
|
|
.Match(
|
|
Left: error => throw new AssertionException(error.Value),
|
|
Right: identity);
|
|
|
|
using var stream = new MemoryStream(bytes);
|
|
using var codec = SKCodec.Create(stream);
|
|
|
|
codec.ShouldNotBeNull();
|
|
codec.EncodedFormat.ShouldBe(SKEncodedImageFormat.Png);
|
|
codec.Info.Width.ShouldBe(logoWidth);
|
|
codec.Info.Height.ShouldBe(logoHeight);
|
|
}
|
|
|
|
private static string TestAssetPath(params string[] segments) =>
|
|
Path.Combine([TestContext.CurrentContext.TestDirectory, .. segments]);
|
|
}
|