// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace SixLabors.ImageSharp.Tests { /// /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// public class WithFileCollectionAttribute : ImageDataAttributeBase { private readonly string fileEnumeratorMemberName; /// /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// /// The name of the static test class field/property enumerating the files /// The requested pixel types /// Additional theory parameter values public WithFileCollectionAttribute( string fileEnumeratorMemberName, PixelTypes pixelTypes, params object[] additionalParameters) : base(null, pixelTypes, additionalParameters) { this.fileEnumeratorMemberName = fileEnumeratorMemberName; } /// /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// /// The name of the static test class field/property enumerating the files /// The member name for enumerating method parameters /// The requested pixel types /// Additional theory parameter values public WithFileCollectionAttribute( string fileEnumeratorMemberName, string memberName, PixelTypes pixelTypes, params object[] additionalParameters) : base(memberName, pixelTypes, additionalParameters) { this.fileEnumeratorMemberName = fileEnumeratorMemberName; } /// /// Generates the collection of method arguments from the given test. /// /// The test method /// The test image provider factory type /// The protected override IEnumerable GetAllFactoryMethodArgs(MethodInfo testMethod, Type factoryType) { Func accessor = this.GetPropertyAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName); accessor = accessor ?? this.GetFieldAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName); var files = (IEnumerable)accessor(); return files.Select(f => new object[] { f }); } /// protected override string GetFactoryMethodName(MethodInfo testMethod) => "File"; } }