mocking/stubbing framework for C# dynamic objects [closed]
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 questionI 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.
精彩评论