Regional Accents

Jay Fields wonders when it is appropriate to use #region blocks in C#. I've found a good use them! Here's a test from nMock 2, a port of jMock to C# that I've been writing on and off over the last few weeks.

region1.gif

What's the value of ANY_NUMBER? You shouldn't care! It means any number. So I hid the declaration in a region. If the reader opens that region:

region2.gif

What, you really want to know? Ok, but don't say I didn't warn you.

region3.gif

Did I say it was a good use of regions? Perhaps that was not completely accurate.

Posted on May 16, 2005 [ Permalink ]
Comments

LoL. What's the advantage of your NMock2 over NMock itself?

Posted by: Jeremy Miller at May 16, 2005 7:47 PM

LOL, very nice.

Posted by: Jay Fields at May 16, 2005 8:13 PM

NMock is a port of an old version of my old Java DynaMock library. The API is inflexible, hard to extend and makes tests brittle. NMock2 is a port of jMock, which itself fixed a lot of the problems with DynaMock, with additional changes to fix problems we've discovered in jMock.

In particular, in nMock2 mock objects will have the correct type: no need to call .proxy() or .MockInstance and then cast the result whenever you want to use a mock object. NMock2 has lots of support for C# features: you can expect method calls, property or indexer getter and setters and the adding and removing of event listeners. NMock2 supports operator overloading to combine Matchers (what jMock calls Constraints). Finally, nMock2 works with NUnit and doesn't require the test case to derive from any specific base class.

Posted by: Nat Pryce at May 17, 2005 9:08 AM