-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call times verification change from 4.11.0 #990
Comments
Possibly related to #904. If so (I haven't yet had time to look at this in-depth), then the change would be intended. |
Great point, definitely with no doubt as "Moq no longer considers the return type as part of a method's signature like it used to (and that is generally a good thing)". The only thing I'd like to clear - if we have
also fails with
|
@Caraul, what about the following scenario: public interface IFruit { }
public class Apple : IFruit { }
public class Banana : IFruit { }
public interface IEat
{
void Eat<T>(T item);
}
var stakxMock = new Mock<IEat>();
var stakx = stakxMock.Object;
stakx.Eat(new Apple());
stakx.Eat(new Banana());
stakxMock.Verify(s => s.Eat(It.IsAny<IFruit>()), Times.Exactly(2)); Here we verify that I ate any two fruit. Since I ate one apple and one banana (both of which are fruit), I believe verification should pass. However, if we went along with your suggestion, verification would fail because I didn't eat two abstract fruit; I ate a concrete apple and a concrete banana. That doesn't really make much sense in my book. |
P.S.: I believe you could define a custom type matcher (those were introduced with version 4.13) to match a precise type while excluding its subtypes; see #908. |
As being a monkey some millenniums ago I have to agree :) Closing this issue, thanks for pointing out to custom type matchers. |
Repro 4.13.1:
throws:
Expected invocation on the mock once, but was 2 times: xyz => xyz.M<Program.A>()
Performed invocations:
MockProgram.IXyz:1 (xyz):
Works in 4.11.0 - looks like in 4.11.0 Moq also took in account return types during verification. Is it intended behaviour change?
The text was updated successfully, but these errors were encountered: