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

            schema.Register();

            var pParams = new UIAutomationParameter[0];

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

            schema.Handler.Dispatch(p, schema.Methods[0].Index, pParams, 0);
            p.Received().VoidParameterlessMethod();
        }
        public void ClientWrapper_CachedPropertyCalled_MakesCorrectRequestToPatternInstance()
        {
            var schema = new AttributeDrivenPatternSchema(typeof(IAttrDrivenTestProvider), typeof(IAttrDrivenTestPattern));

            schema.Register();

            var patternInstance = Substitute.For <IUIAutomationPatternInstance>();
            var wrapper         = GetClientWrapper(schema, patternInstance);

            var propHelper = schema.Properties.First(p => p.Data.pProgrammaticName == Provider.IntPropertyProperty.Name);
            var verifier   = ExpectCachedPropertyCall(patternInstance, propHelper, returnValue: 42);

            var val = wrapper.CachedIntProperty;

            verifier();
            Assert.AreEqual(42, val);
        }
        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);
        }
        public void ClientWrapper_BoolMethodWithIntAndOutStringParamsCalled_MakesCorrectRequestToPatternInstance()
        {
            var schema = new AttributeDrivenPatternSchema(typeof(IAttrDrivenTestProvider), typeof(IAttrDrivenTestPattern));

            schema.Register();

            var patternInstance = Substitute.For <IUIAutomationPatternInstance>();
            var wrapper         = GetClientWrapper(schema, patternInstance);

            var methodHelper = schema.Methods.First(m => m.Data.pProgrammaticName == Provider.BoolMethodWithInAndOutParams.Name);
            var inArgs       = new object[] { 42, null, null };
            var outArgs      = new object[] { null, "abc", true };
            var verifier     = ExpectMethodCall(patternInstance, methodHelper, inArgs, outArgs);

            string strResult;
            var    boolResult = wrapper.BoolMethodWithInAndOutParams(42, out strResult);

            verifier();
            Assert.AreEqual("abc", strResult);
            Assert.AreEqual(true, boolResult);
        }
        public void AttributeDrivenPatternSchema_AssertRegistrationGoesSmoothly()
        {
            var schema = new AttributeDrivenPatternSchema(typeof(IAttrDrivenTestProvider), typeof(IAttrDrivenTestPattern));

            schema.Register();
        }