public void WhenAddMultipleActionsWithDifferentDelays_ShouldExecuteInRightOrder()
        {
            var testee  = new ApplicationDispatcher();
            var action1 = new ActionTester();
            var action2 = new ActionTester();

            testee.AddDelayedAction(-1, action1.TestAction);
            testee.AddDelayedAction(5, action2.TestAction);

            testee.ExecuteInvokes();
            action1.WasCalled.Should().BeTrue();
            action2.WasCalled.Should().BeFalse();

            Thread.Sleep(25);
            testee.ExecuteInvokes();
            action2.WasCalled.Should().BeTrue();
        }
        public void WhenAddNegativeDelayedAction_ShouldExecuteImmediately()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddDelayedAction(-10, actionTester.TestAction);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeTrue();
        }
        public void WhenClearActions_ShouldExecuteNothing()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddDelayedAction(5, actionTester.TestAction);
            testee.AddActionAfterPolls(1, actionTester.TestAction);

            testee.CancellAll();
            Thread.Sleep(25);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeFalse();
        }
        public void WhenAddDelayedAction_ShouldExecuteDelayed()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddDelayedAction(20, actionTester.TestAction);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeFalse();

            Thread.Sleep(25);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeTrue();
        }
        public void WhenAddMixedActions_AfterPoll_ShouldExecuteAll()
        {
            var testee = new ApplicationDispatcher();

            var action1 = new ActionTester();
            var action2 = new ActionTester();

            testee.AddDelayedAction(-1, action1.TestAction);
            testee.AddActionAfterPolls(1, action2.TestAction);

            testee.ExecuteInvokes();

            action1.WasCalled.Should().BeTrue();
            action2.WasCalled.Should().BeTrue();
        }