* Trivial - Add VS Code workspace * Trivial - Add VSCode build task & extra ignore On GNU/Linux, auto-generated .directory files should be ignored. * WIP #485 - Boilerplate for unit test project * WIP #485 - Add test coverage (Remove/RemoveAll) * WIP #485 - Implement RemoveAll * Remove redundant logic, covered by IDictionary Per the following, the contract for a generic IDictionary, the Remove method already deals with non-existent keys. https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.idictionary-2.remove?view=net-5.0#System_Collections_Generic_IDictionary_2_Remove__0_ * Resolve #485 - Add PurgeVariables methods These are convenience methods upon ActivityExecutionContext and WorkflowExecutionContext, consistent with their current APIs. Also in this commit are tests for those simple methods. There's a bit of test-scaffold as well included, such as: * Autofixture Xunit2 integration * New project for unit tests * Customize attribute for avoiding crashes on Autofixture recursion * Reusable specimen builder for creating IServiceProvider which resolves services from Autofixture * Custonize attribute for a parameter to use that ^^ specimen builder
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using AutoFixture;
|
|
using AutoFixture.Kernel;
|
|
using AutoFixture.Xunit2;
|
|
using Elsa.Testing.Shared.AutoFixture.SpecimenBuilders;
|
|
|
|
namespace Elsa.Testing.Shared.AutoFixture.Attributes
|
|
{
|
|
/// <summary>
|
|
/// Customizes the parameter so that it creates an <see cref="IServiceProvider"/>
|
|
/// using Moq. That mock service provider gets services by resolving them from Autofixture.
|
|
/// </summary>
|
|
/// <seealso cref="AutofixtureServiceProviderSpecimenBuilder"/>
|
|
public class AutofixtureServiceProviderAttribute : CustomizeAttribute
|
|
{
|
|
public override ICustomization GetCustomization(ParameterInfo parameter)
|
|
=> new AutofixtureServiceProviderCustomization(parameter);
|
|
|
|
class AutofixtureServiceProviderCustomization : ICustomization
|
|
{
|
|
readonly ParameterInfo parameter;
|
|
|
|
public void Customize(IFixture fixture)
|
|
{
|
|
fixture.Customizations.Insert(0, GetSpecimenBuilder());
|
|
}
|
|
|
|
ISpecimenBuilder GetSpecimenBuilder()
|
|
{
|
|
var paramSpec = new ParameterSpecification(parameter.ParameterType, parameter.Name);
|
|
var specimenBuilder = new AutofixtureServiceProviderSpecimenBuilder();
|
|
return new FilteringSpecimenBuilder(specimenBuilder, paramSpec);
|
|
}
|
|
|
|
public AutofixtureServiceProviderCustomization(ParameterInfo parameter)
|
|
{
|
|
this.parameter = parameter;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |