Esempio n. 1
0
        public void TableView_as_only_child_should_be_recognized()
        {
            var table = new TableView
            {
                Intent = TableIntent.Form,
                Root   = new TableRoot
                {
                    new TableSection
                    {
                        new ImageCell(),
                        new SwitchCell(),
                        new EntryCell()
                    }
                }
            };

            var page = new ContentPage
            {
                Content = table
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var pair = mgr[table.Id];

            Assert.IsNotNull(pair);
            Assert.AreEqual(3, pair.UIWidget.Children.Count);

            Assert.AreEqual(typeof(ImageCell).FullName, pair.UIWidget.Children[0].FullTypeName);
            Assert.AreEqual(typeof(SwitchCell).FullName, pair.UIWidget.Children[1].FullTypeName);
            Assert.AreEqual(typeof(EntryCell).FullName, pair.UIWidget.Children[2].FullTypeName);
        }
Esempio n. 2
0
        public void Should_return_all_parents_for_nested_stacks()
        {
            var         stack = new StackLayout();
            StackLayout last  = null;

            for (var i = 0; i < 5; i++)
            {
                var tmp = new StackLayout();

                if (last == null)
                {
                    stack.Children.Add(tmp);
                }
                else
                {
                    last.Children.Add(tmp);
                }

                last = tmp;
            }

            var page = new ContentPage
            {
                Content = stack
            };

            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var pair = mgr[last.Id];
            var cp   = ElementHelper.GetParents(pair.UIWidget);

            Assert.AreEqual(6, cp.Length);
        }
Esempio n. 3
0
        public void Calling_Contains_should_return_true_when_UIWidget_is_a_descendant_of_root()
        {
            var label = new Label();
            var child = new Entry {
                Placeholder = "text"
            };
            var layout = new StackLayout();

            layout.Children.Add(child);
            var page = new ContentPage {
                Content = layout
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var childPair      = mgr[child.Id.ToString()];
            var containsWidget = mgr.Contains(childPair.UIWidget);
            var containsVisual = mgr.Contains(childPair.VisualElement);
            var containsLabel  = mgr.Contains(label);

            Assert.IsTrue(containsWidget, "UIWidget not found.");
            Assert.IsTrue(containsVisual, "VisualElement not found.");
            Assert.IsFalse(containsLabel, "Label was not added to the page.");
        }
Esempio n. 4
0
        public void ListView_Cells_should_be_recognized()
        {
            var lv = new ListView
            {
                ItemsSource = new[]
                {
                    "1",
                    "2",
                    "3"
                }
            };

            var page = new ContentPage {
                Content = lv
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var pair = mgr[lv.Id];

            Assert.AreEqual(3, pair.UIWidget.Children.Count);

            Assert.IsFalse(pair.UIWidget.IsCell);
            Assert.IsTrue(pair.UIWidget.Children[0].IsCell);
            Assert.IsTrue(pair.UIWidget.Children[1].IsCell);
            Assert.IsTrue(pair.UIWidget.Children[2].IsCell);
        }
Esempio n. 5
0
        public void ListView_should_have_three_children_returned()
        {
            var lv = new ListView
            {
                ItemsSource = new[]
                {
                    "1",
                    "2",
                    "3"
                }
            };

            var page = new ContentPage {
                Content = lv
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var pair = mgr[lv.Id];

            Assert.AreEqual(3, pair.UIWidget.Children.Count);
            Assert.AreEqual(typeof(TextCell).FullName, pair.UIWidget.Children[0].FullTypeName);
        }
Esempio n. 6
0
        public void Should_remove_child_of_stacklayout_by_using_its_UIWidget()
        {
            var child = new Entry {
                Placeholder = "text"
            };
            var layout = new StackLayout();

            layout.Children.Add(child);
            var page = new ContentPage {
                Content = layout
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var childPair  = mgr[child.Id.ToString()];
            var layoutPair = mgr[layout.Id.ToString()];

            Assert.IsNotEmpty(layoutPair.UIWidget.Children, "The stacklayouts UIWidget should have children.");

            var removed = mgr.Remove(childPair.UIWidget);

            Assert.IsTrue(removed, "Removed wasn't true.");
            Assert.IsEmpty(layout.Children, "The stacklayout has children.");
            Assert.IsEmpty(layoutPair.UIWidget.Children, "The stacklayout has children.");
        }
Esempio n. 7
0
        public void Removing_root_UIWidget()
        {
            var page = new ContentPage();
            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            Assert.Throws <InvalidOperationException>(() => mgr.Remove(root));
        }
Esempio n. 8
0
        public void When_setting_design_surface_the_page_becomes_the_root_widget()
        {
            var mgr  = new DefaultSurfaceManager();
            var page = new ContentPage();

            var root = mgr.SetInspectorSurface(page);

            Assert.AreEqual(page.Id.ToString(), root.Id, "Ids aren't equal.");
        }
Esempio n. 9
0
        public void When_setting_design_surface_Root_is_set_and_returned()
        {
            var mgr  = new DefaultSurfaceManager();
            var page = new ContentPage();

            var root = mgr.SetInspectorSurface(page);

            Assert.AreEqual(root, mgr.Root);
        }
Esempio n. 10
0
        public void When_widget_isnt_found_during_lookup_return_null()
        {
            var page = new ContentPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var pair = mgr["12345"];

            Assert.IsNull(pair);
        }
Esempio n. 11
0
        public void Can_lookup_UIWidget_by_guid()
        {
            var page = new ContentPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);
            var match = mgr[page.Id];

            Assert.IsNotNull(match, "Match was null.");
            Assert.AreEqual(match.UIWidget.Id, page.Id.ToString());
        }
Esempio n. 12
0
        public void SetParent_entry_is_parent_and_label_is_child()
        {
            var child = new Label();
            var entry = new Entry();
            var page  = new ContentPage();
            var mgr   = new DefaultSurfaceManager();

            page.Content = entry;
            mgr.SetInspectorSurface(page);

            var parented = mgr.SetParent(child, entry);

            Assert.IsFalse(parented, "Parented should be false.");
            Assert.AreEqual(mgr.Root.Children[0].Id, entry.Id.ToString(), "The content view has changed.");
        }
Esempio n. 13
0
        public void ContentView_HasContentProperty()
        {
            var cv   = new ContentView();
            var page = new ContentPage {
                Content = cv
            };
            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var pair = mgr[cv.Id.ToString()];

            Assert.IsTrue(pair.UIWidget.HasContentProperty);
            Assert.IsTrue(pair.UIWidget.IsContentPropertyViewType);
            Assert.AreEqual(pair.UIWidget.ContentPropertyTypeName, typeof(View).FullName);
        }
        public void Page_without_content()
        {
            var mgr  = new DefaultSurfaceManager();
            var page = new ContentPage
            {
                Title = "No Content Example",
            };

            var root = mgr.SetInspectorSurface(page);

            Assert.IsNotNull(root, "Page should be in result.");
            Assert.AreEqual(page.Title, root.Name, "Title wrong.");
            Assert.AreEqual(nameof(ContentPage), root.Type, "Type wrong.");
            Assert.IsTrue(root.Children == null || root.Children.Count == 0, "No children should be returnd.");
        }
Esempio n. 15
0
        public void Test_IsDatabound_False()
        {
            var page = new ContentPage
            {
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var pair = mgr[page.Id];

            Assert.IsNotNull(pair);
            Assert.IsFalse(pair.UIWidget.IsDatabound);
        }
Esempio n. 16
0
        public void SetParent_page_is_parent_and_label_is_child()
        {
            var label = new Label {
                Text = "value"
            };
            var page = new ContentPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var parented = mgr.SetParent(label, page);

            Assert.IsTrue(parented, "SetParent returned false.");
            Assert.AreEqual(1, mgr.Root.Children.Count, "Expected one child.");
            Assert.AreEqual(label.Id.ToString(), mgr.Root.Children[0].Id, "The label widget wasn't added to the children collection.");
        }
Esempio n. 17
0
        public void ListView_Custom_cells_should_be_recognized()
        {
            var page = new ImageCellPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var listview = mgr[page.ListView.Id];

            Assert.IsNotNull(listview);

            var cell = listview.UIWidget.Children[0];

            Assert.IsNotNull(cell);
            Assert.AreEqual(typeof(CustomCell).FullName, cell.FullTypeName);
        }
Esempio n. 18
0
        public void ListView_ViewCells_in_StackLayout_recognized()
        {
            var page = new TestDataSelectorPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var listview = mgr[page.ListView.Id];

            Assert.IsNotNull(listview);

            var cell = listview.UIWidget.Children[0];

            Assert.IsNotNull(cell);
            Assert.IsTrue(cell.Children.Count > 0, "cell.Children.Count > 0");
        }
Esempio n. 19
0
        public void TableView_ImageCells_should_be_recognized()
        {
            var page = new ImageCellTableViewPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var table = mgr[page.Table.Id];

            Assert.IsNotNull(table);

            var cell = table.UIWidget.Children[0];

            Assert.IsNotNull(cell);
            Assert.AreEqual(typeof(ImageCell).FullName, cell.FullTypeName);
        }
Esempio n. 20
0
        public void StackLayout_IsLayout_no_ContentProperty()
        {
            var stack = new StackLayout();
            var page  = new ContentPage {
                Content = stack
            };
            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var pair = mgr[stack.Id.ToString()];

            Assert.AreEqual("System.Collections.IEnumerable<Xamarin.Forms.View>", pair.UIWidget.ContentPropertyTypeName);
            Assert.IsTrue(pair.UIWidget.IsLayout);
            Assert.IsTrue(pair.UIWidget.IsContentPropertyViewType);
            Assert.IsTrue(pair.UIWidget.HasContentProperty);
        }
        public void Page_with_stacklayout()
        {
            var page = new ContentPage
            {
                Title   = "Stacklayout Example",
                Content = new StackLayout
                {
                    Children =
                    {
                        new StackLayout
                        {
                            Children =
                            {
                                new Entry   {
                                    Placeholder = "placeholder "
                                },
                                new BoxView {
                                    BackgroundColor = Color.Green
                                }
                            }
                        }
                    }
                }
            };

            var builder = new DefaultSurfaceManager();

            var result    = builder.SetInspectorSurface(page);
            var flattened = result.GetNodeAndDescendants().ToArray();

            Assert.IsTrue(flattened.Length == 5, "There should have been 5 widgets created.");

            Assert.AreEqual(result.Type, nameof(ContentPage), "1st widget");
            Assert.AreEqual(result.CanDelete, false, "1st widget");

            Assert.AreEqual(result.Children[0].Type, nameof(StackLayout), "2nd widget");
            Assert.AreEqual(result.Children[0].CanDelete, true, "2nd widget");

            Assert.AreEqual(result.Children[0].Children[0].Type, nameof(StackLayout), "3rd widget");
            Assert.AreEqual(result.Children[0].Children[0].CanDelete, true, "3rd widget");

            Assert.AreEqual(result.Children[0].Children[0].Children[0].Type, nameof(Entry), "4th widget");
            Assert.AreEqual(result.Children[0].Children[0].Children[0].CanDelete, true, "4th widget");

            Assert.AreEqual(result.Children[0].Children[0].Children[1].Type, nameof(BoxView), "5th widget");
            Assert.AreEqual(result.Children[0].Children[0].Children[1].CanDelete, true, "5th widget");
        }
Esempio n. 22
0
        public void When_setting_design_surface_the_UIWidget_type_properties_are_set()
        {
            const string title = "Some title.";
            var          mgr   = new DefaultSurfaceManager();

            var page = new ContentPage
            {
                Title = title
            };

            var root = mgr.SetInspectorSurface(page);

            Assert.AreEqual(root.Id, page.Id.ToString(), "Ids aren't equal.");
            Assert.AreEqual(root.FullTypeName, page.GetType().FullName, "Full type names aren't equal.");
            Assert.AreEqual(root.Type, page.GetType().Name, "Short type names aren't equal.");
            Assert.AreEqual(root.Name, title, "The titles aren't equal.");
        }
Esempio n. 23
0
        public void Should_return_null_on_invalid_input()
        {
            var traverser = new DefaultSurfaceManager();

            // Act
            var nullArg = traverser[null];

            Assert.IsNull(nullArg, "Null returns null.");

            var empty = traverser[""];

            Assert.IsNull(empty, "Empty returns null.");

            var whitespace = traverser[" "];

            Assert.IsNull(whitespace, "Whitespace returns null.");
        }
Esempio n. 24
0
        public void Should_return_ContentPage_as_parent()
        {
            var label = new Label();

            var page = new ContentPage
            {
                Content = label
            };

            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var pair = mgr[label.Id];
            var cp   = ElementHelper.GetParents(pair.UIWidget);

            Assert.AreEqual(root.Id, cp[0].Id);
        }
Esempio n. 25
0
        public void String_Content_isnt_Layout()
        {
            var label = new Label {
                Text = "value"
            };
            var page = new ContentPage {
                Content = label
            };
            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var pair = mgr[label.Id.ToString()];

            Assert.IsFalse(pair.UIWidget.IsLayout);
            Assert.IsTrue(pair.UIWidget.HasContentProperty);
            Assert.IsFalse(pair.UIWidget.IsContentPropertyViewType);
            Assert.AreEqual(typeof(string).FullName, pair.UIWidget.ContentPropertyTypeName);
        }
Esempio n. 26
0
        public void ListView_ViewCell_children_recognized()
        {
            var page = new ImageCellPage();
            var mgr  = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var listview = mgr[page.ListView.Id];

            Assert.IsNotNull(listview);

            var cell = listview.UIWidget.Children[0];

            Assert.IsNotNull(cell);
            Assert.IsTrue(cell.Children.Count > 0, "cell.Children.Count > 0");
            Assert.AreEqual("Xamarin.Forms.StackLayout", cell.Children[0].FullTypeName);
            Assert.IsTrue(cell.Children[0].Children.Count > 0, "cell.Children[0].Children.Count > 0");
        }
Esempio n. 27
0
        public void Button_has_no_children_and_no_ContentProperty()
        {
            var btn = new Button {
                Text = "value"
            };
            var page = new ContentPage {
                Content = btn
            };
            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var pair = mgr[btn.Id.ToString()];

            Assert.IsFalse(pair.UIWidget.IsLayout);
            Assert.IsFalse(pair.UIWidget.HasContentProperty);
            Assert.IsFalse(pair.UIWidget.IsContentPropertyViewType);
            Assert.AreEqual(null, pair.UIWidget.ContentPropertyTypeName);
        }
        public void Should_return_view_when_using_indexer()
        {
            var entry  = new Entry();
            var button = new Button();

            // start of page
            var page = new ContentPage
            {
                Content = new StackLayout
                {
                    Children =
                    {
                        new StackLayout
                        {
                            Children =
                            {
                                new ContentView
                                {
                                    Content = new StackLayout
                                    {
                                        Children =
                                        {
                                            entry,
                                            button
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);

            var entryFound  = mgr[entry.Id.ToString()];
            var buttonFound = mgr[button.Id.ToString()];

            Assert.AreSame(entry, entryFound.VisualElement, "Entry is incorrect.");
            Assert.AreSame(button, buttonFound.VisualElement, "Button is incorrect.");
            Assert.IsNull(mgr["test"], "Should return null when id not found.");
        }
Esempio n. 29
0
        public void SetParent_stacklayout_is_parent_and_entry_is_child()
        {
            var child  = new Entry();
            var layout = new StackLayout();
            var page   = new ContentPage();
            var mgr    = new DefaultSurfaceManager();

            page.Content = layout;
            mgr.SetInspectorSurface(page);

            var parented = mgr.SetParent(child, layout);

            Assert.IsTrue(parented, "Parented returned false.");

            var layoutWidget = mgr[layout.Id.ToString()];

            Assert.IsNotEmpty(layoutWidget.UIWidget.Children, "UIWidget did not have any children.");
            Assert.IsNotEmpty(layout.Children, "StackLayout view did not contain children.");
        }
Esempio n. 30
0
        public void SetParent_ScrollView_is_parent_and_entry_is_child()
        {
            var child   = new Label();
            var content = new ScrollView();
            var page    = new ContentPage {
                Content = content
            };
            var mgr = new DefaultSurfaceManager();

            mgr.SetInspectorSurface(page);
            var parented = mgr.SetParent(child, content);

            Assert.IsTrue(parented, "Parented should be true.");

            var contentPair = mgr[content.Id.ToString()];

            Assert.IsNotEmpty(contentPair.UIWidget.Children, "Content children should have an element.");
            Assert.AreEqual(contentPair.UIWidget.Children[0].Id, child.Id.ToString(), "The wrong child was attached.");
        }