public void ValidateValidatesConditions()
 {
     var wasValidated = false;
     var conditionMock = new MockCondition
                             {
                                 ValidateAction = (c, t, ep) => wasValidated = true
                             };
     var task = new ConditionalTask
                    {
                        TaskConditions = new[] {conditionMock}
                    };
     task.Validate(null, ConfigurationTrace.Start(this), null);
     Assert.IsTrue(wasValidated);
 }
        public void ValidateCallsChildrenValidation()
        {
            var processor = this.mocks.StrictMock<IConfigurationErrorProcesser>();
            var validateCalled = false;
            var childCondition = new MockCondition
                {
                    ValidateAction = (c, t, ep) => validateCalled = true
                };

            this.mocks.ReplayAll();
            var condition = new AndTaskCondition
                {
                    Conditions = new[] { childCondition }
                };
            condition.Validate(null, ConfigurationTrace.Start(this), processor);

            this.mocks.VerifyAll();
            Assert.IsTrue(validateCalled);
        }
示例#3
0
        public void ValidateCallsChildrenValidation()
        {
            var processor      = this.mocks.Create <IConfigurationErrorProcesser>(MockBehavior.Strict).Object;
            var validateCalled = false;
            var childCondition = new MockCondition
            {
                ValidateAction = (c, t, ep) => validateCalled = true
            };

            var condition = new OrTaskCondition
            {
                Conditions = new[] { childCondition }
            };

            condition.Validate(null, ConfigurationTrace.Start(this), processor);

            this.mocks.VerifyAll();
            Assert.IsTrue(validateCalled);
        }
        public void ExecuteRunsTasksWhenConditionsPass()
        {
            var passRan = false;
            var failRan = false;
            var mockCondition = new MockCondition
                                    {
                                        EvalFunction = ir => true
                                    };
            var passTask = new MockTask
                               {
                                   RunAction = ir => passRan = true
                               };
            var failTask = new MockTask
                               {
                                   RunAction = ir => failRan = true
                               };
            var task = new ConditionalTask
                           {
                               Tasks = new[] {passTask},
                               ElseTasks = new[] {failTask},
                               TaskConditions = new[] {mockCondition}
                           };
            var resultMock = this.GenerateResultMock();
            
            this.mocks.ReplayAll();
            resultMock.Status = IntegrationStatus.Success;
            task.Run(resultMock);

            this.mocks.VerifyAll();
            Assert.IsTrue(passRan);
            Assert.IsFalse(failRan);
        }
        public void ExecuteRunsAllTasksWhenConditionsFailAndNotContinueOnFailure()
        {
            var passRan = false;
            var firstFailRan = false;
            var secondFailRan = false;
            var thirdFailRan = false;
            var mockCondition = new MockCondition
            {
                EvalFunction = ir => false
            };
            var passTask = new MockTask
            {
                RunAction = ir => passRan = true
            };
            var firstFailTask = new MockTask
            {
                RunAction = ir => firstFailRan = true
            };
            var secondFailTask = new MockTask
            {
                RunAction = ir => { secondFailRan = true; ir.Status = IntegrationStatus.Failure; }
            };
            var thirdFailTask = new MockTask
            {
                RunAction = ir => thirdFailRan = true
            };
            var task = new ConditionalTask
            {
                Tasks = new[] { passTask },
                ElseTasks = new[] { firstFailTask, secondFailTask, thirdFailTask },
                TaskConditions = new[] { mockCondition },
                ContinueOnFailure = false
            };
            var resultMock = this.GenerateResultMock();
            AddResultMockExpectedClone(resultMock);
            AddResultMockExpectedMerge(resultMock);

            this.mocks.ReplayAll();
            resultMock.Status = IntegrationStatus.Success;
            task.Run(resultMock);

            this.mocks.VerifyAll();
            Assert.IsFalse(passRan);
            Assert.IsTrue(firstFailRan);
            Assert.IsTrue(secondFailRan);
            Assert.IsFalse(thirdFailRan);
        }
        public void ExecuteRunsAllInnerTasksWhenConditionsFailAndContinueOnFailure()
        {
            const int innerCount = 3;
            const int leafCount = 2;

            var passRan = false;
            int taskRunCount = 0;

            var mockCondition = new MockCondition
            {
                EvalFunction = ir => false
            };
            var passTask = new MockTask
            {
                RunAction = ir => passRan = true
            };


            var innerTasks = new List<ConditionalTask>();
            for (var innerLoop = 1; innerLoop <= innerCount; innerLoop++)
            {
                var leafTasks = new List<MockTask>();
                for (var leafLoop = 1; leafLoop <= leafCount; leafLoop++)
                    leafTasks.Add(((innerLoop == 2) && (leafLoop == 2)) ?
                        new MockTask 
                        { 
                            RunAction = ir =>
                            {
                                taskRunCount++;
                                ir.Status = IntegrationStatus.Failure;
                            }
                        }
                        :
                        new MockTask
                        {
                            RunAction = ir =>
                            {
                                taskRunCount++;
                                ir.Status = IntegrationStatus.Success;
                            }
                        }
                    );

                innerTasks.Add(new ConditionalTask 
                    { 
                        ContinueOnFailure = false,
                        ElseTasks = leafTasks.ToArray(),
                        TaskConditions = new[] { mockCondition }
                    });
            }

            var task = new ConditionalTask
            {
                Tasks = new[] { passTask },
                ElseTasks = innerTasks.ToArray(),
                TaskConditions = new[] { mockCondition },
                ContinueOnFailure = true
            };
            var resultMock = this.GenerateResultMock(leafCount, leafCount);
            AddResultMockExpectedClone(resultMock, leafCount, leafCount);
            AddResultMockExpectedClone(resultMock, leafCount, leafCount);
            AddResultMockExpectedMerge(resultMock);
            AddResultMockExpectedMerge(resultMock);

            this.mocks.ReplayAll();
            resultMock.Status = IntegrationStatus.Success;
            task.Run(resultMock);

            this.mocks.VerifyAll();
            Assert.IsFalse(passRan);
            Assert.AreEqual(innerCount * leafCount, taskRunCount, "Bad task run count");
        }