I am trying to inject through the use of Unity two objects based on an interface into a class constructor.
I'm currently receiving the following error when unit testing:
Result Message:
Test method TestProject.TFStests.Check_Interface_CheckOut_Method threw exception: System.InvalidOperationException: The type Adp.Tools.VersionControl.TfsVersionControl.TfsVcPromotionManager does not have a constructor that takes the parameters (TfsVcQaCheckoutWorker).
The following code is my Unity class, this is used to register and resolve the TfsVCPromotionManager object:
public class UnityClass
{
public static ITfsVcPromotionManager returnNewPromotionManager(
VersionControlServer tfServer)
{
var container = new UnityContainer();
ITfsVcQaCheckinWorker test1 = CreateUnityCheckInWorker();
ITfsVcQaCheckoutWorker test2 = CreateUnityCheckOutWorker(tfServer);
container.RegisterType<ITfsVcPromotionManager, TfsVcPromotionManager>(
new InjectionConstructor(test2), new InjectionConstructor(test1));
return container.Resolve<TfsVcPromotionManager>();
}
private static ITfsVcQaCheckinWorker CreateUnityCheckInWorker()
{
var container = new UnityContainer();
container.RegisterType<ITfsVcQaCheckinWorker, ITfsVcQaCheckinWorker>();
return container.Resolve<TfsVcQaCheckinWorker>();
}
private static ITfsVcQaCheckoutWorker CreateUnityCheckOutWorker(
VersionControlServer passedServer)
{
var container = new UnityContainer();
container.RegisterType<ITfsVcQaCheckoutWorker, TfsVcQaCheckoutWorker>(
new InjectionConstructor(passedServer));
return container.Resolve<TfsVcQaCheckoutWorker>();
}
}
This is the constrcutor os the TfsVcPromotionManager class. note that it clearly takes in an instance based on the interfaces ITfsVcQaCheckoutworker and ITfsVcCheckinWorker.
private ITfsVcQaCheckoutWorker _checkOutWorker;
private ITfsVcQaCheckinWorker _checkInWorker;
public TfsVcPromotionManager(ITfsVcQaCheckoutWorker checkOutWorker,
ITfsVcQaCheckinWorker checkInWorker)
{
if (checkOutWorker == null || checkInWorker == null)
{
throw new NullReferenceException();
}
_checkOutWorker = checkOutWorker;
_checkInWorker = checkInWorker;
}
Can anyone give me an indication of what I'm doing wrong.