开发者

mocking/stubbing framework for C# dynamic objects [closed]

Closed.开发者_运维百科 This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 years ago.

Improve this question

I am looking for a framework that I can use with testing C# code that uses dynamic objects. I want to be able to specify method stubs and set mock expectations like you would do using something like Rhino Mocks on interfaces

e.g. something like the following using the Rhino Mocks style

var fakeService = MockRepository.GenerateStub<dynamic>();
fakeService.Stub(s => s.SomeMethod(Arg.Is(someValue))).Returns(someResult);
sut.MethodUnderTest(fakeService);

or

var fakeService = MockRepository.GenerateMock<dynamic>();
fakeService.Expect(s => s.DoSomething(Arg.Is(someValue)));
sut.MethodUnderTest(fakeService);
fakeService.VerifyAllExpectations();

where the method under test declares the parameter as a dynamic object.

Any suggestions?


Well you could always try mocking DynamicObject. It would look a bit different but it mocks a dynamic object with whatever you want.

var fakeService = MockRepository.GenerateStub<DynamicObject>();
object outResult;
fakeService.Stub(s => s.TryInvokeMember(
               Property.Value("Name", "SomeMethod"),
               List.Equal(new{someValue}),
               out outResult))
           .OutRef(someResult)
           .Returns(true);
sut.MethodUnderTest(fakeService);

P.S. please excusing any rhino mocks syntax issues, i've done this using MOQ before and I just wrote out the same concept with the Rhino Mocks quick reference guide.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜