Example #1
0
        public async Task Should_not_call_script_engine_when_no_script_configured()
        {
            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            var content = new ContentEntity {
                SchemaId = schemaId
            };

            await sut.EnrichAsync(ctx, new[] { content }, schemaProvider);

            A.CallTo(() => scriptEngine.ExecuteAndTransformAsync(A <ScriptVars> ._, A <string> ._))
            .MustNotHaveHappened();
        }
        public async Task Should_not_call_script_engine_if_no_script_configured()
        {
            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            var content = new ContentEntity {
                SchemaId = schemaId
            };

            await sut.EnrichAsync(ctx, new[] { content }, schemaProvider, default);

            A.CallTo(() => scriptEngine.TransformAsync(A <ScriptVars> ._, A <string> ._, ScriptOptions(), A <CancellationToken> ._))
            .MustNotHaveHappened();
        }
Example #3
0
        public async Task Should_make_test_with_pre_query_script()
        {
            var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId));

            var(provider, id) = CreateSchema(
                query: @"
                    ctx.data.test = { iv: ctx.custom };
                    replace()",
                queryPre: "ctx.custom = 123;");

            var content = new ContentEntity {
                Data = new ContentData(), SchemaId = id
            };

            var realScriptEngine =
                new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())),
                                     Options.Create(new JintScriptOptions
            {
                TimeoutScript    = TimeSpan.FromSeconds(20),
                TimeoutExecution = TimeSpan.FromSeconds(100)
            }));

            var sut2 = new ScriptContent(realScriptEngine);

            await sut2.EnrichAsync(ctx, new[] { content }, provider, default);

            Assert.Equal(JsonValue.Create(123), content.Data["test"] !["iv"]);