The DoNothing method is used to arrange that a call to a method or property should be ignored.
We will use the following interface for the examples in this article:
Assert Void Call
Before describing the usage of the DoNothing method, let's first see an example to illustrate it.
In the example, we mark foo.VoidCall() with DoNothing and MustBeCalled. In this way we indicate
that a call to foo.VoidCall must be ignored, but still the method should be called during the execution of the test. We can achieve the same behavior without
marking the call with DoNothing. Marking it explicitly improves the code readability. The DoNothing method makes no
functional difference in the test execution, just a good practice to improve your code. The following two lines are functionally equivalent.
You can use DoNothing with non-void calls as well. For the example we will be using the
following Foo class:
Assert DoNothing on property set
DoNothing can be also used on a call to a property set.