コード例 #1
0
        public async Task Test1()
        {
            var serviceCollcetion = new ServiceCollection();

            var script = $"var t = api.Call(\"{ProductGroupJsWorker.WorkerName}\"," + " \"AddProductToGroup\", { ProductGroupId: \"d8c8cf9b-1d9b-4199-a85e-615edd64b4d7\", ProductId: 1 });";

            script += "\n console.log('Result', t)";

            new JsExecutorBuilder(serviceCollcetion)
            .AddJsWorker(new ProductGroupJsWorker())
            .Build();

            var srvProvider = serviceCollcetion.BuildServiceProvider();

            var executor = srvProvider.GetRequiredService <JsExecutor>();

            var result = await executor.RunScriptDetaiiled(script);

            Assert.IsTrue(result.IsSucceeded);
            Assert.AreEqual(1, result.ConsoleLogs.Count);

            var log = result.ConsoleLogs.First();

            var json = ZooSerializer.Serialize(ProductGroupJsWorker.AddProductToGroup(null));

            Assert.AreEqual(log.SerializedVariables.Last().DataJson, json);
        }
コード例 #2
0
        public async Task Test2()
        {
            var script = $"var t = api.Call(\"{ProductGroupJsWorker.WorkerName}\", \"{ProductGroupJsWorker.GetArrayName}\");";

            script += "console.log(t);\n";
            script += "console.log(t.length);\n";
            script += "for(var i = 0; i < t.length; i++) {";

            script += "\n console.log('Result', i, t[i]); \n}";

            var serviceCollection = new ServiceCollection();

            new JsExecutorBuilder(serviceCollection)
            .AddJsWorker(new ProductGroupJsWorker())
            .Build();

            var executor = serviceCollection.BuildServiceProvider().GetRequiredService <JsExecutor>();

            var result = await executor.RunScriptDetaiiled(script);

            Assert.IsTrue(result.IsSucceeded);
            Assert.AreEqual(ProductGroupJsWorker.GetArray().Length + 2, result.ConsoleLogs.Count);
        }