Mocking Generic Methods With NMock2

Recently I was asked how to mock a generic method, now that NMock2 supports generics. Here’s how: Suppose you have this interface: public interface IMyInterface{    T DoStuff<T>();}  And this class using IMyInterface: public class MyClass{    private IMyInterface mi_;     public MyClass(IMyInterface mi)    {        this.mi_ = mi;    }     public string DoSomething()    {        return this.mi_.DoStuff<string>();    }}…

15

Generating NotImplementedException Instead Of Exception

Ever since I started using Visual Studio 2005, I’ve been enjoying its refactoring features, but it has always been bugging me that when you generate a new method stub or implement an interface or abstract class, the auto-generated method throws System.Exception instead of NotImplementedException. However, now I’ve finally found out how to change this behavior,…

0

Console Unit Testing

In many scenarios, console applications are very useful, but if you have a console application of intermediate complexity, you should obviously unit test it like all the other code you write – right? If you have a console application as an administration utility for a complex piece of software you are developing, the console application…

7

Speaking at .NET Days 2006

The week after speaking at TechEd, I’ll be giving a talk at .NET Days 2006 in Århus. In this talk, I’ll be talking a bit about data access component testing. In my terminology, these are not unit tests, but integration tests, but that does not mean that unit testing tools are not useful. In the…

0