开发者

NUnit and NMock- ExpectAndReturn - How to tell NMock to expect CreateObjectSet<T>

开发者 https://www.devze.com 2023-04-09 16:07 出处:网络
I have the following var objSet = new DynamicMock(typeof(IObjectSet<Nationality>)); objSet.ExpectAndReturn(\"GetAll\", new List<Nationality>

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&g开发者_如何学运维t;()

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


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>());
0

精彩评论

暂无评论...
验证码 换一张
取 消