コード例 #1
0
ファイル: TaskDirectorTests.cs プロジェクト: vetterd/CSBuild
        public void Build_state_should_be_set_correctly_if_a_task_should_be_skipped()
        {
            TaskRegistration
                .RegisterTask<ExampleTask0>()
                .AsDefault();

            TaskRegistration
                .RegisterTaskFilter<ExampleTaskFilter0>();

            TaskRegistration
                .RegisterGlobalFilter<ExampleGlobalFilter0>();

            BuildStateSnapshot stateWhileGlobalFilterBeforeExecution = null;
            BuildStateSnapshot stateWhileTaskFilterBeforeExecution = null;
            BuildStateSnapshot stateWhileTaskRun = null;
            BuildStateSnapshot stateWhileTaskFilterAfterExecution = null;
            BuildStateSnapshot stateWhileGlobalFilterAfterExecution = null;

            TaskManagementTestHelper.AddCallCallback<ExampleGlobalFilter0>(nameof(ExampleGlobalFilter0.BeforeExecution), (i, p) => { stateWhileGlobalFilterBeforeExecution = new BuildStateSnapshot(BuildState); return null; });
            TaskManagementTestHelper.AddCallCallback<ExampleTaskFilter0>(nameof(ExampleTaskFilter0.BeforeExecution), (i, p) => { stateWhileTaskFilterBeforeExecution = new BuildStateSnapshot(BuildState); return TaskExecution.SkipTask; });
            TaskManagementTestHelper.AddCallCallback<ExampleTask0>(nameof(ExampleTask0.Run), (i, p) => { stateWhileTaskRun = new BuildStateSnapshot(BuildState); return null; });
            TaskManagementTestHelper.AddCallCallback<ExampleTaskFilter0>(nameof(ExampleTaskFilter0.AfterExecution), (i, p) => { stateWhileTaskFilterAfterExecution = new BuildStateSnapshot(BuildState); return null; });
            TaskManagementTestHelper.AddCallCallback<ExampleGlobalFilter0>(nameof(ExampleGlobalFilter0.AfterExecution), (i, p) => { stateWhileGlobalFilterAfterExecution = new BuildStateSnapshot(BuildState); return null; });

            TaskDirector.RunRequestedTask();

            stateWhileGlobalFilterBeforeExecution.Check(null, false, false);
            stateWhileTaskFilterBeforeExecution.Check(typeof(ExampleTask0), false, false);
            Assert.IsNull(stateWhileTaskRun);
            stateWhileTaskFilterAfterExecution.Check(typeof(ExampleTask0), false, true);
            stateWhileGlobalFilterBeforeExecution.Check(null, false, false);
            stateWhileGlobalFilterAfterExecution.Check(null, false, false);
        }
コード例 #2
0
ファイル: TaskDirectorTests.cs プロジェクト: vetterd/CSBuild
        public void Build_state_should_be_set_correctly_if_the_build_runs_with_error()
        {
            TaskRegistration
                .RegisterTask<ExampleTask0>()
                .AsDefault();

            TaskRegistration
                .RegisterTaskFilter<ExampleTaskFilter0>();

            TaskRegistration
                .RegisterGlobalFilter<ExampleGlobalFilter0>();

            BuildStateSnapshot stateWhileGlobalFilterBeforeExecution = null;
            BuildStateSnapshot stateWhileTaskFilterBeforeExecution = null;
            BuildStateSnapshot stateWhileTaskRun = null;
            BuildStateSnapshot stateWhileTaskFilterAfterExecution = null;
            BuildStateSnapshot stateWhileGlobalFilterAfterExecution = null;

            TaskManagementTestHelper.AddCallCallback<ExampleGlobalFilter0>(nameof(ExampleGlobalFilter0.BeforeExecution), (i, p) => { stateWhileGlobalFilterBeforeExecution = new BuildStateSnapshot(BuildState); return null; });
            TaskManagementTestHelper.AddCallCallback<ExampleTaskFilter0>(nameof(ExampleTaskFilter0.BeforeExecution), (i, p) => { stateWhileTaskFilterBeforeExecution = new BuildStateSnapshot(BuildState); return TaskExecution.Continue; });
            TaskManagementTestHelper.AddCallCallback<ExampleTask0>(nameof(ExampleTask0.Run), (i, p) => { stateWhileTaskRun = new BuildStateSnapshot(BuildState); throw new Exception(); });
            TaskManagementTestHelper.AddCallCallback<ExampleTaskFilter0>(nameof(ExampleTaskFilter0.AfterExecution), (i, p) => { stateWhileTaskFilterAfterExecution = new BuildStateSnapshot(BuildState); return null; });
            TaskManagementTestHelper.AddCallCallback<ExampleGlobalFilter0>(nameof(ExampleGlobalFilter0.AfterExecution), (i, p) => { stateWhileGlobalFilterAfterExecution = new BuildStateSnapshot(BuildState); return null; });

            Assert.AreNotEqual(0, TaskDirector.RunRequestedTask());

            stateWhileGlobalFilterBeforeExecution.Check(null, false, false);
            stateWhileTaskFilterBeforeExecution.Check(typeof(ExampleTask0), false, false);
            stateWhileTaskRun.Check(typeof(ExampleTask0), false, false);
            stateWhileTaskFilterAfterExecution.Check(typeof(ExampleTask0), true, false);
            stateWhileGlobalFilterBeforeExecution.Check(null, false, false);
            stateWhileGlobalFilterAfterExecution.Check(null, false, false);
        }