diff --git a/tests/Perspex.LeakTests/ControlTests.cs b/tests/Perspex.LeakTests/ControlTests.cs index 76351ac635..78dc8d764e 100644 --- a/tests/Perspex.LeakTests/ControlTests.cs +++ b/tests/Perspex.LeakTests/ControlTests.cs @@ -269,12 +269,12 @@ namespace Perspex.LeakTests Content = target = new TreeView { DataTemplates = new DataTemplates - { - new FuncTreeDataTemplate( - x => new TextBlock { Text = x.Name }, - x => x.Children, - x => true) - }, + { + new FuncTreeDataTemplate( + x => new TextBlock { Text = x.Name }, + x => x.Children, + x => true) + }, Items = nodes } }; diff --git a/tests/Perspex.LeakTests/StyleTests.cs b/tests/Perspex.LeakTests/StyleTests.cs index 82f8ebf1d5..30a4aef525 100644 --- a/tests/Perspex.LeakTests/StyleTests.cs +++ b/tests/Perspex.LeakTests/StyleTests.cs @@ -65,5 +65,64 @@ namespace Perspex.LeakTests dotMemory.Check(memory => Assert.Equal(0, memory.GetObjects(where => where.Type.Is()).ObjectsCount)); } + + [Fact] + public void Changing_Carousel_SelectedIndex_Should_Not_Leak_StyleActivators() + { + Func run = () => + { + Carousel target; + + var window = new Window + { + Styles = new Styles + { + new Style(x => x.OfType().Class("foo")) + { + Setters = new[] + { + new Setter(Visual.OpacityProperty, 0.5), + } + } + }, + Content = target = new Carousel + { + Items = new[] + { + new ContentControl + { + Name = "item1", + Classes = new Classes("foo"), + Content = "item1", + }, + new ContentControl + { + Name = "item2", + Classes = new Classes("foo"), + Content = "item2", + }, + } + } + }; + + // Do a layout and make sure that Carousel gets added to visual tree. + window.LayoutManager.ExecuteLayoutPass(); + Assert.IsType(window.Presenter.Child); + + target.SelectedIndex = 1; + window.LayoutManager.ExecuteLayoutPass(); + target.SelectedIndex = 0; + window.LayoutManager.ExecuteLayoutPass(); + target.SelectedIndex = 1; + window.LayoutManager.ExecuteLayoutPass(); + + return window; + }; + + var result = run(); + + dotMemory.Check(memory => + Assert.Equal(1, memory.GetObjects(where => where.Type.Is()).ObjectsCount)); + } } }