Skip to Content
Windows Developer Power Tools
book

Windows Developer Power Tools

by James Avery, Jim Holmes
December 2006
Intermediate to advanced
1312 pages
35h 17m
English
O'Reilly Media, Inc.
Content preview from Windows Developer Power Tools

10.10 Creating Strongly Typed Mocks with Rhino.Mocks

You need to create mock objects to let you decouple your work from external resources, but you’re running into some problems. What do you do if you need to create mock objects for classes with no default constructors, or classes with parameterized constructors? What about generic objects? What do you do if you need to explicitly check the order of methods called on mocked objects? And wouldn’t it be nice if you could use strongly typed mocked objects, so you could access methods and properties directly when writing tests, instead of passing in strings of names (which, by the way, aren’t checked at compile-time, so you won’t know you’ve made a mistake until you run your tests)?

Rhino.Mocks, by Oren Eini, offers an attractive alternative to the NMock and NMock 2.0 libraries. Rhino.Mocks’s model creates strongly typed mock objects, so you’ll get full IntelliSense support as you’re coding. Also, the IDE and compiler will point out errors as you work, so you won’t have to wait until runtime to find you’ve mistyped a string representing a method name.

Rhino.Mocks enables you to mock up classes as well as interfaces. It also supports calling parameterized constructors. Rhino.Mocks has a very rich set of constraints you can place against expectations, and you can specify that recorded expectations must occur in a specific order. Rhino.Mocks supports generic classes and working with generic methods, which is of great importance to developers ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Introducing .NET 6: Getting Started with Blazor, MAUI, Windows App SDK, Desktop Development, and Containers

Introducing .NET 6: Getting Started with Blazor, MAUI, Windows App SDK, Desktop Development, and Containers

Nico Vermeir
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 0596527543Errata PagePurchase book