Thank you for the answers!
I've tried the GetInvokedMethods() method and after excluding a couple of
methods that throw an exception when they are invoked, the code worked.
However, the control I'm trying to test (Chart) does not seem to invoke any
methods on the Graphics object. I invoked a method (Clear()) to check
whether the mocked object is used and this call is indeed returned by
GetInvokedMethods(). Maybe Chart uses unmanaged code to draw itself?
Am Dienstag, 7. August 2012 20:03:39 UTC+2 schrieb Guillaume:
>
> 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/-/H-mI9fFvalcJ.
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.