Move test projects from src/ to tests/ (#11357)

* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
This commit is contained in:
Paul Johnson
2021-10-18 08:14:04 +01:00
committed by GitHub
parent c005673a96
commit 00133e880d
752 changed files with 650 additions and 1844 deletions

View File

@@ -0,0 +1,80 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using NUnit.Framework;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Web;
using SixLabors.ImageSharp.Web.Commands;
using SixLabors.ImageSharp.Web.Commands.Converters;
using Umbraco.Cms.Web.Common.ImageProcessors;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.ImageProcessors
{
[TestFixture]
public class CropWebProcessorTests
{
[Test]
public void CropWebProcessor_CropsImage()
{
var converters = new List<ICommandConverter>
{
CreateArrayConverterOfFloat(),
CreateSimpleCommandConverterOfFloat(),
};
var parser = new CommandParser(converters);
CultureInfo culture = CultureInfo.InvariantCulture;
var commands = new Dictionary<string, string>
{
{ CropWebProcessor.Coordinates, "0.1,0.2,0.1,0.4" }, // left, top, right, bottom
};
using var image = new Image<Rgba32>(50, 80);
using FormattedImage formatted = CreateFormattedImage(image, PngFormat.Instance);
new CropWebProcessor().Process(formatted, null, commands, parser, culture);
Assert.AreEqual(40, image.Width); // Cropped 5 pixels from each side.
Assert.AreEqual(32, image.Height); // Cropped 16 pixels from the top and 32 from the bottom.
}
private static ICommandConverter CreateArrayConverterOfFloat()
{
// ImageSharp.Web's ArrayConverter is internal, so we need to use reflection to instantiate.
var type = Type.GetType("SixLabors.ImageSharp.Web.Commands.Converters.ArrayConverter`1, SixLabors.ImageSharp.Web");
Type[] typeArgs = { typeof(float) };
Type genericType = type.MakeGenericType(typeArgs);
return (ICommandConverter)Activator.CreateInstance(genericType);
}
private static ICommandConverter CreateSimpleCommandConverterOfFloat()
{
// ImageSharp.Web's SimpleCommandConverter is internal, so we need to use reflection to instantiate.
var type = Type.GetType("SixLabors.ImageSharp.Web.Commands.Converters.SimpleCommandConverter`1, SixLabors.ImageSharp.Web");
Type[] typeArgs = { typeof(float) };
Type genericType = type.MakeGenericType(typeArgs);
return (ICommandConverter)Activator.CreateInstance(genericType);
}
private FormattedImage CreateFormattedImage(Image<Rgba32> image, PngFormat format)
{
// Again, the constructor of FormattedImage useful for tests is internal, so we need to use reflection.
Type type = typeof(FormattedImage);
var instance = type.Assembly.CreateInstance(
type.FullName,
false,
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new object[] { image, format },
null,
null);
return (FormattedImage)instance;
}
}
}