Ejemplo n.º 1
0
        public static List <IUiElement> GetResultList_GetWindowCollectionByPid(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            var windowSearcher = new WindowSearcher();

            List <IUiElement> resultList =
                windowSearcher.GetWindowCollectionByPid(
                    rootElement,
                    data);

            return(resultList);
        }
        private void TestParametersAgainstCollection(
            IEnumerable <int> processIds,
            IEnumerable <string> names,
            string automationId,
            string className,
            IEnumerable <IUiElement> collection,
            int expectedNumberOfElements)
        {
            // Arrange
            IUiElement rootElement =
                FakeFactory.GetElement_ForFindAll(
                    collection,
                    null);

            var windowSearcherData =
                new WindowSearcherData {
                ProcessIds   = processIds.ToArray(),
                Name         = new[] { string.Empty },
                AutomationId = automationId,
                Class        = className,
                First        = false,
                Recurse      = false
            };

            // Act
            List <IUiElement> resultList =
                RealCodeCaller.GetResultList_GetWindowCollectionByPid(
                    rootElement,
                    windowSearcherData);

            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
//            string[] controlTypeNames;
//            switch (selector) {
//                case UIAutomationUnitTests.Helpers.Inheritance.UsualWildcardRegex.Wildcard:
//                    const WildcardOptions options = WildcardOptions.IgnoreCase;
//                    WildcardPattern namePattern = new WildcardPattern(name, options);
//                    WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
//                    WildcardPattern classNamePattern = new WildcardPattern(className, options);
//                    WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
//
//                    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(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 UIAutomationUnitTests.Helpers.Inheritance.UsualWildcardRegex.Regex:
//                    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(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);
//                            });
//                        Xunit.Assert.True(
//                            resultList.All(
//                                x => {
//                                    IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
//                                    return valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue);
//                                })
//                           );
//                    }
//                    break;
//            }
        }