public virtual void ShouldUpdateValueWithSliders()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1
            };

            DateTime value      = DateTime.Now;
            int      valueCount = 0;

            stp.ValueChanged += (sender, e) =>
            {
                valueCount++;
                value = e.NewValue.Value;
            };

            TestAsync(
                stp,
                () => stp.OverriddenHoursSlider.Value   = 8,
                () => stp.OverriddenMinutesSlider.Value = 10,
                () => stp.OverriddenSecondsSlider.Value = 12,
                () => Assert.AreEqual(3, valueCount),
                () => Assert.AreEqual(new DateTime(1900, 1, 1, 8, 10, 12).TimeOfDay, value.TimeOfDay),
                () => stp.OverriddenHoursSlider.Value = 14,
                () => Assert.AreEqual(4, valueCount),
                () => Assert.AreEqual(new DateTime(1900, 1, 1, 14, 10, 12).TimeOfDay, value.TimeOfDay));
        }
        public virtual void ShouldCoerceValue()
        {
            // todo: remove ignore tag as soon as decision has been made here
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1
            };

            TestAsync(
                stp,
                () => stp.Minimum = new DateTime(1900, 1, 1, 5, 5, 5),
                () => stp.Maximum = new DateTime(1900, 1, 1, 15, 15, 15),
                () => Assert.IsNotNull(stp.Value));
        }
        public virtual void ShouldRepresentValueInSliders()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup();

            TestAsync(
                stp,
                () => stp.Value = new DateTime(1900, 1, 1, 14, 12, 14),
                () => Assert.IsTrue(stp.OverriddenHoursSlider.Value == 14),
                () => Assert.IsTrue(stp.OverriddenMinutesSlider.Value == 12),
                () => Assert.IsTrue(stp.OverriddenSecondsSlider.Value == 14),
                () => stp.Value = new DateTime(1900, 1, 1, 8, 10, 20),
                () => Assert.IsTrue(stp.OverriddenHoursSlider.Value == 8),
                () => Assert.IsTrue(stp.OverriddenMinutesSlider.Value == 10),
                () => Assert.IsTrue(stp.OverriddenSecondsSlider.Value == 20));
        }
        public virtual void ShouldSnapValueToInterval()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 5,
                PopupMinutesInterval = 5
            };

            TestAsync(
                stp,
                () => stp.OverriddenHoursSlider.Value   = 5,
                () => stp.OverriddenMinutesSlider.Value = 26,
                () => stp.OverriddenSecondsSlider.Value = 26,
                () => Assert.AreEqual(new DateTime(1900, 1, 1, 5, 25, 25).TimeOfDay, stp.Value.Value.TimeOfDay),
                () => Assert.AreEqual(25, stp.OverriddenMinutesSlider.Value),
                () => Assert.AreEqual(25, stp.OverriddenSecondsSlider.Value));
        }
        public virtual void ShouldGenerateFormattedLabels()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1,
                Culture = new CultureInfo("en-US"),
                Format  = new CustomTimeFormat("hh:mm:ss tt"),
            };

            // rangetime is not expected to re-generate labels when
            // culture or format changes while it is open

            TestAsync(
                stp,
                () => Assert.IsTrue(stp.OverriddenHourContainer.Children.Count > 0),
                () => Assert.AreEqual("10 PM", ((Button)stp.OverriddenHourContainer.Children[0]).Content));
        }
        public virtual void ShouldRespectMinimumAndMaximum()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1
            };

            TestAsync(
                stp,
                () => stp.Minimum = new DateTime(1900, 1, 1, 5, 5, 5),
                () => stp.Maximum = new DateTime(1900, 1, 1, 15, 15, 15),
                () => stp.OverriddenHoursSlider.Value = 4,
                () => Assert.AreEqual(stp.Minimum.Value.TimeOfDay, stp.Value.Value.TimeOfDay),
                () => stp.OverriddenHoursSlider.Value = 16,
                () => Assert.AreEqual(stp.Maximum.Value.TimeOfDay, stp.Value.Value.TimeOfDay),
                () => Assert.AreEqual(15, stp.OverriddenHoursSlider.Value),
                () => Assert.AreEqual(15, stp.OverriddenMinutesSlider.Value),
                () => Assert.AreEqual(15, stp.OverriddenSecondsSlider.Value));
        }
        public virtual void ShouldDisableLabelWhenOutsideRange()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1,
                Culture = new CultureInfo("en-US"),
                Format  = new LongTimeFormat(),
                PopupTimeSelectionMode = PopupTimeSelectionMode.AllowSecondsSelection,
                Minimum = new DateTime(1900, 1, 1, 7, 30, 40),
                Maximum = new DateTime(1900, 1, 1, 11, 40, 50)
            };

            TestAsync(
                stp,
                () => Assert.IsFalse(((Button)stp.OverriddenHourContainer.Children[0]).IsEnabled),
                () => Assert.IsFalse(((Button)stp.OverriddenMinuteContainer.Children[0]).IsEnabled),
                () => Assert.IsFalse(((Button)stp.OverriddenSecondContainer.Children[0]).IsEnabled),
                () => Assert.IsFalse(((Button)stp.OverriddenHourContainer.Children[stp.OverriddenHourContainer.Children.Count - 1]).IsEnabled),
                () => Assert.IsFalse(((Button)stp.OverriddenMinuteContainer.Children[stp.OverriddenMinuteContainer.Children.Count - 1]).IsEnabled),
                () => Assert.IsFalse(((Button)stp.OverriddenSecondContainer.Children[stp.OverriddenSecondContainer.Children.Count - 1]).IsEnabled));
        }
        public virtual void ShouldBeAbleToClickLabel()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1,
                Culture = new CultureInfo("en-US"),
                Format  = new LongTimeFormat(),
                PopupTimeSelectionMode = PopupTimeSelectionMode.AllowSecondsSelection,
            };

            stp.Value = DateTime.Now;
            Button button                       = null;
            ButtonAutomationPeer peer           = null;
            IInvokeProvider      invokeProvider = null;

            TestAsync(
                stp,
                () => button         = (Button)stp.OverriddenHourContainer.Children[0],
                () => peer           = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer,
                () => invokeProvider = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider,
                () => invokeProvider.Invoke(),
                () => System.Threading.Thread.Sleep(40),     // automation peer needs time
                () => Assert.IsTrue(stp.Value.Value.Hour == 22),
                () => button         = (Button)stp.OverriddenMinuteContainer.Children[1],
                () => peer           = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer,
                () => invokeProvider = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider,
                () => invokeProvider.Invoke(),
                () => System.Threading.Thread.Sleep(40),     // automation peer needs time
                () => Assert.IsTrue(stp.Value.Value.Minute == 50),
                () => button         = (Button)stp.OverriddenSecondContainer.Children[2],
                () => peer           = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer,
                () => invokeProvider = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider,
                () => invokeProvider.Invoke(),
                () => System.Threading.Thread.Sleep(40),     // automation peer needs time
                () => Assert.IsTrue(stp.Value.Value.Second == 45));
        }
        public virtual void ShouldDisableLabelWhenOutsideRange()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
                                                     {
                                                             PopupSecondsInterval = 1,
                                                             PopupMinutesInterval = 1,
                                                             Culture = new CultureInfo("en-US"),
                                                             Format = new LongTimeFormat(),
                                                             PopupTimeSelectionMode = PopupTimeSelectionMode.AllowSecondsSelection,
                                                             Minimum = new DateTime(1900, 1, 1, 7, 30, 40),
                                                             Maximum = new DateTime(1900, 1, 1, 11, 40, 50)
                                                     };

            TestAsync(
                    stp,
                    () => Assert.IsFalse(((Button) stp.OverriddenHourContainer.Children[0]).IsEnabled),
                    () => Assert.IsFalse(((Button) stp.OverriddenMinuteContainer.Children[0]).IsEnabled),
                    () => Assert.IsFalse(((Button) stp.OverriddenSecondContainer.Children[0]).IsEnabled),
                    () => Assert.IsFalse(((Button) stp.OverriddenHourContainer.Children[stp.OverriddenHourContainer.Children.Count - 1]).IsEnabled),
                    () => Assert.IsFalse(((Button) stp.OverriddenMinuteContainer.Children[stp.OverriddenMinuteContainer.Children.Count - 1]).IsEnabled),
                    () => Assert.IsFalse(((Button) stp.OverriddenSecondContainer.Children[stp.OverriddenSecondContainer.Children.Count - 1]).IsEnabled));
        }
        public virtual void ShouldCoerceValue()
        {
            // todo: remove ignore tag as soon as decision has been made here
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1
            };

            TestAsync(
                    stp,
                    () => stp.Minimum = new DateTime(1900, 1, 1, 5, 5, 5),
                    () => stp.Maximum = new DateTime(1900, 1, 1, 15, 15, 15),
                    () => Assert.IsNotNull(stp.Value));
        }
 public virtual void ShouldBeAbleToClickLabel()
 {
     OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
                                              {
                                                      PopupSecondsInterval = 1,
                                                      PopupMinutesInterval = 1,
                                                      Culture = new CultureInfo("en-US"),
                                                      Format = new LongTimeFormat(),
                                                      PopupTimeSelectionMode = PopupTimeSelectionMode.AllowSecondsSelection,
                                              };
     stp.Value = DateTime.Now;
     Button button = null;
     ButtonAutomationPeer peer = null;
     IInvokeProvider invokeProvider = null;
     TestAsync(
             stp,
             () => button = (Button) stp.OverriddenHourContainer.Children[0],
             () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer,
             () => invokeProvider = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider,
             () => invokeProvider.Invoke(),
             () => System.Threading.Thread.Sleep(40), // automation peer needs time
             () => Assert.IsTrue(stp.Value.Value.Hour == 22),
             () => button = (Button) stp.OverriddenMinuteContainer.Children[1],
             () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer,
             () => invokeProvider = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider,
             () => invokeProvider.Invoke(),
             () => System.Threading.Thread.Sleep(40), // automation peer needs time
             () => Assert.IsTrue(stp.Value.Value.Minute == 50),
             () => button = (Button) stp.OverriddenSecondContainer.Children[2],
             () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer,
             () => invokeProvider = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider,
             () => invokeProvider.Invoke(),
             () => System.Threading.Thread.Sleep(40), // automation peer needs time
             () => Assert.IsTrue(stp.Value.Value.Second == 45));
 }
        public virtual void ShouldSnapValueToInterval()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 5,
                PopupMinutesInterval = 5
            };

            TestAsync(
                stp,
                () => stp.OverriddenHoursSlider.Value = 5,
                () => stp.OverriddenMinutesSlider.Value = 26,
                () => stp.OverriddenSecondsSlider.Value = 26,
                () => Assert.AreEqual(new DateTime(1900, 1, 1, 5, 25, 25).TimeOfDay, stp.Value.Value.TimeOfDay),
                () => Assert.AreEqual(25, stp.OverriddenMinutesSlider.Value),
                () => Assert.AreEqual(25, stp.OverriddenSecondsSlider.Value));
        }
        public virtual void ShouldGenerateFormattedLabels()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1,
                Culture = new CultureInfo("en-US"),
                Format = new CustomTimeFormat("hh:mm:ss tt"),
            };

            // rangetime is not expected to re-generate labels when 
            // culture or format changes while it is open

            TestAsync(
                stp,
                () => Assert.IsTrue(stp.OverriddenHourContainer.Children.Count > 0),
                () => Assert.AreEqual("10 PM", ((Button)stp.OverriddenHourContainer.Children[0]).Content));
        }
        public virtual void ShouldRespectMinimumAndMaximum()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
                                                      {
                                                          PopupSecondsInterval = 1, 
                                                          PopupMinutesInterval = 1
                                                      };

            TestAsync(
                stp,
                () => stp.Minimum = new DateTime(1900, 1, 1, 5, 5, 5),
                () => stp.Maximum = new DateTime(1900, 1, 1, 15, 15, 15),
                () => stp.OverriddenHoursSlider.Value = 4,
                () => Assert.AreEqual(stp.Minimum.Value.TimeOfDay, stp.Value.Value.TimeOfDay),
                () => stp.OverriddenHoursSlider.Value = 16,
                () => Assert.AreEqual(stp.Maximum.Value.TimeOfDay, stp.Value.Value.TimeOfDay),
                () => Assert.AreEqual(15, stp.OverriddenHoursSlider.Value),
                () => Assert.AreEqual(15, stp.OverriddenMinutesSlider.Value),
                () => Assert.AreEqual(15, stp.OverriddenSecondsSlider.Value));
        }
        public virtual void ShouldUpdateValueWithSliders()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup
            {
                PopupSecondsInterval = 1,
                PopupMinutesInterval = 1
            };

            DateTime value = DateTime.Now;
            int valueCount = 0;
            stp.ValueChanged += (sender, e) =>
                                    {
                                        valueCount ++;
                                        value = e.NewValue.Value;
                                    };

            TestAsync(
                stp,
                () => stp.OverriddenHoursSlider.Value = 8,
                () => stp.OverriddenMinutesSlider.Value = 10,
                () => stp.OverriddenSecondsSlider.Value = 12,
                () => Assert.AreEqual(3, valueCount),
                () => Assert.AreEqual(new DateTime(1900, 1, 1, 8, 10, 12).TimeOfDay, value.TimeOfDay),
                () => stp.OverriddenHoursSlider.Value = 14,
                () => Assert.AreEqual(4, valueCount),
                () => Assert.AreEqual(new DateTime(1900, 1, 1, 14, 10, 12).TimeOfDay, value.TimeOfDay));
        }
        public virtual void ShouldRepresentValueInSliders()
        {
            OverriddenRangeTimePickerPopup stp = new OverriddenRangeTimePickerPopup();

            TestAsync(
                stp,
                () => stp.Value = new DateTime(1900, 1, 1, 14, 12, 14),
                () => Assert.IsTrue(stp.OverriddenHoursSlider.Value == 14),
                () => Assert.IsTrue(stp.OverriddenMinutesSlider.Value == 12),
                () => Assert.IsTrue(stp.OverriddenSecondsSlider.Value == 14),
                () => stp.Value = new DateTime(1900, 1, 1, 8, 10, 20),
                () => Assert.IsTrue(stp.OverriddenHoursSlider.Value == 8),
                () => Assert.IsTrue(stp.OverriddenMinutesSlider.Value == 10),
                () => Assert.IsTrue(stp.OverriddenSecondsSlider.Value == 20));
        }