Just for the record, I *like* that "mock.Object crap". It's clear
which object one is working with.
Just so you know.
/bs
> Why do you need that knowledge? What for?
For clarity. In case I'm not the guy who has to make the next change
and breaks that test.
> Imagine they are removed: will it hamper the readability of your
tests?
Yes.
For me, 1 is clearer than 2
1.------------------
Mock<ISomething> mockedSomething = new Mock<ISomething>();
mockedSomething.Setup(...)
mockedSomething.Setup(...)
SomethingUser.Method(mockedSomething.object);
mockedSomething.Verify(...)
2.------------------
Mock<ISomething> mockedSomething = new Mock<ISomething>();
mockedSomething.Setup(...)
mockedSomething.Setup(...)
SomethingUser.Method(mockedSomething);
mockedSomething.Verify(...)
YMM,AOD,V
> Also I don't understand why some people prefix their mocked variables
> with "mock" -
Again, for clarity.
> Just try with small tests and see, that stuff actually make tests
*less* readable (imho).
I have, and it doesn't. For me, IMNECTHO.
/bs
Now instead of
=============================================
bus.Verify(x => x.Send(It.Is<SomethingCreated>(y => y.CorrelationId ===============================================
correlationId)));
of you can use a somewhat less verbose
=============================================
bus.Verify(x => x.Send(Correlation(correlationId)));
...
public Match<SomethingCreated> Correlation(int id)
{
return new Match<SomethingCreated>(x => x.CorrelationId == id);
}
=============================================
Hope this helps,
mock.Verify(x => x.Foo(A.String, A.String));but you would need one for each type (until C# 6.0 maybe :-P with return type inference and generic properties).