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 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; } }