We are using Rhino Mocks to perform some unit testing and need to mock two interfaces. Only one interface is implemented on the object and the other is implemented dynamically using an aspect-oriented approach. Is there an easy way to combine the two interfaces dynamically so that a mock can be created and the methods stubbed for both interfaces?
Using Rhino Mocks
var mock = MockRepository.GenerateMock<IFirst, ISecond>();
mock.Stub(m => m.FirstProperty).PropertyBehavior();
((ISecond)mock).Stub(k=> k.SecondProperty).PropertyBehavior();
Found and used the information from http://www.richard-banks.org/2010/08/mocking-comparison-part-11-multiple.html
It's not dynamic, but certainly easy: create an interface within your testing assembly which does nothing other than implementing the other two interfaces:
internal interface ICombined : IFirstInterface, ISecondInterface {}
Then mock ICombined
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With