Description of HasTimeoutCmdletBase.
Inheritance: HasControlInputCmdletBase
 public void NoResults_ZeroInput()
 {
     HasTimeoutCmdletBase cmdlet =
         new HasTimeoutCmdletBase();
     
     var controlSearcherData =
         new ControlSearcherData {
         Name = string.Empty,
         AutomationId = string.Empty,
         Class = string.Empty,
         Value = string.Empty,
         ControlType = new string[] {}
     };
     
     List<IUiElement> resultList =
         WindowSearcher.ReturnOnlyRightElements(
             new UiElement[] {},
             controlSearcherData,
             false,
             true);
     
     MbUnit.Framework.Assert.AreEqual(0, resultList.Count);
 }
 public void ThreeResults()
 {
     const string expectedName = "name";
     
     HasTimeoutCmdletBase cmdlet =
         new HasTimeoutCmdletBase();
     
     IFakeUiElement element01 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             expectedName,
             string.Empty,
             string.Empty,
             string.Empty);
     
     IFakeUiElement element02 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             expectedName,
             string.Empty,
             string.Empty,
             string.Empty);
     
     IFakeUiElement element03 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             string.Empty,
             string.Empty,
             string.Empty,
             string.Empty);
     
     IFakeUiElement element04 =
         FakeFactory.GetAutomationElementExpected(
             ControlType.Button,
             expectedName,
             string.Empty,
             string.Empty,
             string.Empty);
     
     var controlSearcherData =
         new ControlSearcherData {
         Name = expectedName,
         AutomationId = string.Empty,
         Class = string.Empty,
         Value = string.Empty
     };
     
     List<IUiElement> resultList =
         WindowSearcher.ReturnOnlyRightElements(
             new[] { element01, element02, element03, element04 },
             controlSearcherData,
             false,
             true);
     
     MbUnit.Framework.Assert.AreEqual(3, resultList.Count);
     // 20140312
     // MbUnit.Framework.Assert.Exists(resultList, e => e.Current.Name == expectedName); // ??
     MbUnit.Framework.Assert.Exists(resultList, e => e.GetCurrent().Name == expectedName); // ??
 }
Exemplo n.º 3
0
        // 20130513
        //internal ArrayList returnOnlyRightElements(
        internal static ArrayList ReturnOnlyRightElements(
            //AutomationElementCollection results,
            // 20130513
            HasTimeoutCmdletBase cmdlet,
            IEnumerable results,
            //System.Collections.Generic.IEnumerable<AutomationElement> results,
            string name,
            string automationId,
            string className,
            string textValue,
            string[] controlType,
            bool caseSensitive)
        {
            ArrayList resultCollection = new ArrayList();

            WildcardOptions options;
            if (caseSensitive) {
                options =
                    WildcardOptions.Compiled;
            } else {
                options =
                    WildcardOptions.IgnoreCase |
                    WildcardOptions.Compiled;
            }

            if (null == name || string.Empty == name || 0 == name.Length) { name = "*"; }
            if (null == automationId || string.Empty == automationId || 0 == automationId.Length) { automationId = "*"; }
            if (null == className || string.Empty == className || 0 == className.Length) { className = "*"; }
            if (null == textValue || string.Empty == textValue || 0 == textValue.Length) { textValue = "*"; }

            //Console.WriteLine("name = " + name);
            //Console.WriteLine("auId = " + automationId);
            //Console.WriteLine("class = " + className);
            //Console.WriteLine("value = " + textValue);

            WildcardPattern wildcardName =
                new WildcardPattern(name, options);
            WildcardPattern wildcardAutomationId =
                new WildcardPattern(automationId, options);
            WildcardPattern wildcardClass =
                new WildcardPattern(className, options);
            WildcardPattern wildcardValue =
                new WildcardPattern(textValue, options);
            // 20130513
            //this.WriteVerbose(this, "inside the returnOnlyRightElements method 20");
            cmdlet.WriteVerbose(cmdlet, "inside the returnOnlyRightElements method 20");
                System.Collections.Generic.List<AutomationElement> list =
                    new System.Collections.Generic.List<AutomationElement>();

                // 20130513
                foreach (AutomationElement elt in results) {

                    list.Add(elt);

                }
                //list.AddRange(results);
                //list.AddRange(results.AsQueryable());

            try {

                var query = list
            //                    .Where<AutomationElement>(item => wildcardName.IsMatch(item.Current.Name))
            //                    .Where<AutomationElement>(item => wildcardAutomationId.IsMatch(item.Current.AutomationId))
            //                    .Where<AutomationElement>(item => wildcardClass.IsMatch(item.Current.ClassName))
            //                    .Where<AutomationElement>(item =>
            //                                              item.GetSupportedPatterns().Contains(ValuePattern.Pattern) ?
            //                                              //(("*" != textValue) ? wildcardValue.IsMatch((item.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern).Current.Value) : false) :
            //                                              (("*" != textValue) ? (positiveMatch(item, wildcardValue, textValue)) : (negativeMatch(textValue))) :
            //                                              true
            //                                              )
                    .Where<AutomationElement>(
                        item => (wildcardName.IsMatch(item.Current.Name) &&
                                 wildcardAutomationId.IsMatch(item.Current.AutomationId) &&
                                 wildcardClass.IsMatch(item.Current.ClassName) &&
                                 // check whether a control has or hasn't ValuePattern
                                 (item.GetSupportedPatterns().Contains(ValuePattern.Pattern) ?
                                  // 20130513
                                  //testRealValueAndValueParameter(item, name, automationId, className, textValue, wildcardValue) :
                                  cmdlet.testRealValueAndValueParameter(item, name, automationId, className, textValue, wildcardValue) :
                                  // check whether the -Value parameter has or hasn't value
                                  ("*" == textValue ? true : false)
                                 )
                                )
                       )
                    .ToArray<AutomationElement>();

                // 20130513
                //this.WriteVerbose(
                //    this,
                cmdlet.WriteVerbose(
                        cmdlet,
                        "There are " +
                        query.Count().ToString() +
                        " elements");

                resultCollection.AddRange(query);

                // 20130513
                //this.WriteVerbose(
                //    this,
                cmdlet.WriteVerbose(
                    cmdlet,
                    "There are " +
                    resultCollection.Count.ToString() +
                    " elements");

            }
            catch {

            }

            return resultCollection;
        }