I want to test a delete methode.
The delete methode is called in a mocked service (not mocked with moq).
The service manages a list of objects. The class of the objects is derived from a base class overriding equals().
public override bool Equals(object obj) {
if (obj == null || GetType() != obj.GetType()) {
return false;
}
BaseClass testObj = (BaseClass)obj;
return BusinessId.Equals(testObj.BusinessId);
}
When I call
serive.GetAll().Contains(objectInList);
I get false.
The Equals method in the base class is not called.
The objects in the list are mocked with moq.
Mock<TypeOfObject> objectMock = new Mock<TypeOfObject>();
objectMock.SetupGet(pf => pf.BusinessId).Returns(guid);
return objectMock.Object;
How do I have to setup the mock that the Equals-Methode of the base class is called and the Contains-method returns true?
Thanks in advance.
You can make the mock to call your Equals method by settings Mock.CallBase property to true, e.g.: