After creating fakes and setting behaviors. we come to the end of our journey (until next release, when new APIs will appear) – verification.
The syntax makes the tests much more readable. You specify exactly what you expect to have happened.
Verify comes in 3 flavors:
- WasCalledWithExactArguments – The method was called at least once, with the exact parameters specified.
- WasCalledWithAnyArguments – The method was called at least once, regardless of parameters.
- WasNotCalled – Well, you can guess this one.
In future releases, we’re going to add more features around this, like number of times the method was called, more specific checks, and if specific instances got created.
Verify also works great with chains. Have a look at this example:
1 |
[TestMethod]<br />[Isolated]<br /><span class="kwrd">public</span> <span class="kwrd">void</span> RecursiveStubsWithChainExpectation()<br />{<br /> RealLogger fake = Isolate.Fake.Instance<RealLogger>(Members.ReturnRecursiveFakes);<br /><br /> Isolate.WhenCalled(() => fake.GetSon().DoSomething(1)).WillReturn(13);<br /><br /> Assert.AreEqual(13, fake.GetSon().DoSomething(10));<br /> Isolate.Verify.WasCalledWithExactArguments(() => fake.GetSon().DoSomething(10));<br />} |
Note that the Verify clause checks that the entire chain was called. If only part of it was called, the Verify will fail, and you’ll get a nice VerifyException.
I encourage you to start using these APIs and give us feedback – on readability, coding experience, and fabulous success stories (if they are indeed related to the API).
We are already in the process of implementation of other existing features in the new syntax (first and foremost – static calls), and once they’re out I’ll post on them too. In the meanwhile – go play with these toys.