Exemplo n.º 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);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }