FakeItEasy and a case of method configuration

By | April 24, 2015
Recently while writing unit tests for a device driver I came across a situation.

I had to simulate the call to the device to wait for sometime and then throw an error and then check if I handled it properly.

This helped.

This configures the Start method (which in real life issues command to the device and waits for response) to wait for 1 sec and then throw.

    Where(x => x.Method.Name == "Start").
    Invokes( x=> Thread.Sleep(1000)).
    Throws(new InvalidOperationException());


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.