Lack of event support in NMock disappointing

I have been using NMock more and more at work, since I am starting to fully embrace test-driven development. Unfortunately, NMock does not support events. If you set Mock.Strict = True, as I do in most of my tests where I use dynamic mock objects, calling Mock.Verify will generate an exception if an event is raised.

For each event in a class, the the C# compiler generates a add_Event, remove_Event and raise_Event member from the declaration event EventHandler Event. Intuitively, NMock should allow you to call Mock.Expects("add_Event"), but it doesn’t, so the only alternative is to write my own mock. Oh, well. That is what I had to do before I started using a dynamic mock object framework.

4 Responses to “Lack of event support in NMock disappointing”

  1. barak says:

    Hi

    Can i have the code for event support

  2. [...] for over a year now. In that time, not much development has taken place. I mentioned in a previous entry that NMock lacks support for events. It also has a few other bugs that have been stac [...]

  3. [...] Experimenting with the Model View Presenter pattern in .NET, I was bothered by an apparent limitation in various dynamic mock frameworks. I want dynamic mocks to stub out my views. I find tha [...]

  4. [...] Experimenting with the Model View Presenter pattern in .NET, I was bothered by an apparent limitation in various dynamic mock frameworks. I want dynamic mocks to stub out my views. I find tha [...]

Leave a Reply