From 568b9ca01716b141676defaef693183275a9ad7d Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Tue, 28 Jun 2016 23:53:44 -0700 Subject: [PATCH 01/14] Added XAML for Universal App support. Some "modal windows" cannot be found due to "XAML" FrameworkId missing in Windows 10. --- src/TestStack.White/Factory/ChildWindowFactory.cs | 2 +- src/TestStack.White/UIItems/WindowsFramework.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TestStack.White/Factory/ChildWindowFactory.cs b/src/TestStack.White/Factory/ChildWindowFactory.cs index 40f4dedb..882dd61b 100644 --- a/src/TestStack.White/Factory/ChildWindowFactory.cs +++ b/src/TestStack.White/Factory/ChildWindowFactory.cs @@ -55,7 +55,7 @@ internal static Window Create(AutomationElement element, InitializeOption option var windowsFramework = WindowsFrameworkExtensions.FromFrameworkId(element.Current.FrameworkId); if (windowsFramework == WindowsFramework.WinForms) return new WinFormWindow(element, option, windowSession); - if (windowsFramework == WindowsFramework.Wpf) return new WPFWindow(element, WindowFactory.Desktop, option, windowSession); + if (windowsFramework == WindowsFramework.Wpf || windowsFramework == WindowsFramework.Xaml) return new WPFWindow(element, WindowFactory.Desktop, option, windowSession); if (windowsFramework == WindowsFramework.Win32) return new Win32Window(element, WindowFactory.Desktop, option, windowSession); throw new UIItemSearchException(string.Format("{0} is not supported yet.", windowsFramework)); } diff --git a/src/TestStack.White/UIItems/WindowsFramework.cs b/src/TestStack.White/UIItems/WindowsFramework.cs index 28abbbbf..2b42b9e7 100644 --- a/src/TestStack.White/UIItems/WindowsFramework.cs +++ b/src/TestStack.White/UIItems/WindowsFramework.cs @@ -7,6 +7,8 @@ public enum WindowsFramework [FrameworkId("WPF")] Wpf, Win32, + [FrameworkId("XAML")] + Xaml, [FrameworkId("WinForm")] WinForms, Silverlight, From 01c0b9d0f7dee5416eeb001cdb2c513680d27a97 Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Tue, 28 Jun 2016 23:55:43 -0700 Subject: [PATCH 02/14] Update VS2015. --- src/TestStack.White.sln | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestStack.White.sln b/src/TestStack.White.sln index d79fdf24..b8658976 100644 --- a/src/TestStack.White.sln +++ b/src/TestStack.White.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BCBA4C4-8C47-496C-B0D4-FDE9D066ED27}" ProjectSection(SolutionItems) = preProject From e9eb5ae0414e8bf5d11b6470ff29e3e59f15fd27 Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Wed, 29 Jun 2016 23:24:01 -0700 Subject: [PATCH 03/14] Updates some XAML hack...Will look at this later. --- .../Bricks/DynamicProxyInterceptors.cs | 72 +++++++--- .../Factory/ChildWindowFactory.cs | 100 +++++++++++--- .../Factory/DictionaryMappedItemFactory.cs | 101 ++++++++++++-- .../Mappings/ControlDictionary.cs | 77 +++++++---- .../Mappings/ControlDictionaryItem.cs | 128 ++++++++++++------ .../Mappings/ControlDictionaryItems.cs | 74 +++++++--- .../Custom/CustomControlTypeMapping.cs | 59 ++++++-- .../UIItems/ListBoxItems/WPFListItem.cs | 76 ++++++++--- .../UIItems/UIItemCollection.cs | 128 +++++++++++++++--- 9 files changed, 633 insertions(+), 182 deletions(-) diff --git a/src/TestStack.White/Bricks/DynamicProxyInterceptors.cs b/src/TestStack.White/Bricks/DynamicProxyInterceptors.cs index a27e7caa..f4c22370 100644 --- a/src/TestStack.White/Bricks/DynamicProxyInterceptors.cs +++ b/src/TestStack.White/Bricks/DynamicProxyInterceptors.cs @@ -1,31 +1,69 @@ -using System.Collections.Generic; -using System.Linq; -using Castle.DynamicProxy; -using TestStack.White.Interceptors; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the DynamicProxyInterceptors type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace TestStack.White.Bricks { - public class DynamicProxyInterceptors : List + using System.Collections.Generic; + using System.Linq; + + using Castle.DynamicProxy; + + using TestStack.White.Interceptors; + + /// + /// The dynamic proxy interceptors. + /// + public sealed class DynamicProxyInterceptors : List { - public virtual void Process(IInvocation invocation) + /// + /// The to-string. + /// + /// + /// The invocation. + /// + /// + /// The . + /// + public static string ToString(IInvocation invocation) { - ForEach(obj => obj.PreProcess(invocation, null)); - invocation.Proceed(); - ForEach(obj => obj.PostProcess(invocation, null)); + string message = $"Error when invoking {invocation.Method.Name}, on {invocation.TargetType.Name} with parameters: "; + return message + string.Join(",", invocation.Arguments.Select(argument => argument?.ToString() ?? "null").ToArray()); } - public virtual void Process(IInvocation invocation, CoreInterceptContext interceptedContext) + /// + /// The process. + /// + /// + /// The invocation. + /// + public void Process(IInvocation invocation) { - ForEach(obj => obj.PreProcess(invocation, interceptedContext)); - var invokeTargetDelegate = DelegateInvoker.CreateInvoker(interceptedContext.Target, invocation.Method); - invocation.ReturnValue = invokeTargetDelegate.Call(invocation.Arguments); - ForEach(obj => obj.PostProcess(invocation, interceptedContext)); + this.ForEach(obj => obj.PreProcess(invocation, null)); + invocation.Proceed(); + this.ForEach(obj => obj.PostProcess(invocation, null)); } - public static string ToString(IInvocation invocation) + /// + /// The process. + /// + /// + /// The invocation. + /// + /// + /// The intercepted context. + /// + public void Process(IInvocation invocation, CoreInterceptContext interceptedContext) { - string message = string.Format("Error when invoking {0}, on {1} with parameters: ", invocation.Method.Name, invocation.TargetType.Name); - return message + string.Join(",", invocation.Arguments.Select(argument => argument == null ? "null" : argument.ToString()).ToArray()); + this.ForEach(obj => obj.PreProcess(invocation, interceptedContext)); + var invokeTargetDelegate = DelegateInvoker.CreateInvoker(interceptedContext.Target, invocation.Method); + invocation.ReturnValue = invokeTargetDelegate.Call(invocation.Arguments); + this.ForEach(obj => obj.PostProcess(invocation, interceptedContext)); } } } \ No newline at end of file diff --git a/src/TestStack.White/Factory/ChildWindowFactory.cs b/src/TestStack.White/Factory/ChildWindowFactory.cs index 882dd61b..68c751fc 100644 --- a/src/TestStack.White/Factory/ChildWindowFactory.cs +++ b/src/TestStack.White/Factory/ChildWindowFactory.cs @@ -22,42 +22,110 @@ protected ChildWindowFactory(AutomationElementFinder finder) Finder = finder; } + /// + /// The modal window. + /// + /// + /// The title. + /// + /// + /// The option. + /// + /// + /// The window session. + /// + /// + /// The . + /// public virtual Window ModalWindow(string title, InitializeOption option, WindowSession windowSession) { var message = "Could not find modal window with title: " + title; - var modalWindowElement = WaitTillFound(() => Finder.FindWindow(title, 0), message); + var modalWindowElement = this.WaitTillFound(() => this.Finder.FindWindow(title, 0), message); return Create(modalWindowElement, option, windowSession); } + /// + /// The modal window. + /// + /// + /// The search criteria. + /// + /// + /// The option. + /// + /// + /// The window session. + /// + /// + /// The . + /// public virtual Window ModalWindow(SearchCriteria searchCriteria, InitializeOption option, WindowSession windowSession) { var message = "Could not find modal window with SearchCriteria: " + searchCriteria; - var modalWindowElement = WaitTillFound(() => Finder.FindWindow(searchCriteria), message); + var modalWindowElement = this.WaitTillFound(() => this.Finder.FindWindow(searchCriteria), message); return Create(modalWindowElement, option, windowSession); } - protected virtual AutomationElement WaitTillFound(Func find, string message) - { - var element = Retry.For(find, CoreAppXmlConfiguration.Instance.FindWindowTimeout()); - if (element == null) - throw new AutomationException(message, Debug.GetAllWindows()); - return element; - } - - /// The application type is not supported by White + /// + /// The create. + /// + /// + /// The element. + /// + /// + /// The option. + /// + /// + /// The window Session. + /// + /// + /// The application type is not supported by White + /// + /// + /// The . + /// internal static Window Create(AutomationElement element, InitializeOption option, WindowSession windowSession) { - ISpecializedWindowFactory specializedWindowFactory = SpecializedWindowFactories.Find(factory => factory.DoesSpecializeInThis(element)); + var specializedWindowFactory = SpecializedWindowFactories.Find(factory => factory.DoesSpecializeInThis(element)); if (specializedWindowFactory != null) { return specializedWindowFactory.Create(element, option, windowSession); } var windowsFramework = WindowsFrameworkExtensions.FromFrameworkId(element.Current.FrameworkId); - if (windowsFramework == WindowsFramework.WinForms) return new WinFormWindow(element, option, windowSession); - if (windowsFramework == WindowsFramework.Wpf || windowsFramework == WindowsFramework.Xaml) return new WPFWindow(element, WindowFactory.Desktop, option, windowSession); - if (windowsFramework == WindowsFramework.Win32) return new Win32Window(element, WindowFactory.Desktop, option, windowSession); - throw new UIItemSearchException(string.Format("{0} is not supported yet.", windowsFramework)); + if (windowsFramework == WindowsFramework.WinForms) + { + return new WinFormWindow(element, option, windowSession); + } + + if (windowsFramework == WindowsFramework.Wpf || windowsFramework == WindowsFramework.Xaml) + { + return new WPFWindow(element, WindowFactory.Desktop, option, windowSession); + } + + if (windowsFramework == WindowsFramework.Win32) + { + return new Win32Window(element, WindowFactory.Desktop, option, windowSession); + } + + throw new UIItemSearchException($"{windowsFramework} is not supported yet."); + } + + /// + /// Waits till found. + /// + /// The find function. + /// The message. + /// + protected virtual AutomationElement WaitTillFound(Func find, string message) + { + var element = Retry.For(find, CoreAppXmlConfiguration.Instance.FindWindowTimeout()); + if (element == null) + { + throw new AutomationException(message, Debug.GetAllWindows()); + } + + return element; } } } \ No newline at end of file diff --git a/src/TestStack.White/Factory/DictionaryMappedItemFactory.cs b/src/TestStack.White/Factory/DictionaryMappedItemFactory.cs index 7999a1c2..14e21bac 100644 --- a/src/TestStack.White/Factory/DictionaryMappedItemFactory.cs +++ b/src/TestStack.White/Factory/DictionaryMappedItemFactory.cs @@ -1,30 +1,101 @@ -using System; -using System.Windows.Automation; -using TestStack.White.Mappings; -using TestStack.White.UIItems; -using TestStack.White.UIItems.Actions; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the DictionaryMappedItemFactory type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace TestStack.White.Factory { - public class DictionaryMappedItemFactory : IUIItemFactory + using System; + using System.Windows.Automation; + + using TestStack.White.Mappings; + using TestStack.White.UIItems; + using TestStack.White.UIItems.Actions; + + /// + /// The dictionary mapped item factory. + /// + public sealed class DictionaryMappedItemFactory : IUIItemFactory { - public virtual IUIItem Create(AutomationElement automationElement, IActionListener actionListener) + /// + /// Creates the UI item. + /// + /// + /// The automation element. + /// + /// + /// The action listener. + /// + /// + /// The . + /// + public IUIItem Create(AutomationElement automationElement, IActionListener actionListener) { - if (automationElement == null) return null; - return Create(automationElement, ControlDictionary.Instance.GetTestControlType(automationElement), actionListener); + if (automationElement == null) + { + return null; + } + + return this.Create(automationElement, ControlDictionary.Instance.GetTestControlType(automationElement), actionListener); } - public virtual IUIItem Create(AutomationElement automationElement, IActionListener actionListener, Type customItemType) + /// + /// Creates the UI item. + /// + /// + /// The automation element. + /// + /// + /// The action listener. + /// + /// + /// The custom item type. + /// + /// + /// The . + /// + public IUIItem Create(AutomationElement automationElement, IActionListener actionListener, Type customItemType) { - if (automationElement == null) return null; - if (customItemType != null) return Create(automationElement, customItemType, actionListener); - return Create(automationElement, actionListener); + if (automationElement == null) + { + return null; + } + + if (customItemType != null) + { + return this.Create(automationElement, customItemType, actionListener); + } + + return this.Create(automationElement, actionListener); } + /// + /// Creates the UI item. + /// + /// + /// The automation element. + /// + /// + /// The item type. + /// + /// + /// The action listener. + /// + /// + /// The . + /// private IUIItem Create(AutomationElement automationElement, Type itemType, IActionListener actionListener) { - if (itemType == null) return null; - return (IUIItem) Activator.CreateInstance(itemType, automationElement, actionListener); + if (itemType == null) + { + return null; + } + + return (IUIItem)Activator.CreateInstance(itemType, automationElement, actionListener); } } } \ No newline at end of file diff --git a/src/TestStack.White/Mappings/ControlDictionary.cs b/src/TestStack.White/Mappings/ControlDictionary.cs index 88e1d7a4..ad3d4e08 100644 --- a/src/TestStack.White/Mappings/ControlDictionary.cs +++ b/src/TestStack.White/Mappings/ControlDictionary.cs @@ -16,7 +16,7 @@ namespace TestStack.White.Mappings { - public class ControlDictionary + public sealed class ControlDictionary { public static readonly ControlDictionary Instance = new ControlDictionary(); private readonly ControlDictionaryItems items = new ControlDictionaryItems(); @@ -24,6 +24,10 @@ public class ControlDictionary private ControlDictionary() { + this.items.AddXamlSpecificPrimary(ControlType.ComboBox, typeof(ComboBox)); + this.items.AddXamlSpecificPrimary(ControlType.Text, typeof(TextBox)); + this.items.AddXamlSpecificPrimary(ControlType.Edit, typeof(TextBox)); + items.AddFrameworkSpecificPrimary(ControlType.Edit, typeof(TextBox), typeof(WinFormTextBox), typeof(TextBox), typeof(TextBox)); items.AddWinFormPrimary(typeof(WinFormSlider), ControlType.Slider); @@ -83,6 +87,7 @@ private ControlDictionary() items.Add(ControlDictionaryItem.Win32Secondary(typeof(Win32ListItem), ControlType.ListItem)); items.Add(ControlDictionaryItem.WPFSecondary(typeof(WPFListItem), ControlType.ListItem)); items.Add(ControlDictionaryItem.SilverlightSecondary(typeof(WPFListItem), ControlType.ListItem)); + this.items.Add(ControlDictionaryItem.XamlSecondary(typeof(WPFListItem), ControlType.ListItem)); items.Add(ControlDictionaryItem.WinFormSecondary(typeof(Win32TreeNode), ControlType.TreeItem)); items.Add(ControlDictionaryItem.WPFSecondary(typeof(WPFTreeNode), ControlType.TreeItem)); @@ -100,7 +105,7 @@ private ControlDictionary() editableControls.Add(typeof(ListControl)); } - public virtual bool HasPrimaryChildren(ControlType controlType) + public bool HasPrimaryChildren(ControlType controlType) { if (controlType.Equals(ControlType.Custom)) return true; var results = items.FindBy(controlType).ToArray(); @@ -108,36 +113,55 @@ public virtual bool HasPrimaryChildren(ControlType controlType) return results.Any(i => i.HasPrimaryChildren); } - public virtual ControlType[] GetControlType(Type testControlType, string frameworkId) + public ControlType[] GetControlType(Type testControlType, string frameworkId) { var controlDictionaryItem = items.FindBy(testControlType, frameworkId); if (controlDictionaryItem == null) - throw new WhiteException(string.Format("Cannot find {0} for {1}", testControlType.Name, frameworkId)); + { + throw new WhiteException($"Cannot find {testControlType.Name} for {frameworkId}"); + } + return controlDictionaryItem.Select(c => c.ControlType).ToArray(); } - public virtual Type GetTestControlType(string className, string name, ControlType controlType, string frameWorkId, bool isNativeControl) + private Type GetTestControlType(string className, string name, ControlType controlType, string frameWorkId, bool isNativeControl) { - if (Equals(controlType, ControlType.ListItem) && string.IsNullOrEmpty(frameWorkId)) + if (object.Equals(controlType, ControlType.ListItem) && string.IsNullOrEmpty(frameWorkId)) + { frameWorkId = WindowsFramework.Win32.FrameworkId(); + } + + var dictionaryItems = this.items.Where(controlDictionaryItem => + { + if (!ControlTypeMatches(controlType, controlDictionaryItem)) + { + return false; + } + + if (!FrameworkIdMatches(frameWorkId, controlDictionaryItem)) + { + return false; + } + + if (controlDictionaryItem.IsIdentifiedByClassName && !className.Contains(controlDictionaryItem.ClassName)) + { + return false; + } + + if (controlDictionaryItem.IsIdentifiedByName && controlDictionaryItem.TestControlType.Name != name) + { + return false; + } + + return true; + }).ToArray(); - var dictionaryItems = items.Where(controlDictionaryItem => - { - if (!ControlTypeMatches(controlType, controlDictionaryItem)) return false; - if (!FrameworkIdMatches(frameWorkId, controlDictionaryItem)) return false; - if (controlDictionaryItem.IsIdentifiedByClassName && !className.Contains(controlDictionaryItem.ClassName)) - return false; - if (controlDictionaryItem.IsIdentifiedByName && controlDictionaryItem.TestControlType.Name != name) - return false; - - return true; - }) - .ToArray(); if (!dictionaryItems.Any()) { - throw new ControlDictionaryException(string.Format("Could not find TestControl for ControlType={0} and FrameworkId:{1}", - controlType.LocalizedControlType, frameWorkId)); + throw new ControlDictionaryException( + $"Could not find TestControl for ControlType={controlType.LocalizedControlType} and FrameworkId:{frameWorkId}"); } + if (dictionaryItems.Length > 1) { var primaries = dictionaryItems.Where(i => IsPrimaryControl(i.ControlType, className, name)).ToArray(); @@ -160,6 +184,7 @@ public virtual Type GetTestControlType(string className, string name, ControlTyp string.Join(", ", dictionaryItems.Select(d => d.TestControlType == null ? "null" : d.TestControlType.FullName)))); } + return dictionaryItems.Single().TestControlType; } @@ -175,7 +200,7 @@ private static bool FrameworkIdMatches(string frameWorkId, ControlDictionaryItem string.IsNullOrEmpty(controlDictionaryItem.FrameworkId); } - public virtual bool IsPrimaryControl(ControlType controlType, string className, string name) + public bool IsPrimaryControl(ControlType controlType, string className, string name) { return items.Exists(controlDictionaryItem => { @@ -186,17 +211,17 @@ public virtual bool IsPrimaryControl(ControlType controlType, string className, }); } - public virtual bool IsExcluded(ControlType controlType) + public bool IsExcluded(ControlType controlType) { return items.Exists(controlDictionaryItem => controlDictionaryItem.ControlType.Equals(controlType) && controlDictionaryItem.IsExcluded); } - public virtual bool IsControlTypeSupported(ControlType controlType) + public bool IsControlTypeSupported(ControlType controlType) { return items.Any(controlDictionaryItem => controlDictionaryItem.ControlType.Equals(controlType)); } - public virtual List PrimaryControlTypes(string frameworkId) + public List PrimaryControlTypes(string frameworkId) { var controlTypes = new List(); foreach (ControlDictionaryItem controlDictionaryItem in items) @@ -208,12 +233,12 @@ public virtual List PrimaryControlTypes(string frameworkId) return controlTypes; } - public virtual bool IsEditable(UIItem uiItem) + public bool IsEditable(UIItem uiItem) { return editableControls.All(t => t.IsInstanceOfType(uiItem)); } - public virtual Type GetTestControlType(AutomationElement automationElement) + public Type GetTestControlType(AutomationElement automationElement) { AutomationElement.AutomationElementInformation current = automationElement.Current; return GetTestControlType(current.ClassName, current.Name, current.ControlType, current.FrameworkId, current.NativeWindowHandle != 0); diff --git a/src/TestStack.White/Mappings/ControlDictionaryItem.cs b/src/TestStack.White/Mappings/ControlDictionaryItem.cs index f8557151..99abb5d2 100644 --- a/src/TestStack.White/Mappings/ControlDictionaryItem.cs +++ b/src/TestStack.White/Mappings/ControlDictionaryItem.cs @@ -4,7 +4,7 @@ namespace TestStack.White.Mappings { - public class ControlDictionaryItem + public sealed class ControlDictionaryItem { private readonly Type testControlType; private readonly ControlType controlType; @@ -38,11 +38,6 @@ public static ControlDictionaryItem Primary(Type testControlType, ControlType co return new ControlDictionaryItem(testControlType, controlType, string.Empty, false, true, false, null, hasPrimaryChildren); } - private static ControlDictionaryItem Primary(Type testControlType, ControlType controlType, string frameworkId) - { - return new ControlDictionaryItem(testControlType, controlType, string.Empty, false, true, false, frameworkId, false); - } - public static ControlDictionaryItem WinFormPrimary(Type testControlType, ControlType controlType) { return Primary(testControlType, controlType, WindowsFramework.WinForms.FrameworkId()); @@ -63,9 +58,21 @@ public static ControlDictionaryItem SilverlightPrimary(Type testControlType, Con return Primary(testControlType, controlType, WindowsFramework.Silverlight.FrameworkId()); } - private static ControlDictionaryItem Secondary(Type testControlType, ControlType controlType, string frameworkId) + /// + /// The XAML primary. + /// + /// + /// The test control type. + /// + /// + /// The control type. + /// + /// + /// The . + /// + public static ControlDictionaryItem XamlPrimary(Type testControlType, ControlType controlType) { - return new ControlDictionaryItem(testControlType, controlType, string.Empty, false, false, false, frameworkId, false); + return Primary(testControlType, controlType, WindowsFramework.Xaml.FrameworkId()); } public static ControlDictionaryItem Secondary(Type testControlType, ControlType controlType) @@ -98,61 +105,92 @@ public static ControlDictionaryItem SilverlightSecondary(Type testControlType, C return Secondary(testControlType, controlType, WindowsFramework.Silverlight.FrameworkId()); } - public virtual bool IsPrimary + /// + /// The XAML secondary. + /// + /// + /// The test control type. + /// + /// + /// The control type. + /// + /// + /// The . + /// + public static ControlDictionaryItem XamlSecondary(Type testControlType, ControlType controlType) { - get { return isPrimary; } + return Secondary(testControlType, controlType, WindowsFramework.Xaml.FrameworkId()); } - public virtual Type TestControlType - { - get { return testControlType; } - } + public bool IsPrimary => this.isPrimary; - public virtual string FrameworkId - { - get { return frameworkId; } - } + public Type TestControlType => this.testControlType; - public virtual ControlType ControlType - { - get { return controlType; } - } + public string FrameworkId => this.frameworkId; - public virtual string ClassName - { - get { return className; } - } + public ControlType ControlType => this.controlType; - public virtual bool IsExcluded - { - get { return isExcluded; } - } + public string ClassName => this.className; - public virtual bool IsIdentifiedByClassName - { - get { return identifiedByClassName; } - } + public bool IsExcluded => this.isExcluded; - public virtual bool HasPrimaryChildren - { - get { return hasPrimaryChildren; } - } + public bool IsIdentifiedByClassName => this.identifiedByClassName; - public virtual bool OfFramework(string id) + public bool HasPrimaryChildren => this.hasPrimaryChildren; + + public bool OfFramework(string id) { //TODO id.Equals(id) will always return true.. figure out what this is doing return string.IsNullOrEmpty(id) || id.Equals(id); } - public virtual bool IsIdentifiedByName { set; get; } + public bool IsIdentifiedByName { set; get; } + /// public override string ToString() { - return - string.Format( - "TestControlType: {0}, ControlType: {1}, ClassName: {2}, IdentifiedByClassName: {3}, IsPrimary: {4}, IsExcluded: {5}, FrameworkId: {6}, HasPrimaryChildren: {7}, IsIdentifiedByName: {8}", - testControlType.Name, controlType.LocalizedControlType, className, identifiedByClassName, isPrimary, isExcluded, frameworkId, hasPrimaryChildren, - IsIdentifiedByName); + return + $"TestControlType: {this.testControlType.Name}, ControlType: {this.controlType.LocalizedControlType}, ClassName: {this.className}, IdentifiedByClassName: {this.identifiedByClassName}, IsPrimary: {this.isPrimary}, IsExcluded: {this.isExcluded}, FrameworkId: {this.frameworkId}, HasPrimaryChildren: {this.hasPrimaryChildren}, IsIdentifiedByName: {this.IsIdentifiedByName}"; + } + + /// + /// The primary. + /// + /// + /// The test control type. + /// + /// + /// The control type. + /// + /// + /// The framework id. + /// + /// + /// The . + /// + private static ControlDictionaryItem Primary(Type testControlType, ControlType controlType, string frameworkId) + { + return new ControlDictionaryItem(testControlType, controlType, string.Empty, false, true, false, frameworkId, false); + } + + /// + /// The secondary. + /// + /// + /// The test control type. + /// + /// + /// The control type. + /// + /// + /// The framework id. + /// + /// + /// The . + /// + private static ControlDictionaryItem Secondary(Type testControlType, ControlType controlType, string frameworkId) + { + return new ControlDictionaryItem(testControlType, controlType, string.Empty, false, false, false, frameworkId, false); } } } \ No newline at end of file diff --git a/src/TestStack.White/Mappings/ControlDictionaryItems.cs b/src/TestStack.White/Mappings/ControlDictionaryItems.cs index e6093a2a..be04a177 100644 --- a/src/TestStack.White/Mappings/ControlDictionaryItems.cs +++ b/src/TestStack.White/Mappings/ControlDictionaryItems.cs @@ -1,65 +1,91 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Automation; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the ControlDictionaryItems type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace TestStack.White.Mappings { - public class ControlDictionaryItems : List + using System; + using System.Collections.Generic; + using System.Linq; + using System.Windows.Automation; + + /// + /// The control dictionary items. + /// + public sealed class ControlDictionaryItems : List { - public virtual void AddWin32Primary(Type testControlType, ControlType controlType) + /// + /// Add XAML primary. + /// + /// + /// The test control type. + /// + /// + /// The control type. + /// + public void AddXamlPrimary(Type testControlType, ControlType controlType) + { + this.Add(ControlDictionaryItem.XamlPrimary(testControlType, controlType)); + } + + public void AddWin32Primary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.Win32Primary(testControlType, controlType)); } - public virtual void AddWPFPrimary(Type testControlType, ControlType controlType) + public void AddWPFPrimary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.WPFPrimary(testControlType, controlType)); } - public virtual void AddWPFSecondary(Type testControlType, ControlType controlType) + public void AddWPFSecondary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.WPFSecondary(testControlType, controlType)); } - public virtual void AddWinFormPrimary(Type testControlType, ControlType controlType) + public void AddWinFormPrimary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.WinFormPrimary(testControlType, controlType)); } - public virtual void AddSilverlightPrimary(Type testControlType, ControlType controlType) + public void AddSilverlightPrimary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.SilverlightPrimary(testControlType, controlType)); } - public virtual void AddPrimary(Type testControlType, ControlType controlType) + public void AddPrimary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.Primary(testControlType, controlType)); } - public virtual void AddSecondary(Type testControlType, ControlType controlType) + public void AddSecondary(Type testControlType, ControlType controlType) { Add(ControlDictionaryItem.Secondary(testControlType, controlType)); } - public virtual void AddPrimary(Type testControlType, ControlType controlType, bool hasPrimaryChildren) + public void AddPrimary(Type testControlType, ControlType controlType, bool hasPrimaryChildren) { Add(ControlDictionaryItem.Primary(testControlType, controlType, hasPrimaryChildren)); } - public virtual void AddSecondary(Type testControlType, ControlType controlType, bool hasPrimaryChildren) + public void AddSecondary(Type testControlType, ControlType controlType, bool hasPrimaryChildren) { Add(ControlDictionaryItem.Secondary(testControlType, controlType, hasPrimaryChildren)); } - public virtual ControlDictionaryItem[] FindBy(ControlType controlType) + public ControlDictionaryItem[] FindBy(ControlType controlType) { return this .Where(obj => controlType.Equals(obj.ControlType) && !obj.IsIdentifiedByClassName && !obj.IsIdentifiedByName) .ToArray(); } - public virtual ControlDictionaryItem[] FindBy(Type testControlType, string frameworkId) + public ControlDictionaryItem[] FindBy(Type testControlType, string frameworkId) { var frameworkSpecificMatch = this .Where(c => testControlType.IsAssignableFrom(c.TestControlType) && Equals(c.FrameworkId, frameworkId)) @@ -71,7 +97,21 @@ public virtual ControlDictionaryItem[] FindBy(Type testControlType, string frame .ToArray(); } - public virtual void AddFrameworkSpecificPrimary(ControlType controlType, Type win32Type, Type winformType, Type wpfType, Type silverlightType) + /// + /// Adds XAML specific primary. + /// + /// + /// The control type. + /// + /// + /// The XAML type. + /// + public void AddXamlSpecificPrimary(ControlType controlType, Type xamlType) + { + this.AddXamlPrimary(xamlType, controlType); + } + + public void AddFrameworkSpecificPrimary(ControlType controlType, Type win32Type, Type winformType, Type wpfType, Type silverlightType) { AddWin32Primary(win32Type, controlType); AddWinFormPrimary(winformType, controlType); diff --git a/src/TestStack.White/UIItems/Custom/CustomControlTypeMapping.cs b/src/TestStack.White/UIItems/Custom/CustomControlTypeMapping.cs index 835e14fc..81bf050b 100644 --- a/src/TestStack.White/UIItems/Custom/CustomControlTypeMapping.cs +++ b/src/TestStack.White/UIItems/Custom/CustomControlTypeMapping.cs @@ -1,14 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Automation; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the CustomControlTypeMapping type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace TestStack.White.UIItems.Custom { - public class CustomControlTypeMapping + using System; + using System.Collections.Generic; + using System.Linq; + using System.Windows.Automation; + + /// + /// The custom control type mapping. + /// + public static class CustomControlTypeMapping { + /// + /// The mappings. + /// private static readonly Dictionary Mappings = new Dictionary(); + /// + /// Initializes static members of the class. + /// static CustomControlTypeMapping() { Mappings[CustomUIItemType.Pane] = System.Windows.Automation.ControlType.Pane; @@ -52,24 +70,45 @@ static CustomControlTypeMapping() Mappings[CustomUIItemType.TreeItem] = System.Windows.Automation.ControlType.TreeItem; } + /// + /// The control type. + /// + /// + /// The custom UI item type. + /// + /// + /// The . + /// public static ControlType ControlType(CustomUIItemType customUIItemType) { return Mappings[customUIItemType]; } + /// + /// The control type. + /// + /// + /// The type. + /// + /// + /// The framework. + /// + /// + /// The . + /// public static ControlType ControlType(Type type, WindowsFramework framework) { var controlTypeMappingAttribute = type.GetCustomAttributes(typeof(ControlTypeMappingAttribute), true) .OfType() .ToArray(); if (!controlTypeMappingAttribute.Any()) - throw new CustomUIItemException("ControlTypeMappingAttribute needs to be defined for this type: " + type.FullName); + { + throw new CustomUIItemException( + "ControlTypeMappingAttribute needs to be defined for this type: " + type.FullName); + } var frameworkSpecific = controlTypeMappingAttribute.FirstOrDefault(c => c.AppliesToFramework == framework); - if (frameworkSpecific != null) - return ControlType(frameworkSpecific.CustomUIItemType); - - return ControlType(controlTypeMappingAttribute.Single(a=>a.AppliesToFramework == null).CustomUIItemType); + return ControlType(frameworkSpecific?.CustomUIItemType ?? controlTypeMappingAttribute.Single(a => a.AppliesToFramework == null).CustomUIItemType); } } } \ No newline at end of file diff --git a/src/TestStack.White/UIItems/ListBoxItems/WPFListItem.cs b/src/TestStack.White/UIItems/ListBoxItems/WPFListItem.cs index 179cc414..964e3d16 100644 --- a/src/TestStack.White/UIItems/ListBoxItems/WPFListItem.cs +++ b/src/TestStack.White/UIItems/ListBoxItems/WPFListItem.cs @@ -1,51 +1,95 @@ -using System.Windows.Automation; -using TestStack.White.AutomationElementSearch; -using TestStack.White.UIItems.Actions; -using TestStack.White.UIItems.Finders; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the WPFListItem type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace TestStack.White.UIItems.ListBoxItems { + using System.Windows.Automation; + + using TestStack.White.AutomationElementSearch; + using TestStack.White.UIItems.Actions; + using TestStack.White.UIItems.Finders; + + /// + /// The WPF list item. + /// [PlatformSpecificItem] public class WPFListItem : ListItem { + /// + /// The finder. + /// private readonly AutomationElementFinder finder; - - protected WPFListItem() {} - public WPFListItem(AutomationElement automationElement, IActionListener actionListener) : base(automationElement, actionListener) - { - finder = new AutomationElementFinder(automationElement); - } - private CheckBox CheckBox + /// + /// Initializes a new instance of the class. + /// + protected WPFListItem() { - get { return (CheckBox) factory.Create(SearchCriteria.ByControlType(ControlType.CheckBox), actionListener); } } - public override bool Checked + /// + /// Initializes a new instance of the class. + /// + /// The automation element. + /// The action listener. + public WPFListItem(AutomationElement automationElement, IActionListener actionListener) : base(automationElement, actionListener) { - get { return CheckBox.Checked; } + finder = new AutomationElementFinder(automationElement); } + /// + /// Gets the checked status. + /// + public override bool Checked => this.CheckBox.Checked; + + /// + /// Checks the item. + /// public override void Check() { if (!Checked) + { CheckBox.Click(); + } } + /// + /// Unchecks the item. + /// public override void UnCheck() { if (Checked) + { CheckBox.Click(); + } } + /// + /// Gets the text. + /// public override string Text { get { - AutomationElement element = finder.FindChildRaw(AutomationSearchCondition.ByControlType(ControlType.Text)); - if (element == null) return base.Text; + var element = this.finder.FindChildRaw(AutomationSearchCondition.ByControlType(ControlType.Text)); + if (element == null) + { + return base.Text; + } + return element.Current.Name; } } + + /// + /// Gets the check box. + /// + private CheckBox CheckBox => (CheckBox)this.factory.Create(SearchCriteria.ByControlType(ControlType.CheckBox), this.actionListener); } } \ No newline at end of file diff --git a/src/TestStack.White/UIItems/UIItemCollection.cs b/src/TestStack.White/UIItems/UIItemCollection.cs index 13ad463a..145d22fd 100644 --- a/src/TestStack.White/UIItems/UIItemCollection.cs +++ b/src/TestStack.White/UIItems/UIItemCollection.cs @@ -1,57 +1,145 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Automation; -using Castle.Core.Logging; -using TestStack.White.Configuration; -using TestStack.White.Factory; -using TestStack.White.Mappings; -using TestStack.White.UIA; -using TestStack.White.UIItems.Actions; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the UIItemCollection type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace TestStack.White.UIItems { + using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + using System.Windows.Automation; + + using Castle.Core.Logging; + + using TestStack.White.Configuration; + using TestStack.White.Factory; + using TestStack.White.Mappings; + using TestStack.White.UIA; + using TestStack.White.UIItems.Actions; + + /// + /// The UI item collection. + /// public class UIItemCollection : List { + /// + /// The dictionary mapped item factory. + /// private static readonly DictionaryMappedItemFactory DictionaryMappedItemFactory = new DictionaryMappedItemFactory(); + + /// + /// The logger. + /// private readonly ILogger logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof(UIItemCollection)); + /// + /// Initializes a new instance of the class. + /// + /// The UI Items. public UIItemCollection(params UIItem[] uiItems) { - AddRange(uiItems); + this.AddRange(uiItems); } - public UIItemCollection(IEnumerable entities) : base(entities.OfType()) {} + /// + /// Initializes a new instance of the class. + /// + /// The entities. + public UIItemCollection(IEnumerable entities) + : base(entities.OfType()) + { + } + /// + /// Initializes a new instance of the class. + /// + /// + /// The automation elements. + /// + /// + /// The action listener. + /// public UIItemCollection(IEnumerable automationElements, IActionListener actionListener) - : this(automationElements, DictionaryMappedItemFactory, actionListener) {} + : this(automationElements, DictionaryMappedItemFactory, actionListener) + { + } + /// + /// Initializes a new instance of the class. + /// + /// + /// The automation elements. + /// + /// + /// The action listener. + /// public UIItemCollection(IEnumerable automationElements, IActionListener actionListener) - : this(automationElements, DictionaryMappedItemFactory, actionListener) {} + : this(automationElements, DictionaryMappedItemFactory, actionListener) + { + } + /// + /// Initializes a new instance of the class. + /// + /// + /// The automation elements. + /// + /// + /// The UI Item factory. + /// + /// + /// The action listener. + /// public UIItemCollection(IEnumerable automationElements, IUIItemFactory uiItemFactory, IActionListener actionListener) { foreach (AutomationElement automationElement in automationElements) { - IUIItem uiItem = uiItemFactory.Create(automationElement, actionListener); - if (uiItem != null) Add(uiItem); + var uiItem = uiItemFactory.Create(automationElement, actionListener); + if (uiItem != null) + { + this.Add(uiItem); + } } } + /// + /// Initializes a new instance of the class. + /// + /// + /// The automation elements. + /// + /// + /// The action listener. + /// + /// + /// The custom item Type. + /// public UIItemCollection(IEnumerable automationElements, IActionListener actionListener, Type customItemType) { foreach (AutomationElement automationElement in automationElements) { try { - if (!automationElement.IsPrimaryControl()) continue; + if (!automationElement.IsPrimaryControl()) + { + continue; + } + var uiItem = DictionaryMappedItemFactory.Create(automationElement, actionListener, customItemType); - if (uiItem != null) Add(uiItem); + if (uiItem != null) + { + this.Add(uiItem); + } } catch (ControlDictionaryException) { - logger.WarnFormat("Couldn't create UIItem for AutomationElement, {0}", automationElement.Display()); + this.logger.WarnFormat("Couldn't create UIItem for AutomationElement, {0}", automationElement.Display()); } } } From 854c59b21ac9d63b76326e140c3614caba5539bd Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Wed, 29 Jun 2016 23:28:33 -0700 Subject: [PATCH 04/14] Update stylecop --- src/Settings.StyleCop | 31 ++ src/TestStack.White.sln.DotSettings | 414 +++++++++++++++++- .../Properties/AssemblyInfo.cs | 11 +- 3 files changed, 448 insertions(+), 8 deletions(-) create mode 100644 src/Settings.StyleCop diff --git a/src/Settings.StyleCop b/src/Settings.StyleCop new file mode 100644 index 00000000..6792c948 --- /dev/null +++ b/src/Settings.StyleCop @@ -0,0 +1,31 @@ + + + + DB + Dto + upsert + Edds + dacpac + + + + + + + TemporaryGeneratedFile_.*\.cs$ + \.g\.cs$ + \.generated\.cs$ + \.g\.i\.cs$ + + + + + + + + TestStack + All rights reserved. + + + + \ No newline at end of file diff --git a/src/TestStack.White.sln.DotSettings b/src/TestStack.White.sln.DotSettings index 5ad2a6e5..11770aac 100644 --- a/src/TestStack.White.sln.DotSettings +++ b/src/TestStack.White.sln.DotSettings @@ -1,23 +1,423 @@  + True + False DO_NOT_SHOW - False - False - False - NEXT_LINE - NEXT_LINE + 0 + Field, Property, Event, Method + True + True + True + True + True + True + True + True + True + True + NEXT_LINE_SHIFTED_2 + 1 + 1 + 1 + 1 + 1 + NEXT_LINE_SHIFTED_2 False False + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD + ALWAYS_ADD False - NEXT_LINE + True + True + NEXT_LINE_SHIFTED_2 + 1 + 1 + False + False + False + False + False + False + False + False + True + LINE_BREAK + False + True + True + True + False + True + True + CHOP_IF_LONG + True + True + CHOP_IF_LONG + CHOP_IF_LONG OnSingleLine + <?xml version="1.0" encoding="utf-16"?> +<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> + <TypePattern DisplayName="COM interfaces"> + <TypePattern.Match> + <Or> + <And> + <Kind Is="Interface" /> + <Or> + <HasAttribute Name="System.Runtime.InteropServices.InterfaceTypeAttribute" /> + <HasAttribute Name="System.Runtime.InteropServices.ComImport" /> + </Or> + </And> + </Or> + </TypePattern.Match> + </TypePattern> + <TypePattern DisplayName="P/Invoke structs"> + <TypePattern.Match> + <And> + <Or> + <Kind Is="Struct" /> + <Kind Is="Class" /> + </Or> + <HasAttribute Name="System.Runtime.InteropServices.StructLayoutAttribute" /> + </And> + </TypePattern.Match> + </TypePattern> + <TypePattern DisplayName="P/Invoke classes (called xxxNativeMethods)"> + <TypePattern.Match> + <And> + <Kind Is="Class" /> + <Name Is=".*NativeMethods" /> + </And> + </TypePattern.Match> + </TypePattern> + <TypePattern DisplayName="StyleCop pattern" RemoveRegions="AllExceptGenerated" Priority="100"> + <TypePattern.Match> + <Or> + <Kind Is="Class" /> + <Kind Is="Struct" /> + <Kind Is="Interface" /> + </Or> + </TypePattern.Match> + <Entry DisplayName="Constants"> + <Entry.Match> + <Kind Is="Constant" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Static Fields"> + <Entry.Match> + <And> + <Kind Is="Field" /> + <Static /> + </And> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Readonly /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Fields"> + <Entry.Match> + <Kind Is="Field" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Readonly /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Constructors and destructors" Priority="150"> + <Entry.Match> + <Or> + <Kind Is="Constructor" /> + <Kind Is="Destructor" /> + </Or> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Kind Order="Constructor Destructor" /> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + </Entry.SortBy> + </Entry> + + <Entry DisplayName="Delegates"> + <Entry.Match> + <Kind Is="delegate"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Delegates"/> --> + </Entry> + + <Entry DisplayName="Public Events"> + <Entry.Match> + <And> + <Kind Is="event"/> + <Access Is="public"/> + </And> + </Entry.Match> + <Entry.SortBy> + <Static /> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Public Events"/> --> + </Entry> + + <Entry DisplayName="Interface events"> + <Entry.Match> + <And> + <Kind Is="event"/> + <ImplementsInterface/> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="true"/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Explicit Interface Events" /> --> + </Entry> + + <Entry DisplayName="Other events"> + <Entry.Match> + <Kind Is="event"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Events"/> --> + </Entry> + + <Entry DisplayName= "Enums"> + <Entry.Match> + <Kind Is="enum"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Enums"/> --> + </Entry> + + <Entry DisplayName = "Interfaces"> + <Entry.Match> + <Kind Is="interface" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Interfaces"/> --> + </Entry> + + <Entry DisplayName = "Public properties"> + <Entry.Match> + <And> + <Kind Is="property"/> + <Access Is="public"/> + </And> + </Entry.Match> + <Entry.SortBy> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Public Properties"/> --> + </Entry> + + <Entry DisplayName = "Interface properties"> + <Entry.Match> + <And> + <Kind Is="property"/> + <ImplementsInterface/> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="true"/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Explicit Interface Properties" /> --> + </Entry> + + <Entry DisplayName="Other properties"> + <Entry.Match> + <Kind Is="property"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private"/> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Properties"/> --> + </Entry> + + <Entry DisplayName="Public indexers" Priority="100"> + <Entry.Match> + <And> + <Kind Is="indexer"/> + <Access Is="public"/> + </And> + </Entry.Match> + <Entry.SortBy> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Public Indexers"/> --> + </Entry> + + <Entry DisplayName="Interface indexers"> + <Entry.Match> + <And> + <Kind Is="indexer"/> + <ImplementsInterface/> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="true"/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Explicit Interface Indexers" /> --> + </Entry> + + <Entry DisplayName = "Other indexers" Priority = "100"> + <Entry.Match> + <Kind Is="indexer"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Indexers"/> --> + </Entry> + + <Entry DisplayName="Public methods (includes operators)"> + <Entry.Match> + <And> + <Or> + <Kind Is="method"/> + <Kind Is="operator"/> + </Or> + <Access Is="public"/> + </And> + </Entry.Match> + <Entry.SortBy> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Public Methods and Operators"/> --> + </Entry> + + <Entry DisplayName = "Interface methods"> + <Entry.Match> + <And> + <Kind Is="method"/> + <ImplementsInterface/> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="true"/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Explicit Interface Methods" /> --> + </Entry> + + <Entry DisplayName = "Other methods"> + <Entry.Match> + <Kind Is="method"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private"/> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Methods"/> --> + </Entry> + + <Entry DisplayName = "Operators"> + <Entry.Match> + <Kind Is="operator"/> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static/> + <!-- <Name/> --> + </Entry.SortBy> + <!-- <Group Region="Operators"/> --> + </Entry> + + <Entry DisplayName = "Nested structs" Priority = "60"> + <Entry.Match> + <Kind Is="struct" /> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <!-- <Name/> --> + </Entry.SortBy> + </Entry> + + <Entry DisplayName = "Nested classes" Priority = "70"> + <Entry.Match> + <Kind Is="class"/> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <!-- <Name/> --> + </Entry.SortBy> + </Entry> + + <Entry DisplayName = "All other members"/> + + </TypePattern> +</Patterns> + True + True UI WPF + $object$_On$event$ + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True + False True + True True True True False + 05/30/2016 11:52:02 + VS <data /> - <data><IncludeFilters /><ExcludeFilters /></data> \ No newline at end of file + <data><IncludeFilters /><ExcludeFilters /></data> + True + True + CSharpLineBreaksAndWrappingPage + -374,-218 + True + True \ No newline at end of file diff --git a/src/TestStack.White/Properties/AssemblyInfo.cs b/src/TestStack.White/Properties/AssemblyInfo.cs index 26faee2f..ab978091 100644 --- a/src/TestStack.White/Properties/AssemblyInfo.cs +++ b/src/TestStack.White/Properties/AssemblyInfo.cs @@ -1,4 +1,13 @@ -using System.Reflection; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// AssemblyInfo.cs +// +// -------------------------------------------------------------------------------------------------------------------- + +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; From 5cfe5fdf50cf92f279fa3b4ad5321ec062841066 Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Thu, 30 Jun 2016 00:00:06 -0700 Subject: [PATCH 05/14] Update stylecop. --- src/Samples/Todo.Core/ITaskRepository.cs | 52 +++++- .../Todo.Core/InMemoryTaskRepository.cs | 64 ++++++- .../Todo.Core/NotifyPropertyChanged.cs | 31 +++- src/Samples/Todo.Core/TodoItem.cs | 25 ++- src/Samples/WinForms/WinformsTodo/Form1.cs | 19 +- src/Samples/WinForms/WinformsTodo/Program.cs | 22 ++- .../WpfTodo.UITests/Screens/NewTaskScreen.cs | 56 +++++- .../Wpf/WpfTodo.UITests/Screens/Screen.cs | 53 ++++-- .../Wpf/WpfTodo.UITests/Screens/TodoWindow.cs | 73 ++++++-- .../Wpf/WpfTodo.UITests/Screens/UITestBase.cs | 41 ++++- .../Wpf/WpfTodo.UITests/TodoAppTests.cs | 50 ++++-- .../Wpf/WpfTodo/BusyAutomationBehaviour.cs | 56 +++++- src/Samples/Wpf/WpfTodo/DelegateCommand.cs | 100 +++-------- src/Samples/Wpf/WpfTodo/DelegateCommand{T}.cs | 157 ++++++++++++++++ src/Samples/Wpf/WpfTodo/FodyWeavers.xml | 3 +- src/Samples/Wpf/WpfTodo/MainWindow.xaml.cs | 17 +- .../Wpf/WpfTodo/MainWindowViewModel.cs | 91 +++++++--- src/Samples/Wpf/WpfTodo/NewTaskViewModel.cs | 88 ++++++--- src/Samples/Wpf/WpfTodo/NewTaskWindow.xaml.cs | 37 +++- .../Wpf/WpfTodo/Properties/AssemblyInfo.cs | 37 ++-- src/Samples/Wpf/WpfTodo/WpfTodo.csproj | 12 +- src/Samples/Wpf/WpfTodo/packages.config | 2 - .../Mappings/ControlDictionaryTests.cs | 169 +++++++++++------- .../Mappings/ControlDictionary.cs | 2 +- 24 files changed, 945 insertions(+), 312 deletions(-) create mode 100644 src/Samples/Wpf/WpfTodo/DelegateCommand{T}.cs diff --git a/src/Samples/Todo.Core/ITaskRepository.cs b/src/Samples/Todo.Core/ITaskRepository.cs index 26654cfc..ebaf194d 100644 --- a/src/Samples/Todo.Core/ITaskRepository.cs +++ b/src/Samples/Todo.Core/ITaskRepository.cs @@ -1,13 +1,61 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the ITaskRepository type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace Todo.Core { + using System.Collections.Generic; + using System.Threading.Tasks; + + /// + /// The TaskRepository interface. + /// public interface ITaskRepository { + /// + /// The get all. + /// + /// + /// The . + /// Task> GetAll(); + + /// + /// The add. + /// + /// + /// The to-do item. + /// + /// + /// The . + /// Task Add(TodoItem todoItem); + + /// + /// The delete. + /// + /// + /// The id. + /// + /// + /// The . + /// Task Delete(int id); + + /// + /// The get. + /// + /// + /// The id. + /// + /// + /// The . + /// Task Get(int id); } } \ No newline at end of file diff --git a/src/Samples/Todo.Core/InMemoryTaskRepository.cs b/src/Samples/Todo.Core/InMemoryTaskRepository.cs index 55cd1f80..70edfddb 100644 --- a/src/Samples/Todo.Core/InMemoryTaskRepository.cs +++ b/src/Samples/Todo.Core/InMemoryTaskRepository.cs @@ -1,49 +1,101 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// In memory repository where all operations take at least 1 second +// +// -------------------------------------------------------------------------------------------------------------------- namespace Todo.Core { + using System.Collections.Generic; + using System.Threading.Tasks; + /// /// In memory repository where all operations take at least 1 second /// public class InMemoryTaskRepository : ITaskRepository { + /// + /// The tasks. + /// private readonly Dictionary tasks = new Dictionary(); + + /// + /// The current id. + /// private int currentId; + /// + /// The get all. + /// + /// + /// The . + /// public Task> GetAll() { return TaskEx.Delay(1500) - .ContinueWith>(t => tasks.Values); + .ContinueWith>(t => this.tasks.Values); } + /// + /// The add. + /// + /// + /// The to-do item. + /// + /// + /// The . + /// public Task Add(TodoItem todoItem) { return TaskEx.Delay(1500) - .ContinueWith(t => tasks.Add(currentId++, todoItem)); + .ContinueWith(t => this.tasks.Add(this.currentId++, todoItem)); } + /// + /// The delete. + /// + /// + /// The id. + /// + /// + /// The . + /// public Task Delete(int id) { return TaskEx.Delay(1500) .ContinueWith(t => { if (tasks.ContainsKey(id)) - tasks.Remove(id); + { + this.tasks.Remove(id); + } }); } + /// + /// The get. + /// + /// + /// The id. + /// + /// + /// The . + /// public Task Get(int id) { return TaskEx.Delay(1500) .ContinueWith(t => { if (tasks.ContainsKey(id)) + { return tasks[id]; + } return null; }); - } } } \ No newline at end of file diff --git a/src/Samples/Todo.Core/NotifyPropertyChanged.cs b/src/Samples/Todo.Core/NotifyPropertyChanged.cs index 5277bb5e..325d958d 100644 --- a/src/Samples/Todo.Core/NotifyPropertyChanged.cs +++ b/src/Samples/Todo.Core/NotifyPropertyChanged.cs @@ -1,15 +1,40 @@ -using System.ComponentModel; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the NotifyPropertyChanged type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace Todo.Core { + using System.ComponentModel; + + /// + /// The notify property changed. + /// public class NotifyPropertyChanged : INotifyPropertyChanged { + /// + /// The property changed. + /// public event PropertyChangedEventHandler PropertyChanged; + /// + /// The on property changed. + /// + /// + /// The property name. + /// protected void OnPropertyChanged(string propertyName) { - var handler = PropertyChanged; - if (handler == null) return; + var handler = this.PropertyChanged; + if (handler == null) + { + return; + } + var e = new PropertyChangedEventArgs(propertyName); handler(this, e); } diff --git a/src/Samples/Todo.Core/TodoItem.cs b/src/Samples/Todo.Core/TodoItem.cs index 6f49d964..c81fd3a0 100644 --- a/src/Samples/Todo.Core/TodoItem.cs +++ b/src/Samples/Todo.Core/TodoItem.cs @@ -1,11 +1,34 @@ -using System; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the TodoItem type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace Todo.Core { + using System; + + /// + /// The to-do item. + /// public class TodoItem : NotifyPropertyChanged { + /// + /// Gets or sets the title. + /// public string Title { get; set; } + + /// + /// Gets or sets the description. + /// public string Description { get; set; } + + /// + /// Gets or sets the due date. + /// public DateTime? DueDate { get; set; } } } diff --git a/src/Samples/WinForms/WinformsTodo/Form1.cs b/src/Samples/WinForms/WinformsTodo/Form1.cs index 47087cf2..fb670cd1 100644 --- a/src/Samples/WinForms/WinformsTodo/Form1.cs +++ b/src/Samples/WinForms/WinformsTodo/Form1.cs @@ -1,12 +1,27 @@ -using System.Windows.Forms; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the Form1 type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace WinformsTodo { + using System.Windows.Forms; + + /// + /// The form 1. + /// public partial class Form1 : Form { + /// + /// Initializes a new instance of the class. + /// public Form1() { - InitializeComponent(); + this.InitializeComponent(); } } } diff --git a/src/Samples/WinForms/WinformsTodo/Program.cs b/src/Samples/WinForms/WinformsTodo/Program.cs index db45722c..ffa70cdc 100644 --- a/src/Samples/WinForms/WinformsTodo/Program.cs +++ b/src/Samples/WinForms/WinformsTodo/Program.cs @@ -1,17 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Forms; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the Program type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace WinformsTodo { - static class Program + using System; + using System.Windows.Forms; + + /// + /// The program. + /// + public static class Program { /// /// The main entry point for the application. /// [STAThread] - static void Main() + public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); diff --git a/src/Samples/Wpf/WpfTodo.UITests/Screens/NewTaskScreen.cs b/src/Samples/Wpf/WpfTodo.UITests/Screens/NewTaskScreen.cs index be521009..381be46e 100644 --- a/src/Samples/Wpf/WpfTodo.UITests/Screens/NewTaskScreen.cs +++ b/src/Samples/Wpf/WpfTodo.UITests/Screens/NewTaskScreen.cs @@ -1,32 +1,66 @@ -using System; -using System.Windows.Automation; -using TestStack.White.ScreenObjects; -using TestStack.White.UIItems; -using TestStack.White.UIItems.Finders; -using TestStack.White.UIItems.WindowItems; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the NewTaskScreen type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace WpfTodo.UITests.Screens { + using System; + using System.Windows.Automation; + + using TestStack.White.ScreenObjects; + using TestStack.White.UIItems; + using TestStack.White.UIItems.Finders; + using TestStack.White.UIItems.WindowItems; + + /// + /// The new task screen. + /// public class NewTaskScreen : Screen { - protected Button CreateButton; + /// + /// The create button. + /// + private readonly Button createButton = null; + /// + /// Initializes a new instance of the class. + /// + /// + /// The window. + /// + /// + /// The screen repository. + /// public NewTaskScreen(Window window, ScreenRepository screenRepository) : base(window, screenRepository) { } + /// + /// Gets or sets the title. + /// public virtual string Title { get { return Window.Get("Title").Text; } set { Window.Get("Title").Text = value; } } + /// + /// Gets or sets the description. + /// public virtual string Description { get { return Window.Get("Description").Text; } set { Window.Get("Description").Text = value; } } + /// + /// Gets or sets the due date. + /// public virtual DateTime DueDate { get @@ -35,6 +69,7 @@ public virtual DateTime DueDate var currentPropertyValue = uiItem.AutomationElement.GetCurrentPropertyValue(ValuePattern.ValueProperty); return (DateTime)currentPropertyValue; } + set { var uiItem = Window.Get(SearchCriteria.ByAutomationId("DueDate")); @@ -42,10 +77,13 @@ public virtual DateTime DueDate } } + /// + /// The create. + /// public virtual void Create() { - CreateButton.Click(); - WaitWhileBusy(); + this.createButton.Click(); + this.WaitWhileBusy(); } } } \ No newline at end of file diff --git a/src/Samples/Wpf/WpfTodo.UITests/Screens/Screen.cs b/src/Samples/Wpf/WpfTodo.UITests/Screens/Screen.cs index 03322425..c1d6b801 100644 --- a/src/Samples/Wpf/WpfTodo.UITests/Screens/Screen.cs +++ b/src/Samples/Wpf/WpfTodo.UITests/Screens/Screen.cs @@ -1,26 +1,57 @@ -using System; -using System.Windows.Automation; -using TestStack.White.ScreenObjects; -using TestStack.White.UIItems.WindowItems; -using TestStack.White.Utility; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the Screen type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace WpfTodo.UITests.Screens { + using System; + using System.Windows.Automation; + + using TestStack.White.ScreenObjects; + using TestStack.White.UIItems.WindowItems; + using TestStack.White.Utility; + + /// + /// The screen. + /// public class Screen : AppScreen { - public Screen(Window window, ScreenRepository screenRepository) : base(window, screenRepository) + /// + /// Initializes a new instance of the class. + /// + /// + /// The window. + /// + /// + /// The screen repository. + /// + protected Screen(Window window, ScreenRepository screenRepository) : base(window, screenRepository) { } - public virtual void WaitWhileBusy() + /// + /// The shell is busy. + /// + /// + /// The . + /// + public bool ShellIsBusy() { - Retry.For(ShellIsBusy, isBusy => isBusy, TimeSpan.FromSeconds(30)); + var currentPropertyValue = Window.AutomationElement.GetCurrentPropertyValue(AutomationElement.HelpTextProperty); + return currentPropertyValue != null && ((string)currentPropertyValue).Contains("Busy"); } - bool ShellIsBusy() + /// + /// The wait while busy. + /// + protected virtual void WaitWhileBusy() { - var currentPropertyValue = Window.AutomationElement.GetCurrentPropertyValue(AutomationElement.HelpTextProperty); - return currentPropertyValue != null && ((string)currentPropertyValue).Contains("Busy"); + Retry.For(this.ShellIsBusy, isBusy => isBusy, TimeSpan.FromSeconds(30)); } } } \ No newline at end of file diff --git a/src/Samples/Wpf/WpfTodo.UITests/Screens/TodoWindow.cs b/src/Samples/Wpf/WpfTodo.UITests/Screens/TodoWindow.cs index b0bd4ff6..9504ab15 100644 --- a/src/Samples/Wpf/WpfTodo.UITests/Screens/TodoWindow.cs +++ b/src/Samples/Wpf/WpfTodo.UITests/Screens/TodoWindow.cs @@ -1,32 +1,65 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using TestStack.White.Factory; -using TestStack.White.ScreenObjects; -using TestStack.White.UIItems; -using TestStack.White.UIItems.Finders; -using TestStack.White.UIItems.ListBoxItems; -using TestStack.White.UIItems.WindowItems; -using TestStack.White.UIItems.WPFUIItems; -using Todo.Core; +// -------------------------------------------------------------------------------------------------------------------- +// +// All rights reserved. +// +// +// Defines the TodoWindow type. +// +// -------------------------------------------------------------------------------------------------------------------- namespace WpfTodo.UITests.Screens { + using System; + using System.Collections.Generic; + using System.Linq; + + using TestStack.White.Factory; + using TestStack.White.ScreenObjects; + using TestStack.White.UIItems; + using TestStack.White.UIItems.Finders; + using TestStack.White.UIItems.ListBoxItems; + using TestStack.White.UIItems.WindowItems; + using TestStack.White.UIItems.WPFUIItems; + + using Todo.Core; + + /// + /// The to-do window. + /// public class TodoWindow : Screen { - protected ListBox TasksList; - protected Button AddTaskButton; + /// + /// The tasks list. + /// + private readonly ListBox tasksList = null; + + /// + /// The add task button. + /// + private readonly Button addTaskButton = null; + /// + /// Initializes a new instance of the class. + /// + /// + /// The window. + /// + /// + /// The screen repository. + /// public TodoWindow(Window window, ScreenRepository screenRepository) : base(window, screenRepository) { } + /// + /// Gets the tasks. + /// public virtual IEnumerable Tasks { get { - WaitWhileBusy(); - return from ListItem item in TasksList.Items + this.WaitWhileBusy(); + return from ListItem item in this.tasksList.Items select new TodoItem { Title = item.Get