Browsing All posts tagged under »nmock«

Mocking functions taking variable number of args using C# params keyword

December 16, 2008

1

Consider the following interface that takes a variable number of arguments in its Add method. And consider that we have to test the following function which invokes Add with two arguments. The expectation created below is incorrect: It will cause NMock to generate the following exception because NMock is expecting two distinct arguments to Add… [Read more…]

Fluently mocking fluent APIs

December 15, 2008

0

The best thing about fluent-style APIs is that they are readable and flow easily. Consider the following for example: The API used above is clearly more readable than: Another reason I like them is that fluent style APIs are easier to pick up. You can rely on intellisense to guide you more as you have… [Read more…]

Testing methods that depend upon a singleton class

December 11, 2008

3

Singleton is probably one of the most (mis-)used design patterns. In this article I intend to lay out a scenario and then demonstrate how we can go about testing methods that depend upon a singleton class. Finally I’ll recap the whole approach in a bulleted list for easy reference. Let’s restrict our problem to involve… [Read more…]

Mocking indexers with NMock

November 25, 2008

0

Indexers allow objects to behave like arrays. Dictionary class in .NET, for example, provides an indexer that allows the retrieval of the item from the dictionary that corresponds to a particular key. There are two ways you can go about mocking indexers defined on interfaces when using NMock. You can use the Get property to… [Read more…]

NMock expectations for functions accepting “ref” and “out” arguments

November 17, 2008

3

There appears to be inadequate documentation on setting up expectations in NMock for methods that accept arguments by reference using “out” and “ref” keywords. Here is a quick note to give an example demonstrating how it can be done. Consider the following interface: “Bar” method takes one “out” parameter and another “ref” parameter. To start… [Read more…]

Follow

Get every new post delivered to your Inbox.