0

I have the following

var objSet = new DynamicMock(typeof(IObjectSet<Nationality>));
objSet.ExpectAndReturn("GetAll", new List<Nationality>
{
 new Nationality 
 {
    //obj init here
 },
 new Nationality 
 {
    //obj init here
 }
}.AsQueryable());

which works just fine (I can call blah.GetAll() and I get the expected list back).

What I'd like to do (if possible?) is tell another DynamicMock to expect a method with the following signature

obj.CreateObjectSet<RandomCustomType>()

But I am unsure of how to include/configure the call to expect the '<Type>'.

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
glosrob
  • 6,631
  • 4
  • 43
  • 73

1 Answers1

1

I'm pretty sure NMock 1.x doesn't support Generic methods, and it's no longer supported. What about moving to another mocking framework other than NMock, which has typed interface, and not based on hardcoded strings?
In Rhino Mocks (for example) you could do this as follows (example taken from yet another StackObverflow question):

  var fakeSession = MockRepository.GenerateMock<ISession>();
  fakeSession.Expect(s => s.Query<SomeClass>());
Community
  • 1
  • 1
Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
  • I rather feared that might be the best advice - this is part of an old project at work, partially covered by unit tests using NUnit. Think I might just refactor them to use Rhino Mocks. Have tried this issue with RhinoMocks using method you suggested and sorted the problem - thanks! – glosrob Sep 30 '11 at 19:44