Example #1
0
        public static async Task ClickFlyoutCloseButton(DependencyObject element, bool isAccept)
        {
            // The Flyout close button could either be a part of the Flyout itself or it could be in the AppBar
            // We look in both places.
            ButtonBase button = default;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                string buttonName = isAccept ? "AcceptButton" : "DismissButton";

                button = TreeHelper.GetVisualChildByNameFromOpenPopups(buttonName, element) as ButtonBase;
                ;

                //if (button == null)
                //{
                //	var cmdBar = TestServices.Utilities.RetrieveOpenBottomCommandBar();
                //	if (cmdBar != null)
                //	{
                //		button = cmdBar.PrimaryCommands[isAccept ? 0 : 1] as ButtonBase;
                //	}
                //}
            });

            Assert.IsNotNull(button, "Close button not found");

            await DoClickUsingAP(button);
        }
Example #2
0
        public Task When_Identity_And_TransformBounds() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform();

            Assert.AreEqual(new Rect(0, 0, 0, 0), SUT.TransformBounds(new Rect(0, 0, 0, 0)));
        });
Example #3
0
        public Task When_ProgressRing_Collapsed() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new ProgressRing
            {
                Visibility = Visibility.Collapsed
            };

            var spacerBorder = new Border
            {
                Width  = 10,
                Height = 10,
                Margin = ThicknessHelper.FromUniformLength(5)
            };

            var root = new Grid
            {
                Children =
                {
                    spacerBorder,
                    SUT
                }
            };

            root.Measure(new Size(1000, 1000));
            Assert.AreEqual(10d + 5d + 5d, root.DesiredSize.Height);
        });
Example #4
0
        public async Task VerifyDefaultsAndBasicSetting()
        {
            SplitButton splitButton = null;
            Flyout      flyout      = null;
            TestCommand command     = null;
            int         parameter   = 0;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                flyout  = new Flyout();
                command = new TestCommand();

                splitButton = new SplitButton();
                Verify.IsNotNull(splitButton);

                // Verify Defaults
                Verify.IsNull(splitButton.Flyout);
                Verify.IsNull(splitButton.Command);
                Verify.IsNull(splitButton.CommandParameter);

                // Verify basic setters
                splitButton.Flyout           = flyout;
                splitButton.Command          = command;
                splitButton.CommandParameter = parameter;
            });

            await RunOnUIThread.ExecuteAsync(() =>
            {
                Verify.AreEqual(splitButton.Flyout, flyout);
                Verify.AreEqual(splitButton.Command, command);
                Verify.AreEqual(splitButton.CommandParameter, parameter);
            });
        }
Example #5
0
        public async Task VerifyNullTemplateGivesMeaningfullError()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                ItemsRepeater repeater = null;
                const int numItems     = 10;

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    // DataTemplateSelector always returns null, but throws hresult_invalid_argument when container is null
                    elementFactory: new DataTemplateSelector(),
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );
                bool threwException = false;
                try
                {
                    await UpdateLayoutWithWaitAsync();
                } catch (Exception e)
                {
                    threwException = true;
                    Verify.IsTrue(e.Message.Contains("Null encountered as data template. That is not a valid value for a data template, and can not be used."));
                }
                Verify.IsTrue(threwException);
                // Set content to null so testapp does not try to update layout again
                Content = null;
            });
        }
Example #6
0
        public async Task ValidateNullItemTemplateAndContainerInItems()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                const int numItems     = 10;
                ItemsRepeater repeater = null;
                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems).Select(i => new Button()
                {
                    Content = i
                }),                                           // ItemsSource is UIElements
                    elementFactory: null,                     // No ItemTemplate
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();

                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));

                for (int i = 0; i < numItems; i++)
                {
                    var element = (Button)repeater.TryGetElement(i);
                    Verify.AreEqual(i, element.Content);
                }

                Button button0 = (Button)repeater.TryGetElement(0);
                Verify.IsNotNull(button0.Parent);

                repeater.ItemsSource = null;
                Verify.IsNull(button0.Parent);
            });
        }
Example #7
0
        public async Task VerifyClearingNodeWithNoChildren()
        {
            TreeView     treeView      = null;
            TreeViewNode treeViewNode1 = null;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                treeViewNode1 = new TreeViewNode();
                treeView      = new TreeView();
                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                var listControl = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
                treeView.RootNodes.Add(treeViewNode1);
                var children            = (treeViewNode1.Children as IObservableVector <TreeViewNode>);
                children.VectorChanged += (vector, args) =>
                {
                    if (((IVectorChangedEventArgs)args).CollectionChange == CollectionChange.Reset)
                    {
                        // should not reset if there are not children items
                        throw new InvalidOperationException();
                    }
                };
                Verify.AreEqual(listControl.GetItems()?.Count(), 1);

                // this should no-op and not crash
                treeViewNode1.Children.Clear();
            });

            await TestServices.WindowHelper.WaitForIdle();
        }
Example #8
0
 public async Task ValidateTemplateSwitchingRefreshesElementsNonVirtualizingLayout()
 {
     await RunOnUIThread.ExecuteAsync(async() =>
     {
         ValidateTemplateSwitchingRefreshesElements(new NonVirtualStackLayout());
     });
 }
Example #9
0
        public async Task ValidateCustomElementFactory()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: new MockElementFactory()
                {
                    GetElementFunc = delegate(int index, UIElement owner)
                    {
                        return(new Button()
                        {
                            Content = index.ToString()
                        });
                    },
                    ClearElementFunc = delegate(UIElement element, UIElement owner)
                    {
                        Verify.AreEqual(typeof(Button), element.GetType());
                    }
                },
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();
                for (int i = 0; i < numItems; i++)
                {
                    var element = (Button)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Content.ToString());
                }
            });
        }
Example #10
0
        public async Task ValidateTreeViewItemSourceChangeUpdatesChevronOpacity()
        {
            TreeView treeView = null;
            ObservableCollection <int> collection = null;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                treeView   = new TreeView();
                collection = new ObservableCollection <int>();
                collection.Add(5);
                treeView.ItemsSource = collection;
                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            TreeViewItem tvi = null;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                tvi = (TreeViewItem)treeView.ContainerFromItem(5);
                Verify.AreEqual(tvi.GlyphOpacity, 0.0);
                tvi.ItemsSource = collection;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                Verify.AreEqual(tvi.GlyphOpacity, 1.0);
            });
        }
Example #11
0
        internal static async Task <Point> GetElementPosition(FrameworkElement element, float fractionOfWidth, float fractionOfHeight)
        {
            Point point = default;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                double height = 0;
                double width  = 0;
                height        = element.ActualHeight;
                width         = element.ActualWidth;

                if (height == 0.0)
                {
                    throw new InvalidOperationException("Element has no height.");
                }
                if (width == 0.0)
                {
                    throw new InvalidOperationException("Element has no width.");
                }

                // Start with the point at the specified fraction into the element, and then
                // transform that to global coordinates.
                point.X = width * fractionOfWidth;
                point.Y = height * fractionOfHeight;

                var spTransform = element.TransformToVisual(null);
                point           = spTransform.TransformPoint(point);
            });

            return(point);
        }
Example #12
0
        public async Task TreeViewPendingSelectedNodesTest()
        {
            TreeView     treeView = null;
            TreeViewNode node1    = null;
            TreeViewNode node2    = null;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                treeView = new TreeView();
                treeView.SelectionMode = TreeViewSelectionMode.Multiple;

                node1 = new TreeViewNode()
                {
                    Content = "Node1"
                };
                node2 = new TreeViewNode()
                {
                    Content = "Node2"
                };
                treeView.RootNodes.Add(node1);
                treeView.RootNodes.Add(node2);
                treeView.SelectedNodes.Add(node1);

                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                Verify.AreEqual(true, IsMultiSelectCheckBoxChecked(treeView, node1));
                Verify.AreEqual(false, IsMultiSelectCheckBoxChecked(treeView, node2));
            });
        }
Example #13
0
        public async Task TreeViewUpdateTest()
        {
            TreeView     treeView      = null;
            TreeViewNode treeViewNode1 = null;
            TreeViewNode treeViewNode2 = null;
            TreeViewNode treeViewNode3 = null;
            TreeViewNode treeViewNode4 = null;
            TreeViewNode treeViewNode5 = null;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                treeViewNode1 = new TreeViewNode();
                treeViewNode2 = new TreeViewNode();
                treeViewNode3 = new TreeViewNode();
                treeViewNode4 = new TreeViewNode();
                treeViewNode5 = new TreeViewNode();

                treeViewNode1.Children.Add(treeViewNode2);
                treeViewNode1.Children.Add(treeViewNode3);
                treeViewNode1.Children.Add(treeViewNode4);
                treeViewNode1.Children.Add(treeViewNode5);

                treeView = new TreeView();
                TestServices.WindowHelper.WindowContent = treeView;
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                var listControl = FindVisualChildByName(treeView, "ListControl") as TreeViewList;
                treeView.RootNodes.Add(treeViewNode1);
                Verify.AreEqual(listControl.GetItems()?.Count(), 1);

                treeView.Expand(treeViewNode1);
                Verify.AreEqual(listControl.GetItems()?.Count(), 5);

                treeViewNode1.Children.RemoveAt(2);
                Verify.AreEqual(listControl.GetItems()?.Count(), 4);
                Verify.AreEqual(listControl.GetItemFromIndex(0), treeViewNode1);
                Verify.AreEqual(listControl.GetItemFromIndex(1), treeViewNode2);
                Verify.AreEqual(listControl.GetItemFromIndex(2), treeViewNode3);
                Verify.AreEqual(listControl.GetItemFromIndex(3), treeViewNode5);

                treeViewNode1.Children.Insert(1, treeViewNode4);
                Verify.AreEqual(listControl.GetItems()?.Count(), 5);
                Verify.AreEqual(listControl.GetItemFromIndex(0), treeViewNode1);
                Verify.AreEqual(listControl.GetItemFromIndex(1), treeViewNode2);
                Verify.AreEqual(listControl.GetItemFromIndex(2), treeViewNode4);
                Verify.AreEqual(listControl.GetItemFromIndex(3), treeViewNode3);
                Verify.AreEqual(listControl.GetItemFromIndex(4), treeViewNode5);

                treeViewNode1.Children.Clear();
                Verify.AreEqual(listControl.GetItems()?.Count(), 1);
                Verify.AreEqual(listControl.GetItemFromIndex(0), treeViewNode1);
            });

            await TestServices.WindowHelper.WaitForIdle();
        }
Example #14
0
        public async Task ValidateBindingAndTemplateSelection()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var staticTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
						<TextBlock Text='static' />
					</DataTemplate>"                    );
                var bindTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
						<TextBlock Text='{Binding}' />
					</DataTemplate>"                    );
                var elementFactory = new RecyclingElementFactory()
                {
                    RecyclePool = new RecyclePool(),
                    Templates   =
                    {
                        { "static", staticTemplate },
                        { "bind",   bindTemplate   }
                    }
                };

                elementFactory.SelectTemplateKey +=
                    delegate(RecyclingElementFactory sender, SelectTemplateEventArgs args)
                {
                    args.TemplateKey = ((int)args.DataContext % 2 == 0) ? "bind" : "static";
                };

                const int numItems     = 10;
                ItemsRepeater repeater = null;
                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: elementFactory,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();

                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    if (i % 2 == 0)
                    {
                        // Text is bound to the data for even indicies
                        Verify.AreEqual(i.ToString(), element.Text);
                        Verify.AreEqual(i, element.DataContext);
                    }
                    else
                    {
                        // Text explicitly set on the element only for odd indicies
                        Verify.AreEqual("static", element.Text);
                    }
                }
            });
        }
Example #15
0
        //TODO Uno specific: This test is adjusted to pass on Android - UpdateLayout needs to be called twice.
        public async Task ValidateSwitchingItemsSourceRefreshesElements(bool isVirtualLayout)
        {
            const int     numItems = 10;
            ItemsRepeater repeater = null;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                repeater = new ItemsRepeater()
                {
                    ItemsSource = Enumerable.Range(0, numItems),
                };

                // By default we use stack layout that is virtualizing.
                if (!isVirtualLayout)
                {
                    repeater.Layout = new NonVirtualStackLayout();
                }

                Content = new ItemsRepeaterScrollHost()
                {
                    Width        = 400,
                    Height       = 400,
                    ScrollViewer = new Windows.UI.Xaml.Controls.ScrollViewer()
                    {
                        Content = repeater
                    }
                };

                Content.UpdateLayout();
                Content.UpdateLayout();
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                }

                repeater.ItemsSource = Enumerable.Range(20, numItems);
                Content.UpdateLayout();
                Content.UpdateLayout();
            });

            await TestServices.WindowHelper.WaitForIdle();

            await RunOnUIThread.ExecuteAsync(() =>
            {
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual((i + 20).ToString(), element.Text);
                }
            });
        }
Example #16
0
        public async Task TreeViewNodeTest()
        {
            await RunOnUIThread.ExecuteAsync(() =>
            {
                TreeViewNode treeViewNode1 = new TreeViewNode();
                TreeViewNode treeViewNode2 = new TreeViewNode();
                TreeViewNode treeViewNode3 = new TreeViewNode();

                Verify.AreEqual(false, treeViewNode1.HasChildren);
                Verify.AreEqual(false, (bool)treeViewNode1.GetValue(TreeViewNode.HasChildrenProperty));

                //Test adding a single TreeViewNode
                treeViewNode1.Children.Add(treeViewNode2);

                Verify.AreEqual(treeViewNode2.Parent, treeViewNode1);
                Verify.AreEqual(treeViewNode1.Children.Count, 1);
                Verify.AreEqual(treeViewNode1.Children[0], treeViewNode2);
                Verify.AreEqual(treeViewNode1.IsExpanded, false);
                Verify.AreEqual(treeViewNode2.Depth, 0);

                //Test removing a single TreeViweNode
                treeViewNode1.Children.RemoveAt(0);

                Verify.IsNull(treeViewNode2.Parent);
                Verify.AreEqual(treeViewNode1.Children.Count, 0);
                Verify.AreEqual(treeViewNode2.Depth, -1);

                //Test insert multiple TreeViewNodes
                treeViewNode1.Children.Insert(0, treeViewNode2);
                treeViewNode1.Children.Insert(0, treeViewNode3);

                Verify.AreEqual(treeViewNode1.Children.Count, 2);

                Verify.AreEqual(treeViewNode1.Children[0], treeViewNode3);
                Verify.AreEqual(treeViewNode3.Depth, 0);
                Verify.AreEqual(treeViewNode3.Parent, treeViewNode1);

                Verify.AreEqual(treeViewNode1.Children[1], treeViewNode2);
                Verify.AreEqual(treeViewNode2.Depth, 0);
                Verify.AreEqual(treeViewNode2.Parent, treeViewNode1);

                //Test remove multiple TreeViewNodes
                treeViewNode1.Children.RemoveAt(0);

                Verify.AreEqual(treeViewNode1.Children[0], treeViewNode2);
                Verify.AreEqual(treeViewNode1.Children.Count, 1);
                Verify.IsNull(treeViewNode3.Parent);
                Verify.AreEqual(treeViewNode3.Depth, -1);

                treeViewNode1.Children.RemoveAt(0);

                Verify.AreEqual(treeViewNode1.Children.Count, 0);
                Verify.IsNull(treeViewNode2.Parent);
                Verify.AreEqual(treeViewNode2.Depth, -1);
            });
        }
Example #17
0
        public Task When_Translate_And_TransformPoint() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform()
            {
                Matrix = MatrixHelper.Create(1, 0, 0, 1, 10, 20)
            };

            Assert.AreEqual(new Point(10, 20), SUT.TransformPoint(new Point(0, 0)));
        });
Example #18
0
        public Task When_Rotate_And_TransformPoint() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform()
            {
                Matrix = MatrixHelper.FromMatrix3x2(Matrix3x2.CreateRotation((float)Math.PI / 2))
            };

            Assert.AreEqual(new Point(-1, 1), SUT.TransformPoint(new Point(1, 1)));
        });
Example #19
0
        public Task MeasureOverrideWithNan() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MyControl01();

            SUT.BaseAvailableSize = new Size(double.NaN, double.NaN);
            SUT.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Assert.AreEqual(new Size(double.PositiveInfinity, double.PositiveInfinity), SUT.MeasureOverrides.Last());
            Assert.AreEqual(new Size(0, 0), SUT.DesiredSize);
        });
Example #20
0
        public async Task ValidateCorrectSizeWhenEmptyDataTemplateInSelector()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='30' Width='50' />
						</DataTemplate>"                        );
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><Border Height='0' /></DataTemplate>");
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                repeater = new ItemsRepeater()
                {
                    ItemTemplate = selector,
                    Layout       = new StackLayout(),
                    ItemsSource  = Enumerable.Range(0, numItems)
                };

                repeater.VerticalAlignment   = VerticalAlignment.Top;
                repeater.HorizontalAlignment = HorizontalAlignment.Left;
                Content = repeater;

                await UpdateLayoutWithWaitAsync();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (FrameworkElement)repeater.TryGetElement(i);
                    if (i % 2 == 0)
                    {
                        Verify.AreEqual(element.Height, 0);
                    }
                    else
                    {
                        Verify.AreEqual(element.Height, 30);
                    }
                }

                Verify.AreEqual(5 * 30, repeater.ActualHeight);

                // ItemsRepeater stretches page, so actual width is width of page and not 50
                //Verify.AreEqual(50, repeater.ActualWidth);


                repeater.ItemsSource = null;
                await UpdateLayoutWithWaitAsync();
            });
        }
Example #21
0
 public async Task VerifyContactPropertyMetadata()
 {
     await RunOnUIThread.ExecuteAsync(() =>
     {
         Windows.UI.Xaml.XamlTypeInfo.XamlControlsXamlMetaDataProvider provider = new Windows.UI.Xaml.XamlTypeInfo.XamlControlsXamlMetaDataProvider();
         var picturePersonType = provider.GetXamlType(typeof(PersonPicture).FullName);
         var contactMember     = picturePersonType.GetMember("Contact");
         var memberType        = contactMember.Type;
         Verify.AreEqual(memberType.BaseType.FullName, "Object");
     });
 }
Example #22
0
        public Task When_Measure_Once() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MyControl01();

            SUT.Measure(new Size(10, 10));
            Assert.AreEqual(1, SUT.MeasureOverrides.Count);
            Assert.AreEqual(new Size(10, 10), SUT.MeasureOverrides[0]);

            SUT.Measure(new Size(10, 10));
            Assert.AreEqual(1, SUT.MeasureOverrides.Count);
        });
Example #23
0
        public static async Task <bool> IsInVisualState(Control control, string visualStateGroupName, string visualStateName)
        {
            bool result = false;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                var rootVisual       = (FrameworkElement)VisualTreeHelper.GetChild(control, 0);
                var visualStateGroup = GetVisualStateGroup(rootVisual, visualStateGroupName);
                result = visualStateGroup != null && visualStateName == visualStateGroup.CurrentState.Name;
            });

            return(result);
        }
Example #24
0
        internal static async Task OpenDateTimePicker(DatePicker dateTimePicker)
        {
            Button button = default;

            await RunOnUIThread.ExecuteAsync(() =>
            {
                button = TreeHelper.GetVisualChildByName(dateTimePicker, "FlyoutButton") as Button;
            });

            ControlHelper.DoClickUsingTap(button);
            await TestServices.WindowHelper.WaitForIdle();
        }
Example #25
0
        public async Task VerifyAutomationName()
        {
            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Automation.Peers.PersonPictureAutomationPeer"))
            {
                await RunOnUIThread.ExecuteAsync(() =>
                {
                    PersonPicture personPicture = new PersonPicture();
                    Verify.IsNotNull(personPicture);

                    // Set properties and ensure that the AutomationName updates accordingly
                    personPicture.Initials = "AB";
                    String automationName  = AutomationProperties.GetName(personPicture);
                    Verify.AreEqual(automationName, "AB");

                    personPicture.DisplayName = "Jane Smith";
                    automationName            = AutomationProperties.GetName(personPicture);
                    Verify.AreEqual(automationName, "Jane Smith");

                    if (ApiInformation.IsTypePresent("Windows.ApplicationModel.Contacts.Contact"))
                    {
                        Contact contact       = new Contact();
                        contact.FirstName     = "John";
                        contact.LastName      = "Doe";
                        personPicture.Contact = contact;
                        automationName        = AutomationProperties.GetName(personPicture);
                        Verify.AreEqual(automationName, "John Doe");

                        personPicture.IsGroup = true;
                        automationName        = AutomationProperties.GetName(personPicture);
                        Verify.AreEqual(automationName, "Group");
                        personPicture.IsGroup = false;

                        personPicture.BadgeGlyph = "\uE765";
                        automationName           = AutomationProperties.GetName(personPicture);
                        Verify.AreEqual(automationName, "John Doe, icon");

                        personPicture.BadgeText = "Skype";
                        automationName          = AutomationProperties.GetName(personPicture);
                        Verify.AreEqual(automationName, "John Doe, Skype");
                        personPicture.BadgeText = "";

                        personPicture.BadgeNumber = 5;
                        automationName            = AutomationProperties.GetName(personPicture);
                        Verify.AreEqual(automationName, "John Doe, 5 items");

                        personPicture.BadgeText = "direct reports";
                        automationName          = AutomationProperties.GetName(personPicture);
                        Verify.AreEqual(automationName, "John Doe, 5 direct reports");
                    }
                });
            }
        }
Example #26
0
        public Task When_RotateQuarter_And_TransformPoint() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MatrixTransform()
            {
                Matrix = MatrixHelper.FromMatrix3x2(Matrix3x2.CreateRotation((float)Math.PI / 4))
            };

            var expected = new Point(0, 1.41421353816986);
            var res      = SUT.TransformPoint(new Point(1, 1));
            Assert.AreEqual(expected.X, res.X, 1e-10, $"{expected} != {res}");
            Assert.AreEqual(expected.Y, res.Y, 1e-10, $"{expected} != {res}");
        });
Example #27
0
        public Task MeasureWithNan() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var SUT = new MyControl01();

            SUT.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Assert.AreEqual(new Size(double.PositiveInfinity, double.PositiveInfinity), SUT.MeasureOverrides.Last());
            Assert.AreEqual(new Size(0, 0), SUT.DesiredSize);

            Assert.ThrowsException <InvalidOperationException>(() => SUT.Measure(new Size(double.NaN, double.NaN)));
            Assert.ThrowsException <InvalidOperationException>(() => SUT.Measure(new Size(42.0, double.NaN)));
            Assert.ThrowsException <InvalidOperationException>(() => SUT.Measure(new Size(double.NaN, 42.0)));
        });
Example #28
0
        [Ignore]         // Failing on WASM - https://github.com/unoplatform/uno/issues/2314
#endif
        public Task MeasureOverride_With_Nan_In_Grid() =>
        RunOnUIThread.ExecuteAsync(() =>
        {
            var grid = new Grid();

            var SUT     = new MyControl02();
            SUT.Content = new Grid();
            grid.Children.Add(SUT);

            SUT.BaseAvailableSize = new Size(double.NaN, double.NaN);
            grid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Assert.AreEqual(new Size(double.PositiveInfinity, double.PositiveInfinity), SUT.MeasureOverrides.Last());
            Assert.AreEqual(new Size(0, 0), SUT.DesiredSize);
        });
Example #29
0
        public async Task VerifySelectTemplateLayoutFallback()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='static' Height='30' />
						</DataTemplate>"                        );
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='30' />
						</DataTemplate>"                        );
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MyContainerSelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: selector,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();

                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    if (i % 2 == 0)
                    {
                        // Text is bound to the data for even indices
                        Verify.AreEqual(i.ToString(), element.Text);
                        Verify.AreEqual(i, element.DataContext);
                    }
                    else
                    {
                        // Text explicitly set on the element only for odd indices
                        Verify.AreEqual("static", element.Text);
                    }
                }
            });
        }
Example #30
0
        public async Task ValidateRecyclingElementFactoryWithSingleTemplate()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var itemTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='uninitialized' />
						</DataTemplate>"                        );
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var elementFactory     = new RecyclingElementFactoryDerived()
                {
                    Templates      = { { "key", itemTemplate } },
                    RecyclePool    = new RecyclePool(),
                    GetElementFunc = delegate(int index, UIElement owner, UIElement elementFromBase)
                    {
                        ((TextBlock)elementFromBase).Text = index.ToString();
                        return(elementFromBase);
                    },
                    ClearElementFunc = delegate(UIElement element, UIElement owner)
                    {
                        ((TextBlock)element).Text = "uninitialized";
                    },
                };

                elementFactory.SelectTemplateKey += delegate(RecyclingElementFactory sender, SelectTemplateEventArgs args)
                {
                    Verify.Fail("SelectTemplateKey event should not be raised when using a single template");
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems).Select(i => string.Format("Item #{0}", i)),
                    elementFactory: elementFactory,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();

                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                }
            });
        }