private static Action ExpectMethodCall(IUIAutomationPatternInstance patternInstance, UiaMethodInfoHelper methodHelper, object[] inArgs, object[] outArgs)
        {
            if (inArgs.Length != outArgs.Length)
            {
                throw new ArgumentException();
            }


            Action <IUIAutomationPatternInstance> substituteCall
                = instance => instance.CallMethod(methodHelper.Index,
                                                  Arg.Any <UIAutomationParameter[]>(),
                                                  (uint)inArgs.Length);

            patternInstance.When(substituteCall)
            .Do(ci =>
            {
                // imitate what the native UIA part does after server side finishes the call
                var marshalled = (UIAutomationParameter[])ci.Args()[1];
                Assert.IsTrue(DoParamsMatch(marshalled, inArgs));
                var paramList = new UiaParameterListHelper(marshalled);
                for (int i = 0; i < marshalled.Length; i++)
                {
                    if (UiaTypesHelper.IsOutType(marshalled[i].type))
                    {
                        paramList[i] = outArgs[i];
                    }
                }
            });

            return(() =>
            {
                substituteCall(patternInstance.Received());
                patternInstance.ClearReceivedCalls();
            });
        }
        private static Action ExpectPropertyCall(IUIAutomationPatternInstance patternInstance, UiaPropertyInfoHelper propHelper, bool cached, object returnValue)
        {
            Action <IUIAutomationPatternInstance> substituteCall
                = instance => instance.GetProperty(propHelper.Index,
                                                   cached ? 1 : 0,
                                                   propHelper.UiaType,
                                                   Arg.Any <IntPtr>());

            patternInstance.When(substituteCall)
            .Do(ci =>
            {
                // imitate what the native UIA part does after server side returns result
                var marshalled    = (IntPtr)ci.Args()[3];
                var paramHelper   = new UiaParameterHelper(propHelper.UiaType, marshalled);
                paramHelper.Value = returnValue;
            });

            return(() =>
            {
                substituteCall(patternInstance.Received());
                patternInstance.ClearReceivedCalls();
            });
        }