Reputation: 10474
I have the following interface:
public interface IUserRepository : IRepositoryBase
{
void AddUser(User user);
}
IRepositoryBase
has a method Update(params object[] entities)
.
Now I want to check what goes into this method in Moq. What I tried is something like this:
// ARRANGE
var userRepositoryMock = new Mock<IUserRepository>();
(...)
// ASSERT
userRepositoryMock.Verify(mock =>
mock.Update(It.Is<User>(
u => u.CreationDate.Date == DateTime.Today
&& u.Email == expectedEmail
&& u.FullName == expectedFullName
&& u.Name == expectedUserName)),
Times.Once,
"The existing user should be updated with the correct information.");
Unfortunately, since the Update
method is part of the interface where the IUserRepository inherits from I cannot access it. That it is part of the base class can be seen in the error message:
Moq.MockException
Expected invocation on the mock once, but was 0 times (...)
Performed invocations:
IUserRepository.AddUser(User)
IRepositoryBase.Update(System.Object[])
IRepositoryBase.SaveChanges()
Does anyone know how to inspect the method calls of a base interface?
Upvotes: 0
Views: 480
Reputation: 491
The IUserRepository effectively absorbs the members of the base repository so this isn't the issue.
Your Update method takes an object array so this is what you need to verify against. We can see in the performed invocations that your method is indeed being called with an object array. Your verification is set up against just a single User (which the compiler allows due to the params keyword).
The params keyword is really just a compiler trick to make it easier to pass in 0 or more arguments. An array will be created under the hood containing all the arguments.
Upvotes: 3