public void WhenAddNestedAction_ShouldWork()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddActionAfterPolls(1, () => testee.AddActionAfterPolls(1, actionTester.TestAction));

            testee.ExecuteInvokes();
            actionTester.WasCalled.Should().BeFalse();
            testee.ExecuteInvokes();
            actionTester.WasCalled.Should().BeTrue();
        }
        public void WhenAddMultipleActionsWithRemainingPolls_ShouldExecuteInRightOrder()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new OrderedActionTester();

            testee.AddActionAfterPolls(1, actionTester.TestAction2);
            testee.AddActionAfterPolls(1, actionTester.TestAction1);

            testee.ExecuteInvokes();

            actionTester.FirstCalledAction.Should().Be(2, "TestAction2 was added first");
        }
        public void WhenAddActions_ShouldExecuteInRightOrder()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new OrderedActionTester();

            testee.AddActionAfterPolls(1, actionTester.TestAction2);
            testee.AddActionAfterPolls(1, actionTester.TestAction1);

            testee.ExecuteInvokes();

            actionTester.FirstCalledAction.Should().Be(2);
        }
        public void WhenAddActionWithRemainingPolls_ShouldExecuteOnRightPollCount()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddActionAfterPolls(2, actionTester.TestAction);

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

            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 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();
        }