private IUiElement[] GetCmdletInputObject_Empty() { return(new [] { FakeFactory.GetElement_ForFindAll( new IUiElement [] { null }, new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Button)) }); }
private IUiElement[] GetCmdletInputObject_Three() { return(new [] { FakeFactory.GetElement_ForFindAll( new IUiElement [] { FakeFactory.GetAutomationElementExpected(ControlType.Button, "name1", "automationId1", "className1", "value1"), FakeFactory.GetAutomationElementExpected(ControlType.Button, "name2", "automationId2", "className2", "value2"), FakeFactory.GetAutomationElementExpected(ControlType.Button, "name3", "automationId3", "className3", "value3"), }, new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Button)) }); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // [Description("Checks that the extended elements' object model is off when the UseElementsSearchObjectModel parameter is $false")] public void NoExtension() { // Arrange Preferences.UseElementsSearchObjectModel = false; // Act var elements = new IUiElement[] {}; var element = FakeFactory.GetElement_ForFindAll( elements, new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Button)); // Assert MbUnit.Framework.Assert.IsNull(element as ISupportsExtendedModel); Assert.Null(element as ISupportsExtendedModel); }
private void TestParametersAgainstCollection( Hashtable[] inputData, IEnumerable <IUiElement> collection, bool expectedResult) { // Arrange var data = new ControlSearcherData { SearchCriteria = inputData }; Condition condition = ControlSearcher.GetWildcardSearchCondition(data); IUiElement element = FakeFactory.GetElement_ForFindAll( collection, condition); var cmdlet = new WaitUiaControlStateCommand { SearchCriteria = inputData, InputObject = new[] { element }, Timeout = 10 }; // Act var command = new WaitControlStateCommand(cmdlet); command.Execute(); // Assert MbUnit.Framework.Assert.AreEqual <bool>( expectedResult, (bool)PSTestLib.UnitTestOutput.LastOutput[0]); Assert.Equal <bool>( expectedResult, (bool)PSTestLib.UnitTestOutput.LastOutput[0]); }
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; // } }
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)); */ } }