Exemplo n.º 1
0
        public void NoPatterns()
        {
            IFakeUiElement element =
                FakeFactory.GetAutomationElement(
                    ControlType.Button,
                    "name",
                    "auId",
                    "className",
                    new IBasePattern[] {},
                    true);

            MbUnit.Framework.Assert.AreEqual(0, element.GetSupportedPatterns().Count());
            Assert.Equal(0, element.GetSupportedPatterns().Count());
        }
Exemplo n.º 2
0
        public void OnePattern()
        {
            IFakeUiElement element =
                FakeFactory.GetAutomationElement(
                    ControlType.Button,
                    "name",
                    "auId",
                    "className",
                    new[] { AutomationFactory.GetPatternAdapter <IValuePattern>(AutomationFactory.GetUiElement(), null) },
                    true);

            MbUnit.Framework.Assert.AreEqual(1, element.GetSupportedPatterns().Count());
            MbUnit.Framework.Assert.Exists(element.GetSupportedPatterns(), p => p is IValuePattern);
            Assert.Equal(1, element.GetSupportedPatterns().Count());
            // Xunit.Assert.Contains<IBasePattern>(AutomationFactory.GetPatternAdapter<IValuePattern>(AutomationFactory.GetUiElement(), null) as IBasePattern, element.GetSupportedPatterns());
        }
Exemplo n.º 3
0
        public void ThreePatterns()
        {
            IFakeUiElement element =
                FakeFactory.GetAutomationElement(
                    ControlType.Button,
                    "name",
                    "auId",
                    "className",
                    new IBasePattern[] {
                AutomationFactory.GetPatternAdapter <IExpandCollapsePattern>(AutomationFactory.GetUiElement(), null),
                AutomationFactory.GetPatternAdapter <ITableItemPattern>(AutomationFactory.GetUiElement(), null),
                AutomationFactory.GetPatternAdapter <IWindowPattern>(AutomationFactory.GetUiElement(), null)
            },
                    true);

            MbUnit.Framework.Assert.AreEqual(3, element.GetSupportedPatterns().Count());
            MbUnit.Framework.Assert.Exists(element.GetSupportedPatterns(), p => p is IExpandCollapsePattern);
            MbUnit.Framework.Assert.Exists(element.GetSupportedPatterns(), p => p is ITableItemPattern);
            MbUnit.Framework.Assert.Exists(element.GetSupportedPatterns(), p => p is IWindowPattern);
            Assert.Equal(3, element.GetSupportedPatterns().Count());
            // Xunit.Assert.Contains<IBasePattern>(AutomationFactory.GetPatternAdapter<IExpandCollapsePattern>(AutomationFactory.GetUiElement(), null) as IBasePattern, element.GetSupportedPatterns());
            // Xunit.Assert.Contains<IBasePattern>(AutomationFactory.GetPatternAdapter<ITableItemPattern>(AutomationFactory.GetUiElement(), null), element.GetSupportedPatterns());
            // Xunit.Assert.Contains<IBasePattern>(AutomationFactory.GetPatternAdapter<IWindowPattern>(AutomationFactory.GetUiElement(), null), element.GetSupportedPatterns());
        }
Exemplo n.º 4
0
        internal static IFakeUiElement GetAutomationElement(ElementData data, IBasePattern[] patterns, bool expected)
        {
            // 20140312
            // IFakeUiElement element = Substitute.For<FakeUiElement,ISupportsCached,ISupportsCurrent>();
            IFakeUiElement element = null;

            if (Preferences.UseElementsCurrent && !Preferences.UseElementsCached)
            {
                element = Substitute.For <FakeUiElement, ISupportsCurrent>();
            }
            if (Preferences.UseElementsCached && !Preferences.UseElementsCurrent)
            {
                element = Substitute.For <FakeUiElement, ISupportsCached>();
            }
            if (Preferences.UseElementsCached && Preferences.UseElementsCurrent)
            {
                element = Substitute.For <FakeUiElement, ISupportsCached, ISupportsCurrent>();
            }
            if (!Preferences.UseElementsCached && !Preferences.UseElementsCurrent)
            {
                element = Substitute.For <FakeUiElement>();
            }

            if (Preferences.UseElementsCurrent)
            {
                var current = Substitute.For <IUiElementInformation>();
                current.ProcessId.Returns(data.Current_ProcessId);
                current.ControlType.Returns(data.Current_ControlType);
                current.Name.Returns(!string.IsNullOrEmpty(data.Current_Name) ? data.Current_Name : string.Empty);
                current.AutomationId.Returns(!string.IsNullOrEmpty(data.Current_AutomationId) ? data.Current_AutomationId : string.Empty);
                current.ClassName.Returns(!string.IsNullOrEmpty(data.Current_ClassName) ? data.Current_ClassName : string.Empty);
                current.NativeWindowHandle.Returns(data.Current_NativeWindowHandle);
                element.GetCurrent().Returns <IUiElementInformation>(current);
            }

            if (Preferences.UseElementsCached)
            {
                var cached = Substitute.For <IUiElementInformation>();

                cached.ProcessId.Returns(data.Cached_ProcessId);
                cached.ControlType.Returns(data.Cached_ControlType);
                cached.Name.Returns(!string.IsNullOrEmpty(data.Cached_Name) ? data.Cached_Name : string.Empty);
                cached.AutomationId.Returns(!string.IsNullOrEmpty(data.Cached_AutomationId) ? data.Cached_AutomationId : string.Empty);
                cached.ClassName.Returns(!string.IsNullOrEmpty(data.Cached_ClassName) ? data.Cached_ClassName : string.Empty);
                cached.NativeWindowHandle.Returns(data.Cached_NativeWindowHandle);
                element.GetCached().Returns <IUiElementInformation>(cached);
            }

            element.Patterns.AddRange(patterns);
            element.GetSupportedPatterns().Returns(element.Patterns.ToArray());

            element = AddPatternAction <IDockPattern>(DockPattern.Pattern, patterns, element);
            element = AddPatternAction <IExpandCollapsePattern>(ExpandCollapsePattern.Pattern, patterns, element);
            element = AddPatternAction <IGridItemPattern>(GridItemPattern.Pattern, patterns, element);
            element = AddPatternAction <IGridPattern>(GridPattern.Pattern, patterns, element);
            element = AddPatternAction <IInvokePattern>(InvokePattern.Pattern, patterns, element);
            element = AddPatternAction <IRangeValuePattern>(RangeValuePattern.Pattern, patterns, element);
            element = AddPatternAction <IScrollItemPattern>(ScrollItemPattern.Pattern, patterns, element);
            element = AddPatternAction <IScrollPattern>(ScrollPattern.Pattern, patterns, element);
            element = AddPatternAction <ISelectionItemPattern>(SelectionItemPattern.Pattern, patterns, element);
            element = AddPatternAction <ISelectionPattern>(SelectionPattern.Pattern, patterns, element);
            element = AddPatternAction <ITableItemPattern>(TableItemPattern.Pattern, patterns, element);
            element = AddPatternAction <ITablePattern>(TablePattern.Pattern, patterns, element);
            element = AddPatternAction <ITextPattern>(TextPattern.Pattern, patterns, element);
            element = AddPatternAction <ITogglePattern>(TogglePattern.Pattern, patterns, element);
            element = AddPatternAction <ITransformPattern>(TransformPattern.Pattern, patterns, element);
            element = AddPatternAction <IValuePattern>(ValuePattern.Pattern, patterns, element);
            element = AddPatternAction <IWindowPattern>(WindowPattern.Pattern, patterns, element);

            if (expected)
            {
                element.GetTag().Returns("expected");
            }

            element.GetSourceElement().Returns(element);

            return(element);
        }