elsa-core/test/shared/Elsa.Testing.Shared/AutoFixture/Attributes/WithAutofixtureResolutionAttribute.cs
Craig Fowler 282c90f80f Further fixup & refactoring of Autofixture attribs
This now also includes reworking the attribute which activates
Autofixture-style resolution upon an IServiceProvider.
This has now been renamed to WithAutofixtureResolutionAttribute.

The new/reworked attribute is composable with other Autofixture
attributes.
2021-04-02 13:28:27 +01:00

32 lines
1.1 KiB
C#

using System;
using System.Reflection;
using AutoFixture;
using AutoFixture.Xunit2;
using Elsa.Testing.Shared.AutoFixture.Behaviors;
using Elsa.Testing.Shared.AutoFixture.SpecimenBuilders;
using Moq;
namespace Elsa.Testing.Shared.AutoFixture.Attributes
{
/// <summary>
/// Customizes the parameter so that the <see cref="IServiceProvider"/>
/// created by Moq will resolve services of the appropriate type, creating
/// them using Autofixture.
/// </summary>
/// <seealso cref="AutofixtureServiceProviderSpecimenBuilder"/>
public class WithAutofixtureResolutionAttribute : CustomizeAttribute
{
public override ICustomization GetCustomization(ParameterInfo parameter)
=> new AutofixtureServiceProviderCustomization();
class AutofixtureServiceProviderCustomization : ICustomization
{
public void Customize(IFixture fixture)
{
var behavior = BehaviorFactory.GetPostprocessingBehavior<IServiceProvider>(AutofixtureResolutionServiceProviderSpecimenBuilder.AddAutofixtureResolution);
fixture.Behaviors.Add(behavior);
}
}
}
}