示例#1
0
        public void TextBox_With_Xaml_Binding_Is_Freed()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                Func <Window> run = () =>
                {
                    var window = new Window
                    {
                        DataContext = new Node {
                            Name = "foo"
                        },
                        Content = new TextBox()
                    };

                    var binding = new Avalonia.Markup.Xaml.Data.Binding
                    {
                        Path = "Name"
                    };

                    var textBox = (TextBox)window.Content;
                    textBox.Bind(TextBox.TextProperty, binding);

                    window.Show();

                    // Do a layout and make sure that TextBox gets added to visual tree and its
                    // Text property set.
                    LayoutManager.Instance.ExecuteInitialLayoutPass(window);
                    Assert.IsType <TextBox>(window.Presenter.Child);
                    Assert.Equal("foo", ((TextBox)window.Presenter.Child).Text);

                    // Clear the content and DataContext and ensure the TextBox is removed.
                    window.Content     = null;
                    window.DataContext = null;
                    LayoutManager.Instance.ExecuteLayoutPass();
                    Assert.Null(window.Presenter.Child);

                    return(window);
                };

                var result = run();
                PurgeMoqReferences();

                dotMemory.Check(memory =>
                                Assert.Equal(0, memory.GetObjects(where => where.Type.Is <TextBox>()).ObjectsCount));
                dotMemory.Check(memory =>
                                Assert.Equal(0, memory.GetObjects(where => where.Type.Is <Node>()).ObjectsCount));
            }
        }
示例#2
0
        public void TextBox_With_Xaml_Binding_Is_Freed()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                Func<Window> run = () =>
                {
                    var window = new Window
                    {
                        DataContext = new Node { Name = "foo" },
                        Content = new TextBox()
                    };

                    var binding = new Avalonia.Markup.Xaml.Data.Binding
                    {
                        Path = "Name"
                    };

                    var textBox = (TextBox)window.Content;
                    textBox.Bind(TextBox.TextProperty, binding);

                    // Do a layout and make sure that TextBox gets added to visual tree and its 
                    // Text property set.
                    LayoutManager.Instance.ExecuteInitialLayoutPass(window);
                    Assert.IsType<TextBox>(window.Presenter.Child);
                    Assert.Equal("foo", ((TextBox)window.Presenter.Child).Text);

                    // Clear the content and DataContext and ensure the TextBox is removed.
                    window.Content = null;
                    window.DataContext = null;
                    LayoutManager.Instance.ExecuteLayoutPass();
                    Assert.Null(window.Presenter.Child);

                    return window;
                };

                var result = run();
                PurgeMoqReferences();

                dotMemory.Check(memory =>
                    Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount));
                dotMemory.Check(memory =>
                    Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Node>()).ObjectsCount));
            }
        }