I'm trying to set up some Moq repositories to test my service with Castle Windsor as my IOC. Mu service depends on IFoo, so I'm creating a moq instance that implements IFoo and injecting it into the container like so:
_container.AddComponent("AutoBill",
typeof (AutoBillService), typeof (AutoBillService));
var mockUserRepository = new Mock<IUserRepository>();
var testUser = new User()
{
FirstName = "TestFirst",
LastName = "TestLast",
UID=1
};
mockUserRepository.Setup(repo => repo.GetUser(testUser.UID))
.Returns(testUser);
_container.Kernel.AddComponentInstance("UserRepository",
typeof(IUserRepository), mockUserRepository);
var service = _container.Resolve<AutoBillService>(); //FAIL
Doing this gives me an exception: System.ArgumentException: Object of type 'Moq.Mock`1[IUserRepository]' cannot be converted to type 'IUserRepository'
Can anyone see what I'm doing wrong?