Raising events in NMock

March 4, 2009

0

It is actually pretty easy to raise events using the latest release of NMock. You can basically use Expect.Once.On(bla).EventAdd(“SomeEvent”, Is.Anything) to specify that you expect an event handler to be added for “SomeEvent” event on bla object and fire that event using Fire.Event(“SomeEvent”). Here’s an example, minus any domain noise, that demonstrates the whole thing.

Posted in: .NET

Interfaces and partial classes

February 13, 2009

0

What will happen when the following piece of code is compiled? Options: Compiler error. “Moved” will be printed.

Posted in: .NET

Preventing tracing of sensitive information in logs generated using .NET trace classes

December 17, 2008

1

If you have an application that deals with payment processing, social-security numbers, etc., there’s a possibility that such sensitive information can be written to log by a component in the application. While you need to take appropriate measures to ensure that the log files are sufficiently protected, you may also want to prevent such information […]

Posted in: .NET

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 […]

Tagged:
Posted in: .NET

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 […]

Tagged: ,
Posted in: .NET

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 […]

Posted in: .NET

Using Pex to test VB.NET code

December 2, 2008

1

In an ideal world one would write unit-tests before writing any new code following the tenants of TDD. In reality it is quite common to have to rely on a legacy library to do some heavy lifting. Pex is a great new tool available from Microsoft Research that can be used to generate unit-tests automatically. […]

Tagged: , , ,
Posted in: .NET, Tech/Hacks
Follow

Get every new post delivered to your Inbox.