Exemplo n.º 1
0
        private void IsSatisfiedBySpecifications(IPackage Package)
        {
            foreach (var workflow in this.Workflow.Workflows)
            {
                string nSpace = this.GetType().Namespace;
                Assembly assembly = typeof(WorkflowSpecification).Assembly;

                Type type = assembly.GetType(string.Format("{0}.{1}", nSpace, workflow.Specification));

                ISpecification spec = (ISpecification)Activator.CreateInstance(type);

                Outcome outcome;

                // TODO: Conditional smell.
                if (spec.GetType() == typeof(WorkflowSpecification))
                {
                    WorkflowSpecification workflowSpecification = (WorkflowSpecification)spec;
                    workflowSpecification.Workflow = workflow;
                    outcome = workflowSpecification.IsSatisfiedBy(Package);
                }
                else
                {
                    outcome = spec.IsSatisfiedBy(Package);
                }

                Workflow.Outcomes.Add(outcome);
            }
        }
Exemplo n.º 2
0
 public Outcome IsSatisfiedBy(IPackage Package)
 {
     Animal animal = (Animal)Package.Entity;
     bool result = (animal.Age < 10);
     this.Outcome.Result = result;
     return this.Outcome;
 }
Exemplo n.º 3
0
        public void workflow_nested_spec()
        {
            Animal animal = new Animal { Age = 1, Health = HealthStatus.Healthy, Type = AnimalType.Cow };
            var package = new IPackage() { Entity = animal };

            Workflow grandchildWorkflow = new Workflow();
            grandchildWorkflow.Workflows.Add(new Workflow() { Specification = "Processor.CowSpecification" });

            Workflow childworkflow = new Workflow();
            childworkflow.Workflows.Add(new Workflow() { Specification = "Processor.HealthySpecification" });
            childworkflow.Workflows.Add(grandchildWorkflow);

            Workflow parentWorkflow = new Workflow();
            parentWorkflow.Workflows.Add(new Workflow() { Specification = "Processor.HeavySpecification" });
            parentWorkflow.Workflows.Add(childworkflow);

            Workflow grandParentWorkflow = new Workflow();
            grandParentWorkflow.Workflows.Add(new Workflow() { Specification = "Processor.YoungSpecification" });
            grandParentWorkflow.Workflows.Add(parentWorkflow);

            var spec = new WorkflowSpecification();
            spec.Workflow = grandParentWorkflow;

            Outcome outcome = spec.IsSatisfiedBy(package);

            TraceWorkflow(parentWorkflow);

            Assert.IsFalse(outcome.Result);
        }
Exemplo n.º 4
0
 public Outcome IsSatisfiedBy(IPackage Package)
 {
     Animal animal = (Animal)Package.Entity;
     bool result = (animal.Health == HealthStatus.Healthy);
     this.Outcome.Result = result;
     return this.Outcome;
 }
Exemplo n.º 5
0
        public void single_spec()
        {
            Animal animal = new Animal { Age = 1, Health = HealthStatus.Healthy, Type = AnimalType.Cow };

            var package = new IPackage() { Entity = animal };

            var spec = new CowSpecification();

            Outcome outcome = spec.IsSatisfiedBy(package);

            Assert.IsTrue(outcome.Result);
        }
Exemplo n.º 6
0
        public Outcome IsSatisfiedBy(IPackage Package)
        {
            IsSatisfiedBySpecifications(Package);

            if (Workflow.Condition == "Or")
            {
                if (Workflow.Outcomes.Exists(x => x.Result))
                {
                    Outcome.Result = true;
                }
            }
            else if (Workflow.Condition == "Not")
            {
                Outcome.Result = !Outcome.Result;
            }
            else if (Workflow.Outcomes.Exists(x => x.Result == false))
            {
                Outcome.Result = false;
            }

            return this.Outcome;
        }
Exemplo n.º 7
0
        public void workflow_single_spec()
        {
            Animal animal = new Animal { Age = 1, Health = HealthStatus.Healthy, Type = AnimalType.Cow };
            var package = new IPackage() { Entity = animal };

            Workflow parentWorkflow = new Workflow();

            Workflow childworkflow = new Workflow();
            childworkflow.Specification = "Processor.CowSpecification";
            childworkflow.Condition = "And";

            parentWorkflow.Workflows.Add(childworkflow);

            var spec = new WorkflowSpecification();
            spec.Workflow.Workflows.Add(parentWorkflow);

            Outcome outcome = spec.IsSatisfiedBy(package);

            TraceWorkflow(parentWorkflow);

            Assert.IsTrue(outcome.Result);
        }