private void getAndConditions(string name, string automationId, string className, string controlType)
        {
            ResultAndCondition = null;

            var cmdlet =
                new GetControlCmdletBase {
                Name = name, AutomationId = automationId, Class = className, CaseSensitive = false
            };

            var common =
                new CommonCmdletBase();

            // 20131128
            //ResultAndCondition =
            //    (common.GetControlConditionsForWildcardSearch(cmdlet, controlType, cmdlet.CaseSensitive, true) as AndCondition);
            // 20131129
            // ResultAndCondition =
            //     (common.GetControlConditionsForWildcardSearch(cmdlet, controlType, cmdlet.CaseSensitive));
            ResultAndCondition =
                // common.GetWildcardSearchCondition(cmdlet) as AndCondition;
                ControlSearcher.GetWildcardSearchCondition(
                    new ControlSearcherData {
                Name          = name,
                AutomationId  = automationId,
                Class         = className,
                CaseSensitive = false
            }) as AndCondition;
        }
        private void checkConditionsArray(
            string controlType,
            string controlTypeProperty,
            string controlTypeValue)
        {
            Condition[] conditions = null;
            cmdlet =
                new UIAutomation.Commands.GetUiaControlCommand();
            cmdletBase =
                new GetControlCmdletBase();

            Condition condition =
                // cmdlet.GetWildcardSearchCondition(cmdlet);
                ControlSearcher.GetWildcardSearchCondition(
                    new ControlSearcherData {
                // completely new
                Name         = cmdlet.Name,
                AutomationId = cmdlet.AutomationId,
                Class        = cmdlet.Class,
                Value        = cmdlet.Value,
                ControlType  = cmdlet.ControlType
            });

            // 20140630
            // conditions = ((AndCondition)condition).GetConditions();
            if (null != condition as AndCondition)
            {
                conditions = ((AndCondition)condition).GetConditions();
            }
            else if (null != condition as OrCondition)
            {
                conditions = ((OrCondition)condition).GetConditions();
            }
            else
            {
                conditions = new[] { condition };
            }

            foreach (Condition cond in conditions)
            {
                if ((cond as PropertyCondition) != null)
                {
                    MbUnit.Framework.Assert.AreEqual(
                        controlTypeProperty,
                        (cond as PropertyCondition).Property.ProgrammaticName);
                    MbUnit.Framework.Assert.AreEqual(
                        controlTypeValue,
                        (cond as PropertyCondition).Value.ToString());
                }
                else
                {
                    MbUnit.Framework.Assert.AreEqual(cond, Condition.TrueCondition);
                }
            }
        }
        private ControlSearcher PerformGetElements(GetControlCmdletBase cmdlet)
        {
            var controlSearcher =
                AutomationFactory.GetSearcherImpl <ControlSearcher>() as ControlSearcher;

            controlSearcher.GetElements(
                controlSearcher.ConvertCmdletToControlSearcherData(cmdlet),
                0);

            return(controlSearcher);
        }
        private GetControlCmdletBase GetInputCmdlet(bool empty)
        {
            var cmdlet =
                new GetControlCmdletBase {
                Win32 = false, Regex = false
            };

            cmdlet.InputObject = empty ? GetCmdletInputObject_Empty() : GetCmdletInputObject_Three();

            return(cmdlet);
        }
Esempio n. 5
0
        public static GetControlCmdletBase Get_GetControlCmdletBase(ControlType controlType, string searchString)
        {
            GetControlCmdletBase cmdlet = Substitute.For <GetControlCmdletBase>();

            if (null != controlType)
            {
                cmdlet.ControlType.Returns(
                    new[] {
                    controlType.ProgrammaticName.Substring(12)
                }
                    );
            }
            cmdlet.ContainsText.Returns(!string.IsNullOrEmpty(searchString) ? searchString : string.Empty);
            return(cmdlet);
        }
        private void getOrConditions(string searchString, string controlType)
        {
            ResultOrCondition = null;

            GetControlCmdletBase cmdlet =
                new GetControlCmdletBase {
                ContainsText = searchString
            };

            CommonCmdletBase common =
                new CommonCmdletBase();

            // 20131129
            // ResultOrCondition =
            //     (common.GetControlConditionsForExactSearch(cmdlet, controlType, cmdlet.CaseSensitive, false) as OrCondition);
            ResultOrCondition =
                // common.GetTextSearchCondition(searchString, new string[] { controlType }, cmdlet.CaseSensitive) as OrCondition;
                ControlSearcher.GetTextSearchCondition(searchString, new string[] { controlType }, cmdlet.CaseSensitive) as OrCondition;
        }
Esempio n. 7
0
        public static GetControlCmdletBase Get_GetControlCmdletBase(ControlType[] controlTypes, string name, string automationId, string className, string txtValue)
        {
            GetControlCmdletBase cmdlet = Substitute.For <GetControlCmdletBase>();

            if (null != controlTypes && 0 < controlTypes.Length)
            {
                cmdlet.ControlType.Returns <string[]>(controlTypes.Select(
                                                          ct =>
                                                          null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray());
            }
            else
            {
                cmdlet.ControlType.Returns(new string[] {});
            }

            cmdlet.Name.Returns(!string.IsNullOrEmpty(name) ? name : string.Empty);
            cmdlet.AutomationId.Returns(!string.IsNullOrEmpty(automationId) ? automationId : string.Empty);
            cmdlet.Class.Returns(!string.IsNullOrEmpty(className) ? className : string.Empty);
            cmdlet.Value.Returns(!string.IsNullOrEmpty(txtValue) ? txtValue : string.Empty);
            return(cmdlet);
        }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable <IUiElement> collection,
            UsualWildcardRegex selector,
            int expectedNumberOfElements)
        {
            // Arrange
            ControlType[] controlTypes =
                new[] { controlType };

            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue);

            var data =
                new ControlSearcherData {
                ControlType  = controlTypes.ConvertControlTypeToStringArray(),
                Name         = name,
                AutomationId = automationId,
                Class        = className,
                Value        = txtValue
            };

            Condition condition;
            bool      useWildcardOrRegex = true;

            switch (selector)
            {
            case UsualWildcardRegex.Wildcard:
                condition =
                    ControlSearcher.GetWildcardSearchCondition(
                        data);
                useWildcardOrRegex = true;
                break;

            case UsualWildcardRegex.Regex:
                condition =
                    ControlSearcher.GetWildcardSearchCondition(
                        data);
                useWildcardOrRegex = false;
                break;
            }

            // Act
            var resultList = RealCodeCaller.GetResultList_ReturnOnlyRightElements(collection.ToArray(), data, useWildcardOrRegex);

            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            string[] controlTypeNames;
            switch (selector)
            {
            case UsualWildcardRegex.Wildcard:
                const WildcardOptions options = WildcardOptions.IgnoreCase;
                // 20140312
//                    WildcardPattern namePattern = new WildcardPattern(name, options);
//                    WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
//                    WildcardPattern classNamePattern = new WildcardPattern(className, options);
//                    WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
                var namePattern         = new WildcardPattern(name, options);
                var automationIdPattern = new WildcardPattern(automationId, options);
                var classNamePattern    = new WildcardPattern(className, options);
                var txtValuePattern     = new WildcardPattern(txtValue, options);

                // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.Current.Name));
//                        resultList.All(x => namePattern.IsMatch(x.Current.Name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                        resultList.All(x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.Current.ClassName));
//                        resultList.All(x => classNamePattern.IsMatch(x.Current.ClassName));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                if (!string.IsNullOrEmpty(name))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => namePattern.IsMatch(x.GetCurrent().Name));
                    resultList.All(x => namePattern.IsMatch(x.GetCurrent().Name));
                }
                if (!string.IsNullOrEmpty(automationId))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                    resultList.All(x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                }
                if (!string.IsNullOrEmpty(className))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                    resultList.All(x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                }
                controlTypeNames =
                    controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                if (null != controlType)
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                }

                if (!string.IsNullOrEmpty(txtValue))
                {
                    MbUnit.Framework.Assert.ForAll(
                        resultList
                        .Cast <IUiElement>()
                        .ToList <IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value));
                    });

                    resultList.All(
                        x => {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value));
                    });
                }
                break;

            case UsualWildcardRegex.Regex:
                // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.Name, name));
//                        resultList.All(x => Regex.IsMatch(x.Current.Name, name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                        resultList.All(x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.ClassName, className));
//                        resultList.All(x => Regex.IsMatch(x.Current.ClassName, className));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                if (!string.IsNullOrEmpty(name))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().Name, name));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().Name, name));
                }
                if (!string.IsNullOrEmpty(automationId))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                }
                if (!string.IsNullOrEmpty(className))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                }
                controlTypeNames =
                    controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                if (null != controlType)
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                }

                if (!string.IsNullOrEmpty(txtValue))
                {
                    MbUnit.Framework.Assert.ForAll(
                        resultList
                        .Cast <IUiElement>()
                        .ToList <IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue));
                    });
                    Assert.True(
                        resultList.All(
                            x => {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue));
                    })
                        );
                }
                break;
            }
        }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string searchString,
            IEnumerable <IUiElement> collection,
            int expectedNumberOfElements)
        {
            // Arrange
            string controlTypeString = string.Empty;

            if (null != controlType)
            {
                controlTypeString = controlType.ProgrammaticName.Substring(12);
            }

            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlType, searchString);
            Condition condition =
                ControlSearcher.GetTextSearchCondition(searchString, new string[] { controlTypeString }, false);
            IUiElement element =
                FakeFactory.GetElement_ForFindAll(
                    collection,
                    condition);

            // Act
            var resultList = RealCodeCaller.GetResultList_TextSearch(element, condition);

            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            if (!string.IsNullOrEmpty(searchString))
            {
                MbUnit.Framework.Assert.ForAll(
                    resultList.Cast <IUiElement>().ToList <IUiElement>(),
                    // 20140312
//                    x => x.Current.Name == searchString || x.Current.AutomationId == searchString || x.Current.ClassName == searchString ||
                    x => x.GetCurrent().Name == searchString || x.GetCurrent().AutomationId == searchString || x.GetCurrent().ClassName == searchString ||
                    (null != (x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern) && (x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString));

                /*
                 * (null != (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern) ?
                 *   // (x.GetCurrentPattern<IValuePattern, ValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString :
                 *   (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString :
                 *   false));
                 */
            }
//            if (null != controlType) {
//                MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ControlType == controlType);
//            }

            Assert.Equal(expectedNumberOfElements, resultList.Count);
            if (!string.IsNullOrEmpty(searchString))
            {
                resultList.All(
                    // 20140312
                    // x => x.Current.Name == searchString || x.Current.AutomationId == searchString || x.Current.ClassName == searchString ||
                    x => x.GetCurrent().Name == searchString || x.GetCurrent().AutomationId == searchString || x.GetCurrent().ClassName == searchString ||
                    (null != (x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern) && (x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString));

                /*
                 * (null != (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern) ?
                 *   (x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern).Current.Value == searchString :
                 *   false));
                 */
            }
        }
        public void DisposeRunspace()
        {
// // MiddleLevelCode.DisposeRunspace();
            cmdlet = null;
        }