As far as I know, there is no way to configure multiple layout methods at once. You need to specify all the methods for sending them to another implementation ...
... if you have not written a reflection code to customize the layout.
Here is the (working) code. It uses C # 3.0, but the main part is the old-style Rhino Mocks style that was written for C # 2.0.
public static class MockExtensions { public static void ForwardCalls<T>(this T mock, T original) { mock.BackToRecord(); Type mockType = typeof(T); var methods = mockType.GetMethods(BindingFlags.Public | BindingFlags.Instance) .Union(mockType.GetInterfaces().SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.Instance))); foreach (MethodInfo method in methods) { List<object> args = new List<object>(); foreach (var arg in method.GetParameters()) { args.Add(CreateDefaultValue(arg.ParameterType)); } method.Invoke(mock, args.ToArray()); var myMethod = method; if (method.ReturnType == typeof(void)) { LastCall .IgnoreArguments()
Using:
[TestClass] public class TestClass() { [TestMethod] public void Test() { var mock = MockRepository.GenerateMock<IList<int>>(); List<int> original = new List<int>(); mock.ForwardCalls(original); mock.Add(7); mock.Add(8); Assert.AreEqual(2, mock.Count); Assert.AreEqual(7, mock[0]); Assert.AreEqual(8, mock[1]);
source share