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 UIAutomationUnitTests.Helpers.Inheritance.UsualWildcardRegex.Wildcard: condition = ControlSearcher.GetWildcardSearchCondition( data); useWildcardOrRegex = true; break; case UIAutomationUnitTests.Helpers.Inheritance.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); Xunit.Assert.Equal(expectedNumberOfElements, resultList.Count); string[] controlTypeNames; switch (selector) { case UIAutomationUnitTests.Helpers.Inheritance.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 UIAutomationUnitTests.Helpers.Inheritance.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); }); 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 name, string automationId, string className, string txtValue, IEnumerable<IUiElement> collection, int expectedNumberOfElements) { // Arrange string controlTypeString = string.Empty; if (null != controlType) { controlTypeString = controlType.ProgrammaticName.Substring(12); } ControlType[] controlTypes = new[] { controlType }; GetControlCmdletBase cmdlet = FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue); Condition condition = ControlSearcher.GetExactSearchCondition( new ControlSearcherData { ControlType = controlTypes.ConvertControlTypeToStringArray(), Name = name, AutomationId = automationId, Class = className, Value = txtValue }); IUiElement element = FakeFactory.GetElement_ForFindAll( collection, condition); // Act var resultList = RealCodeCaller.GetResultList_ExactSearch(element, condition, cmdlet.SearchCriteria); // Assert MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList); Xunit.Assert.Equal(expectedNumberOfElements, resultList.Count); // 20140312 // if (!string.IsNullOrEmpty(name)) { // MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.Name == name); // resultList.All(x => x.Current.Name == name); // } // if (!string.IsNullOrEmpty(automationId)) { // MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.AutomationId == automationId); // resultList.All(x => x.Current.AutomationId == automationId); // } // if (!string.IsNullOrEmpty(className)) { // MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ClassName == className); // resultList.All(x => x.Current.ClassName == className); // } // if (null != controlType) { // MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.Current.ControlType == controlType); // resultList.All(x => x.Current.ControlType == controlType); // } if (!string.IsNullOrEmpty(name)) { MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().Name == name); resultList.All(x => x.GetCurrent().Name == name); } if (!string.IsNullOrEmpty(automationId)) { MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().AutomationId == automationId); resultList.All(x => x.GetCurrent().AutomationId == automationId); } if (!string.IsNullOrEmpty(className)) { MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().ClassName == className); resultList.All(x => x.GetCurrent().ClassName == className); } if (null != controlType) { MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => x.GetCurrent().ControlType == controlType); resultList.All(x => x.GetCurrent().ControlType == controlType); } if (string.IsNullOrEmpty(txtValue)) return; MbUnit.Framework.Assert.ForAll( resultList .Cast<IUiElement>() .ToList<IUiElement>(), x => { IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern; return valuePattern != null && valuePattern.Current.Value == txtValue; }); resultList.All( x => { IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern; return valuePattern != null && valuePattern.Current.Value == txtValue; }); /* if (!string.IsNullOrEmpty(txtValue)) { MbUnit.Framework.Assert.ForAll( resultList .Cast<IUiElement>() .ToList<IUiElement>(), x => { // 20131208 // IValuePattern valuePattern = x.GetCurrentPattern(ValuePattern.Pattern) as IValuePattern; // IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern, ValuePattern>(ValuePattern.Pattern) as IValuePattern; IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern; return valuePattern != null && valuePattern.Current.Value == txtValue; }); resultList.All( x => { IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern; return valuePattern != null && valuePattern.Current.Value == txtValue; }); } */ }