public void PatternHandler_DispatchesPropertiesCorrectly()
        {
            var schema = new AttributeDrivenPatternSchema(typeof(IAttrDrivenTestProvider), typeof(IAttrDrivenTestPattern));

            schema.Register();

            var paramHelper = new UiaParameterHelper(UIAutomationType.UIAutomationType_OutBool);
            var pParams     = new[] { paramHelper.ToUiaParam() };

            var p = Substitute.For <IAttrDrivenTestProvider>();

            p.BoolProperty.Returns(true);
            schema.Handler.Dispatch(p, schema.Properties[0].Index, pParams, 1);
            Assert.AreEqual(true, paramHelper.Value);

            p.BoolProperty.Returns(false);
            schema.Handler.Dispatch(p, schema.Properties[0].Index, pParams, 1);
            Assert.AreEqual(false, paramHelper.Value);
        }
        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();
            });
        }