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

Le mardi 7 août 2012 05:16:12 UTC-4, Mirko Seifert a écrit :
>
> Hi,
>
> is there a way to get a list of all methods that were invoked on a mocked 
> object?
>
> I've tried using GetArgumentsForCallsMadeOn() but this required to specify 
> the methods I'm interested in. Rather, I want all calls.
>
> Thanks in advance,
>
> Mirko
>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rhinomocks/-/ZHWwe0WDjXsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to