Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best style/syntax to use with Rhino Mocks?

Multiple approaches exist to write your unit tests when using Rhino Mocks:

  • The Standard Syntax
  • Record/Replay Syntax
  • The Fluent Syntax

What is the ideal and most frictionless way?

like image 680
Ray Avatar asked Sep 10 '08 17:09

Ray


People also ask

Which is a valid mock type using Rhino?

Mock OptionsStrict Mock. A strict mock requires you to provide alternate implementations for each method/property that is used on the mock. If any methods/properties are used which you have not provided implementations for, an exception will be thrown. Dynamic Mock.


1 Answers

For .NET 2.0, I recommend the record/playback model. We like this because it separates clearly your expectations from your verifications.

using(mocks.Record())
{
    Expect.Call(foo.Bar());
}
using(mocks.Playback())
{
    MakeItAllHappen();
}

If you're using .NET 3.5 and C# 3, then I'd recommend the fluent syntax.

like image 101
Judah Gabriel Himango Avatar answered Sep 30 '22 19:09

Judah Gabriel Himango