Example #1
0
        public void Undefined_Event_Returns_Unsuccessful_Result()
        {
            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "StateA",
                    events:
                    new List <Event>()
                {
                    new Event(name: "EventA")
                }
                    )
            }
                );

            var flowInstance = new FlowInstance(
                currentState: "StateA",
                flowDefinition: flowDefinition
                );

            SendEventResult result = flowInstance.SendEvent("EventB");

            Assert.AreEqual(false, result.Succeeded);
        }
Example #2
0
        public void There_Should_Be_No_Action_Log_If_No_Action_Executed()
        {
            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "State1",
                    events:
                    new List <Event>()
                {
                    new Event(name: "Event1")
                }
                    )
            }
                );

            var flowInstance = new FlowInstance(
                currentState: "State1",
                flowDefinition: flowDefinition
                );

            {
            };

            var result = flowInstance.SendEvent("Event1");

            Assert.IsFalse(result.CreatedLogs.Any(cl => cl.LogType == "ActionLog"));
        }
Example #3
0
        public void Event_Changes_Flow_Instances_State_2()
        {
            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "StateA",
                    events:
                    new List <Event>()
                {
                    new Event(
                        name: "EventA",
                        destinationState: "StateB"
                        )
                }
                    ),
                new State(name: "StateB")
            }
                );

            var flowInstance = new FlowInstance(
                currentState: "StateA",
                flowDefinition: flowDefinition
                );

            SendEventResult result = flowInstance.SendEvent("EventA");

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual("StateB", flowInstance.CurrentState);
        }
Example #4
0
        public void Action_Execution_Creates_Logs()
        {
            var mockAction = new Mock <IAction>();

            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "State1",
                    events:
                    new List <Event>()
                {
                    new Event(
                        name: "Event1",
                        actions: new List <IAction>()
                    {
                        mockAction.Object
                    }
                        )
                }
                    )
            }
                );

            var flowInstance = new FlowInstance(
                currentState: "State1",
                flowDefinition: flowDefinition
                );


            var result = flowInstance.SendEvent("Event1");

            Assert.IsTrue(result.CreatedLogs.Any(cl => cl.LogType == "Action_PostExecution"));
        }
Example #5
0
        public void Event_Triggers_Action()
        {
            var mockAction = new Mock <IAction>();

            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "State1",
                    events:
                    new List <Event>()
                {
                    new Event(
                        name: "Event1",
                        actions: new List <IAction>()
                    {
                        mockAction.Object
                    }
                        )
                }
                    )
            }
                );

            var flowInstance = new FlowInstance(
                currentState: "State1",
                flowDefinition: flowDefinition
                );

            var result = flowInstance.SendEvent("Event1");

            mockAction.Verify(action => action.Execute());
        }
Example #6
0
        public void Event_Does_Not_Change_The_State()
        {
            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "State1",
                    events:
                    new List <Event>()
                {
                    new Event(name: "Event1")
                }
                    )
            }

                );

            var flowInstance = new FlowInstance(
                currentState: "State1",
                flowDefinition: flowDefinition
                );

            var result = flowInstance.SendEvent("Event1");

            Assert.AreEqual("State1", flowInstance.CurrentState);
        }
Example #7
0
        public void Action_Can_Read_Flow_Data()
        {
            string testText = "bebek";
            int    testInt  = 1;

            var flowDataReadingAction = new FlowDataReadingFakeAction();

            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "State1",
                    events:
                    new List <Event>()
                {
                    new Event(
                        name: "Event1",
                        actions: new List <IAction>()
                    {
                        flowDataReadingAction
                    }
                        )
                }
                    )
            }
                );

            dynamic flowData = new ExpandoObject();


            flowData.SomeFlowData    = testText;;
            flowData.SomeFlowDataInt = testInt;

            var flowInstance = new FlowInstance(
                currentState: "State1",
                flowDefinition: flowDefinition,
                flowData: flowData
                );

            var result = flowInstance.SendEvent("Event1");

            Assert.AreEqual(testText, flowDataReadingAction.TestingField);
            Assert.AreEqual(testInt, flowDataReadingAction.TestingFieldInt);
        }
Example #8
0
        public void Action_Can_Write_Flow_Data()
        {
            string stringTestData = "stringTestData";
            int    intTestData    = 54;

            var flowDataWritingFakeAction = new FlowDataWritingFakeAction()
            {
                TestingFieldInt = intTestData,
                TestingField    = stringTestData
            };

            var flowDefinition = new FlowDefinition(
                states: new List <State>()
            {
                new State(
                    name: "State1",
                    events:
                    new List <Event>()
                {
                    new Event(
                        name: "Event1",
                        actions: new List <IAction>()
                    {
                        flowDataWritingFakeAction
                    }
                        )
                }
                    )
            }
                );

            dynamic flowData = new ExpandoObject();

            flowData.SomeFlowData    = null as string;
            flowData.SomeFlowDataInt = 0;

            var flowInstance = new FlowInstance(flowDefinition, "State1", flowData: flowData);

            var sendEventResult = flowInstance.SendEvent("Event1");

            Assert.AreEqual(stringTestData, flowData.SomeFlowData);
            Assert.AreEqual(intTestData, flowData.SomeFlowDataInt);
        }