* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
111 lines
3.8 KiB
C#
111 lines
3.8 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Collections.Generic;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Media;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
|
|
using Umbraco.Extensions;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Extensions;
|
|
|
|
[TestFixture]
|
|
public class ImageCropperTemplateCoreExtensionsTests
|
|
{
|
|
[Test]
|
|
public void GetCropUrl_WithCropSpecifiedButNotFound_ReturnsNull()
|
|
{
|
|
var imageUrl = "/test.jpg";
|
|
var imageUrlGenerator = CreateMockImageUrlGenerator();
|
|
var result = imageUrl.GetCropUrl(
|
|
imageUrlGenerator.Object,
|
|
new ImageCropperValue(),
|
|
imageCropMode: ImageCropMode.Crop,
|
|
cropAlias: "Missing");
|
|
|
|
Assert.IsNull(result);
|
|
}
|
|
|
|
[Test]
|
|
public void GetCropUrl_WithCropSpecifiedAndUsingCropDimensions_CallsImageGeneratorWithCorrectParameters()
|
|
{
|
|
var imageUrl = "/test.jpg";
|
|
var imageUrlGenerator = CreateMockImageUrlGenerator();
|
|
var result = imageUrl.GetCropUrl(
|
|
imageUrlGenerator.Object,
|
|
CreateImageCropperValueWithCrops(),
|
|
imageCropMode: ImageCropMode.Crop,
|
|
cropAlias: "TestCrop",
|
|
useCropDimensions: true);
|
|
|
|
imageUrlGenerator
|
|
.Verify(x => x.GetImageUrl(
|
|
It.Is<ImageUrlGenerationOptions>(y => y.Width == 100 &&
|
|
y.Height == 200)));
|
|
}
|
|
|
|
[Test]
|
|
public void GetCropUrl_WithCropSpecifiedAndWidthAndHeightProvided_CallsImageGeneratorWithCorrectParameters()
|
|
{
|
|
var imageUrl = "/test.jpg";
|
|
var imageUrlGenerator = CreateMockImageUrlGenerator();
|
|
var result = imageUrl.GetCropUrl(
|
|
imageUrlGenerator.Object,
|
|
CreateImageCropperValueWithCrops(),
|
|
imageCropMode: ImageCropMode.Crop,
|
|
cropAlias: "TestCrop",
|
|
width: 50,
|
|
height: 80);
|
|
|
|
imageUrlGenerator
|
|
.Verify(x => x.GetImageUrl(
|
|
It.Is<ImageUrlGenerationOptions>(y => y.Width == 50 &&
|
|
y.Height == 80)));
|
|
}
|
|
|
|
[Test]
|
|
public void GetCropUrl_WithCropSpecifiedAndWidthOnlyProvided_CallsImageGeneratorWithCorrectParameters()
|
|
{
|
|
var imageUrl = "/test.jpg";
|
|
var imageUrlGenerator = CreateMockImageUrlGenerator();
|
|
var result = imageUrl.GetCropUrl(
|
|
imageUrlGenerator.Object,
|
|
CreateImageCropperValueWithCrops(),
|
|
imageCropMode: ImageCropMode.Crop,
|
|
cropAlias: "TestCrop",
|
|
width: 50);
|
|
|
|
imageUrlGenerator
|
|
.Verify(x => x.GetImageUrl(
|
|
It.Is<ImageUrlGenerationOptions>(y => y.Width == 50 &&
|
|
y.Height == 100)));
|
|
}
|
|
|
|
[Test]
|
|
public void GetCropUrl_WithCropSpecifiedAndHeightOnlyProvided_CallsImageGeneratorWithCorrectParameters()
|
|
{
|
|
var imageUrl = "/test.jpg";
|
|
var imageUrlGenerator = CreateMockImageUrlGenerator();
|
|
var result = imageUrl.GetCropUrl(
|
|
imageUrlGenerator.Object,
|
|
CreateImageCropperValueWithCrops(),
|
|
imageCropMode: ImageCropMode.Crop,
|
|
cropAlias: "TestCrop",
|
|
height: 50);
|
|
|
|
imageUrlGenerator
|
|
.Verify(x => x.GetImageUrl(
|
|
It.Is<ImageUrlGenerationOptions>(y => y.Width == 25 &&
|
|
y.Height == 50)));
|
|
}
|
|
|
|
private static Mock<IImageUrlGenerator> CreateMockImageUrlGenerator() => new();
|
|
|
|
private static ImageCropperValue CreateImageCropperValueWithCrops() => new()
|
|
{
|
|
Crops = new List<ImageCropperValue.ImageCropperCrop> { new() { Alias = "TestCrop", Width = 100, Height = 200 } },
|
|
};
|
|
}
|