NMock DynamicMock - Inherited Interface Members

  • Thread starter Thread starter colinjack
  • Start date Start date
C

colinjack

Hi All,

Not sure if this is the correct forum for this but I cant seem to find
a more specific one for NMock...

I'm trying to use the dynamic mocking functionality of NMock and,
whilst its great, I've run into a problem. Say intefaceA derives from
interfaceB and so gets interfaceB's members:

public interfaceA : intefaceB
{
...
}

public interfaceB
{
public bool Blah { get; }
}

Ok now I want to create a dynamic mock for interfaceA:

DynamicMock dynamicMockInfo = new DynamicMock(typeof(interfaceA));
dynamicMockInfo.SetupResult("Blah", true, new Type[0]);

Thing is it fails with a NullReferenceException in nmock.dll, and will
only work if I also put the Blah property into interfaceA. Anyone got
any idea how I resolve this?

Ta,

Colin
 
colinjack said:
Not sure if this is the correct forum for this but I cant seem to find
a more specific one for NMock...

I'm trying to use the dynamic mocking functionality of NMock and,
whilst its great, I've run into a problem. Say intefaceA derives from
interfaceB and so gets interfaceB's members:

public interfaceA : intefaceB
{
...
}

public interfaceB
{
public bool Blah { get; }
}

Ok now I want to create a dynamic mock for interfaceA:

DynamicMock dynamicMockInfo = new DynamicMock(typeof(interfaceA));
dynamicMockInfo.SetupResult("Blah", true, new Type[0]);

Thing is it fails with a NullReferenceException in nmock.dll, and will
only work if I also put the Blah property into interfaceA. Anyone got
any idea how I resolve this?

Personally, I'd suggest giving EasyMockNET a go instead :)
http://sourceforge.net/projects/easymocknet/

I recently evaluated (fairly briefly) NMock, EasyMockNET and one other
whose name escapes me. EasyMockNET follows the EasyMock model, which
means you call the methods directly on the mock you've created - much
nicer than specifying the method name as a string!

Unfortunately, the distribution is just a DLL at the moment which
requires an old version of NUnit. I fetched the whole thing from CVS
and added a very simple AssertionException, which is all it really uses
from NUnit. That way you also get the documentation, which bizarrely is
only in CVS!

Just to warn you, EasyMockNET doesn't seem to have had any publicity,
and seems to be almost abandoned at the moment (no code changes in 5
months). However, it seems to work well, and I'm going to try to find
out what the project status really is, and probably volunteer as a
maintainer. (I'm using it professionally now, and we'll soon have got
enough test code for it to be a pain to change to a different framework
which doesn't have the same abilities.)
 
Hi Jon,

Ahh yes I'd had a look at that too and decided against using it simply
because .NET unit testing articles seem to focus on NMock but now
you've recommended I'll give it a shot.

Thanks,

Colin Jack
 
Back
Top