public void MeasureParentOnceTest() { TestTaskScheduler scheduler = (TestTaskScheduler)ApplicationHost.Current.TaskScheduler; using (scheduler.DisableImmediateProcessing()) { TestContainer parent = new TestContainer(); TestElement child = new TestElement { MeasureSize = new Size(100, 100), ArrangeSize = new Size(100, 100), }; parent.IsRootElement = true; parent.Child = child; parent.Measure(new Size(100, 100)); parent.Arrange(new Rect(0, 0, 200, 200)); scheduler.ProcessDueOperations(); Assert.AreEqual(1, parent.MeasureCount); Assert.AreEqual(1, parent.ArrangeCount); Assert.AreEqual(1, child.MeasureCount); Assert.AreEqual(1, child.ArrangeCount); Assert.IsTrue(parent.IsMeasureValid); Assert.IsTrue(parent.IsArrangeValid); Assert.IsTrue(child.IsMeasureValid); Assert.IsTrue(child.IsArrangeValid); } }
public void MeasureInvisibleOnceOnlyTest() { TestTaskScheduler scheduler = (TestTaskScheduler)ApplicationHost.Current.TaskScheduler; using (scheduler.DisableImmediateProcessing()) { TestElement child = new TestElement { MeasureSize = new Size(100, 100), ArrangeSize = new Size(100, 100) }; TestContainer parent = new TestContainer { IsRootElement = true }; parent.Child = child; parent.Measure(Size.Infinity); parent.Arrange(new Rect(parent.DesiredSize)); Assert.AreEqual(1, parent.MeasureCount); Assert.AreEqual(1, parent.ArrangeCount); Assert.AreEqual(1, child.MeasureCount); Assert.AreEqual(1, child.ArrangeCount); Assert.AreEqual(new Size(100, 100), child.DesiredSize); Assert.AreEqual(new Size(100, 100), parent.DesiredSize); child.Visibility = Visibility.Collapsed; scheduler.ProcessDueOperations(); Assert.AreEqual(2, parent.MeasureCount); Assert.AreEqual(2, parent.ArrangeCount); Assert.AreEqual(1, child.MeasureCount); Assert.AreEqual(1, child.ArrangeCount); Assert.AreEqual(Size.Zero, child.DesiredSize); Assert.AreEqual(Size.Zero, parent.DesiredSize); child.InvalidateMeasure(); child.InvalidateArrange(); scheduler.ProcessDueOperations(); Assert.AreEqual(2, parent.MeasureCount); Assert.AreEqual(2, parent.ArrangeCount); Assert.AreEqual(1, child.MeasureCount); Assert.AreEqual(1, child.ArrangeCount); parent.InvalidateMeasure(); parent.InvalidateArrange(); scheduler.ProcessDueOperations(); Assert.AreEqual(3, parent.MeasureCount); Assert.AreEqual(3, parent.ArrangeCount); Assert.AreEqual(1, child.MeasureCount); Assert.AreEqual(1, child.ArrangeCount); } }