private static Action ExpectCachedPropertyCall <T>(IUIAutomationPatternInstance patternInstance, UiaPropertyInfoHelper propHelper, T returnValue)
 {
     return(ExpectPropertyCall(patternInstance, propHelper, cached: true, returnValue: returnValue));
 }
        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();
            });
        }
        private void AssertPropertyInfo(string programmaticName, UIAutomationType uiaType, string guid, UiaPropertyInfoHelper propInfo)
        {
            var data = propInfo.Data;

            Assert.AreEqual(programmaticName, data.pProgrammaticName);
            Assert.AreEqual(uiaType, data.type);
            Assert.AreEqual(new Guid(guid), data.guid);
        }