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();
            });
        }
        public PatternClientInstanceInterceptor(CustomPatternSchemaBase schema, IUIAutomationPatternInstance patternInstance)
        {
            _patternInstance = patternInstance;
            _currentPropGetterNameToHelper = schema.Properties.ToDictionary(helper => string.Format("get_Current{0}", helper.Data.pProgrammaticName));
            _cachedPropGetterNameToHelper = schema.Properties.ToDictionary(helper => string.Format("get_Cached{0}", helper.Data.pProgrammaticName));

            // helpers are aware about provider methods, we have to map them from client-side pattern methods
            _methodInfoToHelper = new Dictionary<MethodInfo, UiaMethodInfoHelper>();
            foreach (var methodInfoHelper in schema.Methods)
            {
                var providerInfo = methodInfoHelper.ProviderMethodInfo;
                if (providerInfo == null) continue;

                var patternMethod = ProviderPatternMatcher.GetMatchingPatternMethod(schema.PatternClientInterface, providerInfo);
                if (patternMethod != null)
                    _methodInfoToHelper[patternMethod] = methodInfoHelper;
            }
        }
        public PatternClientInstanceInterceptor(CustomPatternSchemaBase schema, IUIAutomationPatternInstance patternInstance)
        {
            _patternInstance = patternInstance;
            _currentPropGetterNameToHelper = schema.Properties.ToDictionary(helper => string.Format("get_Current{0}", helper.Data.pProgrammaticName));
            _cachedPropGetterNameToHelper  = schema.Properties.ToDictionary(helper => string.Format("get_Cached{0}", helper.Data.pProgrammaticName));

            // helpers are aware about provider methods, we have to map them from client-side pattern methods
            _methodInfoToHelper = new Dictionary <MethodInfo, UiaMethodInfoHelper>();
            foreach (var methodInfoHelper in schema.Methods)
            {
                var providerInfo = methodInfoHelper.ProviderMethodInfo;
                if (providerInfo == null)
                {
                    continue;
                }

                var patternMethod = ProviderPatternMatcher.GetMatchingPatternMethod(schema.PatternClientInterface, providerInfo);
                if (patternMethod != null)
                {
                    _methodInfoToHelper[patternMethod] = methodInfoHelper;
                }
            }
        }
        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();
            });
        }
Ejemplo n.º 5
0
 public void CreateClientWrapper(IUIAutomationPatternInstance pPatternInstance, out object pClientWrapper)
 {
     pClientWrapper = new TestProviderClientInstance(pPatternInstance);
 }
 public TestProviderClientInstance(IUIAutomationPatternInstance patternInstance)
     : base(patternInstance)
 {
 }
 protected CustomClientInstanceBase(IUIAutomationPatternInstance patternInstance)
 {
     PatternInstance = patternInstance;
 }
        public void CreateClientWrapper(IUIAutomationPatternInstance pPatternInstance, out object pClientWrapper)
        {
            var interceptor = new PatternClientInstanceInterceptor(_schema, pPatternInstance);

            pClientWrapper = _proxyGenerator.CreateInterfaceProxyWithoutTarget(_schema.PatternClientInterface, interceptor);
        }
 public void CreateClientWrapper(IUIAutomationPatternInstance pPatternInstance, out object pClientWrapper)
 {
     pClientWrapper = new ColorProviderClientInstance(pPatternInstance);
 }
 public void CreateClientWrapper(IUIAutomationPatternInstance pPatternInstance, out object pClientWrapper)
 {
     var interceptor = new PatternClientInstanceInterceptor(_schema, pPatternInstance);
     pClientWrapper = _proxyGenerator.CreateInterfaceProxyWithoutTarget(_schema.PatternClientInterface, interceptor);
 }
 public ColorProviderClientInstance(IUIAutomationPatternInstance patternInstance)
     : base(patternInstance)
 {
 }
 protected CustomClientInstanceBase(IUIAutomationPatternInstance patternInstance)
 {
     PatternInstance = patternInstance;
 }
        private IAttrDrivenTestPattern GetClientWrapper(AttributeDrivenPatternSchema schema, IUIAutomationPatternInstance patternInstance)
        {
            object wrapperObj;

            schema.Handler.CreateClientWrapper(patternInstance, out wrapperObj);
            return((IAttrDrivenTestPattern)wrapperObj);
        }
 private static Action ExpectCachedPropertyCall <T>(IUIAutomationPatternInstance patternInstance, UiaPropertyInfoHelper propHelper, T returnValue)
 {
     return(ExpectPropertyCall(patternInstance, propHelper, cached: true, returnValue: returnValue));
 }