namespace ImageSharp.Tests { using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using ImageSharp.PixelFormats; public static class TestImageExtensions { /// /// Saves the image only when not running in the CI server. /// /// The pixel format /// The image /// The image provider /// The settings /// The extension public static void DebugSave(this Image image, ITestImageProvider provider, object settings = null, string extension = "png") where TPixel : struct, IPixel { string tag = null; string s = settings as string; if (s != null) { tag = s; } else if (settings != null) { if (settings.GetType().GetTypeInfo().IsPrimitive) { tag = settings.ToString(); } else { IEnumerable properties = settings.GetType().GetRuntimeProperties(); tag = string.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(settings)).Select(x => $"{x.Key}-{x.Value}")); } } if (!bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) || !isCi) { // We are running locally then we want to save it out provider.Utility.SaveTestOutputFile(image, extension, tag: tag); } } } }