mardi 31 mars 2015

Using Moq With Castle Windsor

I am trying to do a simple unit test of my home controller using Moq but I'm getting an exception of


An exception of type "'Castle.MicroKernel.ComponentNotFoundException' occurred in Castle.Windsor.dll but was not handled in user code. No component for supporting the service OrderTrackingSystem.Core.Repositories.IRepository was found" in my HomeController on the line "_repository = MvcApplication.Container.Resolve()".



private IRepository _repository;
_repository = MvcApplication.Container.Resolve<IRepository>();

public HomeController(IRepository repository)
{
_repository = repository;
}


Here is my unit test code.



[TestClass]
public class HomeControllerTests
{
private Mock<IRepository> _repositoryMock;

[TestInitialize]
public void TestSetup()
{
_repositoryMock = new Mock<IRepository>();
}

[TestMethod]
public void HomeControllerIndexReturnsAView()
{
// Arrange
var controller = new HomeController(_repositoryMock.Object);

// Act
var result = controller.Index() as ViewResult;

// Assert
Assert.IsNotNull(result);
}
}


I feel like I must be missing something simple with registering or setting up the repository in my unit test. Any ideas?


Aucun commentaire:

Enregistrer un commentaire