Example #1
0
        public void CanGenerateHoursButtons()
        {
            var clock = new Clock();

            clock.ApplyDefaultStyle();

            Canvas hoursCanvas    = clock.FindVisualChild <Canvas>(Clock.HoursCanvasPartName);
            var    buttonContents = hoursCanvas.GetVisualChildren <ClockItemButton>().Select(x => x.Content.ToString());

            var expected = Enumerable.Range(1, 12).Select(x => $"{x:0}");

            Assert.Equal(expected.OrderBy(x => x), buttonContents.OrderBy(x => x));
        }
    public void TimeChangedEvent_WhenTimeChanges_EventIsRaised()
    {
        var clock = new Clock();

        clock.ApplyDefaultStyle();
        List <TimeChangedEventArgs> invocations = new();

        clock.TimeChanged += OnTimeChanged;

        void OnTimeChanged(object?sender, TimeChangedEventArgs e)
        => invocations.Add(e);

        DateTime now = DateTime.Now;

        clock.Time  = now;
        clock.Time += TimeSpan.FromMinutes(-2);

        Assert.Equal(2, invocations.Count);

        Assert.Equal(default, invocations[0].OldTime);