public void Dispatch(object pTarget, uint index, UIAutomationParameter[] pParams, uint cParams) { // Parse the provider and parameter list var provider = (ITestProvider)pTarget; var paramList = new UiaParameterListHelper(pParams); var member = TestSchema.GetInstance().GetMemberByIndex(index); if (member != null) { member.DispatchCallToProvider(provider, paramList); return; } // Dispatch the method/property calls if (index == TestSchema.GetInstance().GetBoolValueMethod.Index) { paramList[0] = provider.BoolValue; } else if (index == TestSchema.GetInstance().GetDoubleValueMethod.Index) { paramList[0] = provider.DoubleValue; } else if (index == TestSchema.GetInstance().GetElementValueMethod.Index) { paramList[0] = provider.ElementValue; } else { throw new InvalidOperationException(); } }
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 void PassIntParam(int value, out int retVal) { // Create and init a parameter list // We can't just use the CallMethod helper because we have out-parameters var paramList = new UiaParameterListHelper(TestSchema.GetInstance().PassIntParamMethod); paramList[0] = value; // Call through PatternInstance.CallMethod(TestSchema.GetInstance().PassIntParamMethod.Index, paramList.Data, paramList.Count); // Get the out-parameter retVal = (int)paramList[1]; }
public void Dispatch(object pTarget, uint index, UIAutomationParameter[] pParams, uint cParams) { // Parse the provider and parameter list var provider = (IColorProvider)pTarget; var paramList = new UiaParameterListHelper(pParams); // Dispatch the method/property calls if (index == ColorSchema.GetInstance().ValueAsColorProperty.Index) { paramList[0] = provider.ValueAsColor; } else if (index == ColorSchema.GetInstance().SetValueAsColorMethod.Index) { provider.SetValueAsColor((int)paramList[0]); } else { throw new InvalidOperationException(); } }
private static bool DoParamsMatch(UIAutomationParameter[] pParams, object[] inArgs) { if (pParams.Length != inArgs.Length) { return(false); } var paramList = new UiaParameterListHelper(pParams); for (int i = 0; i < paramList.Count; i++) { if (UiaTypesHelper.IsInType(pParams[i].type)) { if (!inArgs[i].Equals(paramList[i])) { return(false); } } } return(true); }