Typemock – Beautiful exceptions

So I recently started to use Typemock instead of Moq and I’m currently getting acquainted with the API. I just found something that I really think shows that they are putting in some effort to the product. It’s no fancy feature just something that I think every Mocking-framework should provide: “Informative and guiding exceptions when you use the framework inappropriately.”

Take this for an example:

[Test, Isolated]
public void Execute_WhenNoNotationExistsAndDateIsToday_RegistrationIsAllowed()
    var scenario = new RegisterSleepNotationScenario().ConfigureParams(
        p => p.NewSleepNotation = new SleepNotation(new Kid(), Week.Current, DayOfWeek.Monday, 1, 50));
    var sleepNotationsSourceFake = Isolate.Fake.Instance<IEditableObjectSource<SleepNotation>>();
    scenario.SleepNotaionsSource = sleepNotationsSourceFake;


        () => sleepNotationsSourceFake.Insert(scenario.Params.NewSleepNotation));

This test resulted in the following exception from Typemock:

This informative message then lead me to the small change:

var expectedNewSleepNotation = scenario.Params.NewSleepNotation;
Isolate.Verify.WasCalledWithExactArguments(() => sleepNotationsSourceFake.Insert(expectedNewSleepNotation));

Which resulted in a green test and a happy developer, without having to use Google or the Typemock-documentations to search for: “how to consume WasCalledWithExactArguments”. As it should be. Thank you Typemock!


5 thoughts on “Typemock – Beautiful exceptions

    • Hi,
      The image looks good to me. Don’t understand why you can’t see it.

      Well it says:

      Verify does not support using a property call as an argument.
      – To fix this extract the call for RegisterSleepNotationScenarioParams.NewSleepNotation to a variable and pass it instead


  1. So I guess someone might think the code is hard to read. I totally agree and the code has been rewritten to not use the Configure methods etc, but instead a request/response solution, but that’s not the point of this post. The point is….

    The good guidance from Typemock.


  2. Pingback: Tweets that mention Typemock – Beautiful exceptions « Daniel Wertheim -- Topsy.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s