Hi,
Did you want something like that?
using System;
using System.Linq;
using System.Reflection;
using Rhino.Mocks;
public static class RhinoMocksCustomExtensions
{
public static MethodInfo[] GetInvokedMethods<T>(this T target)
{
return typeof(T).GetMethods().Where(m => target.GetArgumentsForCallsMadeOn(
x => m.Invoke(x,
m.GetParameters().Select(p => p.ParameterType.IsValueType ? Activator.CreateInstance(p.ParameterType) : null).ToArray())
, e => e.IgnoreArguments()).Count != 0).ToArray();
}
}
It should give you an array containing every invoked method on the target.
Test :
public interface ITestClass
{
void ShouldBeInvoked(string testString, int testInt);
void ShouldNotBeInvoked();
}
/// <summary>
///Test pour GetInvokedMethods
///</summary>
[TestMethod()]
public void GetInvokedMethodsTest()
{
ITestClass mock = MockRepository.GenerateMock<ITestClass>();
mock.ShouldBeInvoked("whatever", 42);
var invoked = mock.GetInvokedMethods();
Assert.AreEqual(1, invoked.Count());
Assert.IsTrue(invoked.First().Name.Equals("ShouldBeInvoked"));
}
Have a nice day.
Guillaume Loiselle