Exemplo n.º 1
0
        public async Task WorkflowEngine_TriggerAsyncWithEntityWorkflowInstanceAndSameWorkflowVariable_ReturnsTriggerResult()
        {
            // Arrange
            var instance = new LightSwitcher();

            this.Context.Switchers.Add(instance);

            var workflow = Workflow.Create(instance.Id, instance.Type, instance.State, "tester");
            var variable = new LightSwitcherWorkflowVariable {
                CanSwitch = true
            };

            workflow.AddVariable(variable);

            this.Context.Workflows.Add(workflow);
            await this.Context.SaveChangesAsync();

            variable.CanSwitch = false;
            var param = new TriggerParam("SwitchOn", instance)
                        .AddVariableWithKey <LightSwitcherWorkflowVariable>(variable);;

            // Act
            var triggerResult = await this.WorkflowEngine.TriggerAsync(param);

            // Assert
            Assert.IsNotNull(triggerResult);
            Assert.IsFalse(triggerResult.HasErrors);
            Assert.AreEqual(instance.State, triggerResult.CurrentState);
            Assert.AreEqual("On", triggerResult.CurrentState);

            Assert.IsTrue(param.HasVariables);

            Assert.AreEqual(1, workflow.WorkflowHistories.Count());

            var workflowVariable       = workflow.WorkflowVariables.First();
            var type                   = KeyBuilder.FromKey(workflowVariable.Type);
            var myDeserializedVariable = JsonConvert.DeserializeObject(workflowVariable.Content, type);

            Assert.IsInstanceOfType(myDeserializedVariable, typeof(LightSwitcherWorkflowVariable));

            var variableInstance = myDeserializedVariable as LightSwitcherWorkflowVariable;

            Assert.IsFalse(variableInstance.CanSwitch);
        }