Index: test/Common/DelftTools.Tests/Controls/Swf/TreeViewControls/TreeViewTest.cs =================================================================== diff -u -rd8e4bf47a1ff5b13a9d9e6eaf60b9ca9cd7c7555 -r65413d7212c51bc5fb428abb0a213a878285880c --- test/Common/DelftTools.Tests/Controls/Swf/TreeViewControls/TreeViewTest.cs (.../TreeViewTest.cs) (revision d8e4bf47a1ff5b13a9d9e6eaf60b9ca9cd7c7555) +++ test/Common/DelftTools.Tests/Controls/Swf/TreeViewControls/TreeViewTest.cs (.../TreeViewTest.cs) (revision 65413d7212c51bc5fb428abb0a213a878285880c) @@ -1,12 +1,17 @@ +using System; using System.Collections; +using System.Diagnostics; using System.Linq; +using System.Threading; +using System.Windows.Forms; using DelftTools.Controls; using DelftTools.Controls.Swf.TreeViewControls; using DelftTools.Tests.TestObjects; using DelftTools.TestUtils; using NUnit.Framework; using Rhino.Mocks; using SharpTestsEx; +using TreeView = DelftTools.Controls.Swf.TreeViewControls.TreeView; namespace DelftTools.Tests.Controls.Swf.TreeViewControls { @@ -305,8 +310,74 @@ treeView.Nodes[0].Nodes[0].IsExpanded.Should("node remains expanded").Be.True(); } - private class DynamicParentNodePresenter : TreeViewNodePresenterBase + [Test] + public void TreeViewUpdateOnManyPropertyChangesShouldBeFast() { + var parent = new Child + { + Name = "parent" + }; + + for (var i = 0; i < 100; i++) + { + parent.Children.Add(new Child + { + Name = i.ToString() + }); + } + + // measure time to perform action without tree view + Func processingAction = () => + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + var rnd = new Random(); + for (var i = 0; i < 99; i++) + { + var child = parent.Children[rnd.Next(99)]; + child.Name = i.ToString(); + } + stopwatch.Stop(); + + return stopwatch.ElapsedMilliseconds; + }; + + Console.WriteLine("Elapsed time to perform action without tree view: " + processingAction()); + + var treeView = new TreeView + { + NodePresenters = + { + new ChildNodePresenter() + }, + Data = parent + }; + + // expand / collapse / expand + treeView.ExpandAll(); + + double elapsedMillisecondsWithTreeView = 0; + Action
onShow = delegate + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + elapsedMillisecondsWithTreeView = processingAction(); + Console.WriteLine("Elapsed time to perform action with tree view: " + elapsedMillisecondsWithTreeView); + + treeView.WaitUntilAllEventsAreProcessed(); + + stopwatch.Stop(); + Console.WriteLine("Elapsed time to refresh tree view: " + stopwatch.ElapsedMilliseconds); + }; + + WindowsFormsTestHelper.ShowModal(treeView, onShow); + + TestHelper.AssertIsFasterThan(10, () => Thread.Sleep((int) elapsedMillisecondsWithTreeView)); + } + + public class DynamicParentNodePresenter : TreeViewNodePresenterBase + { public override void UpdateNode(ITreeNode parentNode, ITreeNode node, Parent nodeData) { node.Text = nodeData.Name;