So I have the following class, which takes, in its constructor, three different implementations of the same interface as dependencies:
public class MyTestClass : ISomeInterface<string>
{
// Constructor
public MyTestClass([Named("ImplementationA")] IMyTestInterface implementationA,
[Named("ImplementationB")] IMyTestInterface implementationB,
[Named("ImplementationC")] IMyTestInterface implementationC)
{
// Some logic here
}
public void MethodA(string)
{
}
}
When using this class outside of unit tests, I inject the dependencies in question with Ninject, i.e. I have something like this:
public class MyNinjectModule : NinjectModule
{
public override void Load()
{
this.Bind<IMyTestInterface>().To<ImplementationA>().InRequestScope().Named("ImplementationA");
this.Bind<IMyTestInterface>().To<ImplementationB>().InRequestScope().Named("ImplementationB");
this.Bind<IMyTestInterface>().To<ImplementationC>().InRequestScope().Named("ImplementationC");
}
}
Which works fine, but the problem I am having now is that I want to unit test this class and I want to do it with AutoFixture, which leads me to my question, how do I create an instance of MyTestClass with those three specific implementations of IMyTestInterface, i.e. ImplementationA, ImplementationB, and ImplementationC? If I just do something like this:
private ISomeInterface<string> testInstance;
private Fixture fixture;
[TestInitialize]
public void SetUp()
{
this.fixture = new Fixture();
this.fixture.Customize(new AutoMoqCustomization());
this.testInstance = this.fixture.Create<MyTestClass>();
}
AutoFixture creates an instance of MyTestClass, but with some random implementations of IMyTestInterface, which is not the dependencies I want. I've been searching for an answer online and the only thing I've found so far that seems similar to what I need, but not quite, is this