You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
869 B
29 lines
869 B
using System.Reflection;
|
|
using AutoFixture;
|
|
|
|
namespace Recyclarr.TestLibrary.AutoFixture;
|
|
|
|
// Based on the answer here: https://stackoverflow.com/a/16735551/157971
|
|
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
|
|
public sealed class CustomizeWithAttribute : CustomizeAttribute
|
|
{
|
|
public Type CustomizationType { get; }
|
|
|
|
public CustomizeWithAttribute(Type customizationType)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(customizationType);
|
|
|
|
if (!typeof(ICustomization).IsAssignableFrom(customizationType))
|
|
{
|
|
throw new ArgumentException("Type needs to implement ICustomization");
|
|
}
|
|
|
|
CustomizationType = customizationType;
|
|
}
|
|
|
|
public override ICustomization? GetCustomization(ParameterInfo parameter)
|
|
{
|
|
return (ICustomization?) Activator.CreateInstance(CustomizationType);
|
|
}
|
|
}
|