From 47710578f042c6fc37035ff7aa65f3630fde5073 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 5 May 2017 16:33:22 +1000 Subject: [PATCH] Fix tests --- .../TestUtilities/TestUtilityExtensions.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs index de05e83a9..dfaf1c052 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs @@ -25,26 +25,27 @@ namespace ImageSharp.Tests private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary(); private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes() - .Except(new [] {PixelTypes.Undefined, PixelTypes.All }) + .Except(new[] { PixelTypes.Undefined, PixelTypes.All }) .ToArray(); static TestUtilityExtensions() { - string nameSpace = typeof(Rgba32).FullName; - nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Rgba32).Name.Length - 1); - foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass)) + // Add Rgba32 Our default. + Type defaultPixelFormatType = typeof(Rgba32); + PixelTypes2ClrTypes[PixelTypes.Rgba32] = defaultPixelFormatType; + ClrTypes2PixelTypes[defaultPixelFormatType] = PixelTypes.Rgba32; + + // Add PixelFormat types + string nameSpace = typeof(Alpha8).FullName; + nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Alpha8).Name.Length - 1); + foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass && pt != PixelTypes.Rgba32)) { - string typeName = $"{nameSpace}.{pt.ToString()}"; + string typeName = $"{nameSpace}.{pt}"; Type t = ImageSharpAssembly.GetType(typeName); - if (t == null) - { - throw new InvalidOperationException($"Could not find: {typeName}"); - } - - PixelTypes2ClrTypes[pt] = t; + PixelTypes2ClrTypes[pt] = t ?? throw new InvalidOperationException($"Could not find: {typeName}"); ClrTypes2PixelTypes[t] = pt; } - PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Rgba32); + PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = defaultPixelFormatType; } public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag;