public void UpdateSingleFrame_OthertKey_DoesNotCompletesSequence()
        {
            var    done     = false;
            var    clock    = new FakeClock();
            Action callback = () => done = true;

            var sequence = new KeyboardSequenceDetector(
                clock,
                callback,
                new[]
            {
                new KeyFrame(Key.RightCtrl, true, 0),
            });

            sequence.Update(Key.Space, true);

            Assert.That(done, Is.False);
        }
        public void UpdateMultipleFrames_CorrectInput_CompletesSequence()
        {
            bool   done     = false;
            var    clock    = new FakeClock();
            Action callback = () => done = true;

            var sequence = new KeyboardSequenceDetector(
                clock,
                callback,
                new[]
            {
                new KeyFrame(Key.RightCtrl, true, 0),
                new KeyFrame(Key.RightCtrl, false, 0),
            });

            sequence.Update(Key.RightCtrl, true);
            sequence.Update(Key.RightCtrl, false);

            Assert.That(done, Is.True);
        }
        public void UpdateSingleFrame_CalledManyTimes_CanBeReused()
        {
            int    done     = 0;
            var    clock    = new FakeClock();
            Action callback = () => done++;

            var sequence = new KeyboardSequenceDetector(
                clock,
                callback,
                new[]
            {
                new KeyFrame(Key.RightCtrl, true, 0),
            });

            sequence.Update(Key.RightCtrl, true);
            sequence.Update(Key.RightCtrl, true);
            sequence.Update(Key.RightCtrl, true);
            sequence.Update(Key.RightCtrl, true);

            Assert.That(done, Is.EqualTo(4));
        }
        public void UpdateMultipleFrames_CorrectInputWithinTime_CompletesSequence()
        {
            bool   done     = false;
            var    clock    = new FakeClock();
            Action callback = () => done = true;

            var sequence = new KeyboardSequenceDetector(
                clock,
                callback,
                new[]
            {
                new KeyFrame(Key.RightCtrl, true, 0),
                new KeyFrame(Key.RightCtrl, false, 100),
            });

            sequence.Update(Key.RightCtrl, true);

            clock.Elapsed = TimeSpan.FromMilliseconds(99);
            sequence.Update(Key.RightCtrl, false);

            Assert.That(done, Is.True);
        }
        public void UpdateMultipleFrames_TooSlow_SequenceFailes()
        {
            bool   done     = false;
            var    clock    = new FakeClock();
            Action callback = () => done = true;

            var sequence = new KeyboardSequenceDetector(
                clock,
                callback,
                new[]
            {
                new KeyFrame(Key.RightCtrl, true, 0),
                new KeyFrame(Key.RightCtrl, false, 100),
            });

            sequence.Update(Key.RightCtrl, true);

            clock.Elapsed = TimeSpan.FromMilliseconds(200);
            sequence.Update(Key.RightCtrl, false);

            Assert.That(done, Is.False);
        }