public void TestOverride()
        {
            var testResults = new FailureControlActor.FailureControlTestResults();
            var failure     = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(testResults), "failure-for-stop"));

            var access = testResults.AfterCompleting(40);

            for (var idx = 0; idx < 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            access.ReadFromExpecting("beforeResume", 20);
            Assert.Equal(20, access.ReadFrom <int>("beforeResume"));
            Assert.Equal(20, access.ReadFrom <int>("failNowCount"));
            Assert.Equal(20, access.ReadFrom <int>("afterFailureCount"));

            access = testResults.AfterCompleting(40);

            for (var idx = 0; idx < 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            access.ReadFromExpecting("beforeResume", 40);
            Assert.Equal(40, access.ReadFrom <int>("failNowCount"));
            Assert.Equal(40, access.ReadFrom <int>("afterFailureCount"));

            Assert.False(failure.ActorInside.IsStopped);
        }
        public void TestRestartSupervisor()
        {
            var restartSupervisorTestResults = new RestartSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartSupervisorActor>(
                    Definition.Parameters(restartSupervisorTestResults), "restart-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-restart"));

            var failureAccess = failureControlTestResults.AfterCompleting(6);
            var restartAccess = restartSupervisorTestResults.AfterCompleting(1);

            failure.Actor.FailNow();

            Assert.Equal(1, restartAccess.ReadFrom <int>("informedCount"));
            Assert.Equal(2, failureAccess.ReadFrom <int>("beforeStartCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("afterRestartCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("afterStopCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("beforeRestartCount"));

            var afterFailureAccess = failureControlTestResults.AfterCompleting(1);

            failure.Actor.AfterFailure();

            Assert.Equal(1, afterFailureAccess.ReadFrom <int>("afterFailureCount"));
            Assert.Equal(0, afterFailureAccess.ReadFrom <int>("stoppedCount"));
        }
        public void Test5Intensity1PeriodRestartStrategy()
        {
            var restartFiveInOneSupervisorTestResults = new RestartFiveInOneSupervisorActor.RestartFiveInOneSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartFiveInOneSupervisorActor>(
                    Definition.Parameters(restartFiveInOneSupervisorTestResults), "resuming-5-1-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            var failureAccess = failureControlTestResults.AfterCompleting(0);
            var restartAccess = restartFiveInOneSupervisorTestResults.AfterCompleting(5);

            for (var idx = 1; idx <= 5; ++idx)
            {
                failureAccess = failureControlTestResults.AfterCompleting(1);
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            Assert.Equal(5, failureAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(5, failureAccess.ReadFrom <int>("afterFailureCount"));

            failureAccess = failureControlTestResults.AfterCompleting(1);
            restartAccess = restartFiveInOneSupervisorTestResults.AfterCompleting(1);

            failure.Actor.FailNow();
            failure.Actor.AfterFailure();

            Assert.True(failure.ActorInside.IsStopped);
            Assert.Equal(6, failureAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(5, failureAccess.ReadFrom <int>("afterFailureCount"));
            Assert.Equal(6, restartAccess.ReadFrom <int>("informedCount"));
        }
        public void TestEscalate()
        {
            var escalateSupervisorTestResults = new EscalateSupervisorActor.EscalateSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <EscalateSupervisorActor>(
                    Definition.Parameters(escalateSupervisorTestResults), "escalate"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure"));

            var escalateAccess = escalateSupervisorTestResults.AfterCompleting(1);
            var failureAccess  = failureControlTestResults.AfterCompleting(1);

            failure.Actor.FailNow();

            Assert.Equal(1, escalateAccess.ReadFrom <int>("informedCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("stoppedCount"));
        }
        public void TestPublicRootDefaultParentSupervisor()
        {
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = World.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), World.DefaultParent, "failure-for-default"));

            var access = failureControlTestResults.AfterCompleting(3);

            failure.FailNow();

            Assert.Equal(1, access.ReadFrom <int>("failNowCount"));
            Assert.Equal(1, access.ReadFromExpecting("afterRestartCount", 1));

            access = failureControlTestResults.AfterCompleting(1);

            failure.AfterFailure();

            Assert.Equal(1, access.ReadFromExpecting <int>("afterFailureCount", 1));
        }
        public void TestStoppingSupervisor()
        {
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <StoppingSupervisorActor>(Definition.NoParameters, "stopping-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            var access = failureControlTestResults.AfterCompleting(2);

            failure.Actor.FailNow();

            Assert.Equal(1, access.ReadFrom <int>("failNowCount"));

            failure.Actor.AfterFailure();

            Assert.Equal(1, access.ReadFrom <int>("stoppedCount"));

            Assert.Equal(0, access.ReadFrom <int>("afterFailureCount"));
        }
        public void TestRestartForeverStrategy()
        {
            var restartForeverSupervisorTestResults = new RestartForeverSupervisorActor.RestartForeverSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartForeverSupervisorActor>(
                    Definition.Parameters(restartForeverSupervisorTestResults), "restart-forever-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            var failedAccess  = failureControlTestResults.AfterCompleting(40);
            var restartAccess = restartForeverSupervisorTestResults.AfterCompleting(40);

            for (var idx = 1; idx <= 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            Assert.Equal(20, failedAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(20, failedAccess.ReadFrom <int>("afterFailureCount"));

            failedAccess = failureControlTestResults.AfterCompleting(40);

            for (var idx = 1; idx <= 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            failureControlTestResults.UntilFailNow.Completes();
            failureControlTestResults.UntilAfterFail.Completes();

            Assert.Equal(40, failedAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(40, failedAccess.ReadFrom <int>("afterFailureCount"));
            Assert.True(40 <= restartAccess.ReadFrom <int>("informedCount"));
        }