예제 #1
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.");
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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.");
        }
예제 #6
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);
        }
예제 #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));
        }
예제 #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.");
        }
예제 #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);
        }
예제 #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);
        }
예제 #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());
        }
예제 #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.");
        }
        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.");
        }
예제 #14
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);
        }
예제 #15
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);
        }
예제 #16
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);
        }
예제 #17
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);
        }
예제 #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");
        }
예제 #19
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.");
        }
예제 #20
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);
        }
        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");
        }
예제 #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.");
        }
예제 #23
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);
        }
예제 #24
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);
        }
예제 #25
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);
        }
예제 #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");
        }
        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.");
        }
예제 #28
0
        public void Should_remove_only_design_surface_child_by_using_its_UIWidget()
        {
            var label = new Label {
                Text = "value"
            };
            var page = new ContentPage {
                Content = label
            };
            var mgr  = new DefaultSurfaceManager();
            var root = mgr.SetInspectorSurface(page);

            var labelPair = mgr[label.Id.ToString()];
            var removed   = mgr.Remove(labelPair.UIWidget);

            Assert.IsTrue(removed, "Removed wasn't true.");
            Assert.IsEmpty(mgr.Root.Children, "mgr.Root.Children should be empty.");
            Assert.IsEmpty(root.Children, "root.Children should be empty.");
            Assert.IsNull(page.Content, "Page content should be null.");
        }
예제 #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.");
        }
예제 #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.");
        }