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 Perspex.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(); 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)); } }
public void TextBox_With_Xaml_Binding_Is_Freed() { Func<Window> run = () => { var window = new Window { DataContext = new Node { Name = "foo" }, Content = new TextBox() }; var binding = new Perspex.Markup.Xaml.Data.Binding { Path = "Name" }; binding.Bind((TextBox)window.Content, TextBox.TextProperty); // Do a layout and make sure that TextBox gets added to visual tree and its // Text property set. window.LayoutManager.ExecuteLayoutPass(); 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; window.LayoutManager.ExecuteLayoutPass(); Assert.Null(window.Presenter.Child); return window; }; var result = run(); 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)); }