示例#1
0
        public async Task ForcedParameterCustomType()
        {
            IScriptParser parser = new ScriptParser();

            parser.Types.AddType <Transition>();

            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name    = "input",
                        Type    = "transition[]",
                        Default = "[{\"Log\": \"\\\"Hello there\\\"\"}]"
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object>();
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            Transition[] input = variables["input"] as Transition[];
            Assert.NotNull(input);
            Assert.AreEqual(1, input.Length);
            Assert.AreEqual("\"Hello there\"", input[0].Log);
        }
示例#2
0
        public async Task ForcedParameterComplexType()
        {
            IScriptParser parser = new ScriptParser();

            parser.Types.AddType <Campaign>();

            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name = "input",
                        Type = "campaign",
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object> {
                ["input"] = await Json.ReadAsync(typeof(StartNodeTests).Assembly.GetManifestResourceStream("ScriptService.Tests.Data.2020-10-22_campaign.json"))
            };
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            Campaign campaign = variables["input"] as Campaign;

            Assert.NotNull(campaign);
        }
示例#3
0
        public async Task ForcedParameterDefaultArray()
        {
            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name    = "input",
                        Type    = "int[]",
                        Default = "[1,2,3]"
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object>();
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            IEnumerable <int> input = variables["input"] as IEnumerable <int>;

            Assert.NotNull(input);
            Assert.That(new[] { 1, 2, 3 }.SequenceEqual(input));
        }
示例#4
0
 /*
  * Initializes the dictionary scriptable object and starts the tree's execution
  */
 public void Start()
 {
     treeDataDict = (TreeDict)ScriptableObject.CreateInstance(typeof(TreeDict));
     if (StartNode)
     {
         StartCoroutine(StartNode.Execute());
     }
 }
示例#5
0
        public async Task NoParameters()
        {
            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters(), compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object>();
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);
        }
示例#6
0
        public async Task ForcedParameterCustomTypeDeepDeserialization()
        {
            IScriptParser parser = new ScriptParser();

            parser.Types.AddType <RecursiveType>();

            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name = "input",
                        Type = "recursivetype",
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object> {
                ["input"] = new Dictionary <string, object> {
                    ["Type"] = new Dictionary <string, object> {
                        ["Name"]  = "Peter",
                        ["Array"] = new[] {
                            new Dictionary <string, object> {
                                ["Name"] = "Bärbel"
                            }
                        }
                    }
                }
            };
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            RecursiveType input = variables["input"] as RecursiveType;

            Assert.NotNull(input);
            Assert.NotNull(input.Type);
            Assert.NotNull(input.Type.Array);
            Assert.AreEqual("Peter", input.Type.Name);
            Assert.AreEqual(1, input.Type.Array.Length);
            Assert.AreEqual("Bärbel", input.Type.Array[0].Name);
        }
示例#7
0
        public void ForcedParameterNotProvided()
        {
            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name = "input",
                        Type = "int"
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object>();

            Assert.ThrowsAsync <WorkflowException>(() => node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None));
        }
示例#8
0
        public async Task OptionalParameter()
        {
            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => new ScriptParser().ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name    = "input",
                        Type    = "int",
                        Default = "12"
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object>();
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            Assert.That(variables.ContainsKey("input"));
            Assert.AreEqual(12, variables["input"]);
        }
示例#9
0
 public void Start()
 {
     StartNode.Execute(StartNode, null);
 }
 public void Execute(GameObject context)
 {
     Start.Execute(context);
 }