Exemple #1
0
        public void CanLoadMultiplePluginAssemblies()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(source);

            Console.WriteLine(filterRegistry.GetFilterNames());
            Assert.AreEqual(7, filterRegistry.GetFilterCount());
        }
Exemple #2
0
        public void CanSerializeFilterDefinitions()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";
            string outputSource = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\output.json";

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(source);
            string json = filterRegistry.SerializeFilterDefinitions();

            Assert.AreEqual(7, filterRegistry.GetFilterCount());

            Assert.IsTrue(json.Length > 0);
            WriteFile(json, outputSource);
        }
        public void CanAllowMcCoyToIssueUnfitForDuty()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RedShirtPromotion.json";
            string pluginSource = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";
            string preFilterNames = "FetchDataFilter;MorePlugins.TransporterDiagnosisFilter;ValidParticipantFilter;";
            string postFilterNames = "MorePlugins.TransporterRepairFilter;Plugins.CaptainUnfitForCommandFilter;SaveDataFilter;";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            //  Mission to beam down issue and the red shirt wants off
            var step = new Step("13", "12", "RequestPromotionForm", "",
                                    "Complete", DateTime.Now, "RedShirtGuy", "Data;RedShirtGuy",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(pluginSource);

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            //  Spock says he'll evaluate request
            Assert.AreEqual("FirstOfficerReview", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Spock";
            step.Participants = "Spock;Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);

            //  Captain Kirt denies request, but McCoy issues unfit for command
            parameters.Add("KirkInfected", true);

            step.Answer = "Deny";
            step.AnsweredBy = "Kirk";
            step.Participants = "Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            //  Medical override issued and email to Starfleet generated
            bool medicalOverride = (bool)parameters["MedicalOverride"];
            bool emailSent = (bool)parameters["StarfleetEmail"];

            Assert.IsTrue(medicalOverride);
            Assert.IsTrue(emailSent);
        }
        public void CanIssueSpecialOrdersWithPlugin()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RedShirtPromotion.json";
            string pluginSource = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";
            string preFilterNames = "FetchDataFilter;MorePlugins.TransporterDiagnosisFilter;ValidParticipantFilter;";
            string postFilterNames = "MorePlugins.TransporterRepairFilter;SaveDataFilter;";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            var step = new Step("13", "12", "RequestPromotionForm", "",
                                    "Complete", DateTime.Now, "RedShirtGuy", "Data;RedShirtGuy",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(pluginSource);

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("FirstOfficerReview", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Spock";
            step.Participants = "Spock;Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);

            //  Captain Kirt denies request, special order issued
            step.Answer = "Deny";
            step.AnsweredBy = "Kirk";
            step.Participants = "Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("Report to Shuttle Bay", step.Parameters["SpecialOrders"].ToString());
        }