public virtual void ShouldIncrementAndDecrement() { OverriddenDomainUpDown dud = new OverriddenDomainUpDown(); dud.Items.Add(1); dud.Items.Add(2); dud.Items.Add(3); dud.Items.Add(4); dud.IsCyclic = false; TestAsync( dud, () => Assert.AreEqual(1, dud.Value), () => dud.Decrement(), () => Assert.AreEqual(2, dud.Value), () => Assert.AreEqual(1, dud.CurrentIndex), () => dud.Decrement(), () => dud.Decrement(), () => Assert.AreEqual(4, dud.Value), () => dud.Decrement(), () => Assert.AreEqual(4, dud.Value), () => dud.Increment(), () => dud.Increment(), () => dud.Increment(), () => dud.Increment(), () => Assert.AreEqual(1, dud.Value), () => dud.Increment(), () => Assert.AreEqual(1, dud.Value)); }
public virtual void ShouldGrabFocusWhenSpinning() { OverriddenDomainUpDown dud = new OverriddenDomainUpDown(); dud.Items.Add("a"); dud.Items.Add("b"); dud.Items.Add("c"); dud.CurrentIndex = 1; // using timer so that the tests never get blocked Timer timer = new Timer(state => Assert.Fail("Did not get focus in time. This test has been reported to fail sometimes on first run."), new object(), 2000, 0); Button b = new Button(); bool isLoaded = false; dud.Loaded += delegate { isLoaded = true; }; bool buttonHasFocus = false; b.GotFocus += delegate { buttonHasFocus = true; // potentially null if (timer != null) { // reset the timer for another period. timer.Change(2000, 0); } }; EnqueueCallback(() => TestPanel.Children.Add(dud)); EnqueueCallback(() => TestPanel.Children.Add(b)); EnqueueConditional(() => isLoaded); EnqueueCallback(() => b.Focus()); EnqueueConditional(() => buttonHasFocus); EnqueueCallback(() => buttonHasFocus = false); EnqueueCallback(() => Assert.IsTrue(Input.FocusManager.GetFocusedElement() == b)); EnqueueCallback(() => dud.Increment()); EnqueueVisualDelay(500); EnqueueCallback(() => Assert.IsTrue(Input.FocusManager.GetFocusedElement() != b)); EnqueueCallback(() => Assert.IsTrue(dud.IsEditing == false)); EnqueueCallback(() => b.Focus()); EnqueueConditional(() => buttonHasFocus); EnqueueCallback(() => timer.Dispose()); // get rid of the timer. EnqueueCallback(() => timer = null); EnqueueCallback(() => dud.Decrement()); EnqueueVisualDelay(500); EnqueueCallback(() => Assert.IsTrue(Input.FocusManager.GetFocusedElement() != b)); EnqueueCallback(() => Assert.IsTrue(dud.IsEditing == false)); EnqueueTestComplete(); }