I want to mock a specific expression in one of my repositories and I'm having some trouble.
I currently have:
Mock<Container> returnContainer = new Mock<Container>();
Mock<IRepository<Container>> CntnrRepository =
new Mock<IRepository<Container>>();
CntnrRepository.Setup<Container>(repo => repo
.Find(x => x.Name == "foo")
.Returns(returnContainer.Object);
Whenever the following code runs it's returning null instead of my Mock<Container>
above.
Container found =
containerRepository.Find(x => x.Name == cntnrName);
What am I doing wrong here?
Edit
Below is the code that is using the injected repository:
public int Foo(Guid id, string name)
{
Container found =
containerRepository.Find(x => x.Name == name);
if (found != null)
return CONTAINER_NOT_FREE;
Container cntnrToAssociate =
containerRepository.Find(x => x.Id == cntnrId);
if (cntnrToAssociate == null)
return CONTAINER_NOT_FOUND;
return OK;
}
In the code above for one of my tests I need to return a value only in the first query (Find
) to the containerRepository