public async Task Should_reset_counter_with_callback()
        {
            var appId = DomainId.NewGuid();

            A.CallTo(() => grainFactory.GetGrain <ICounterGrain>(appId.ToString(), null))
            .Returns(counter);

            A.CallTo(() => counter.ResetAsync("my", 4))
            .Returns(3);

            const string script = @"
                resetCounterV2('my', function(result) {
                    complete(result);
                }, 4);
            ";

            var vars = new ScriptVars
            {
                ["appId"] = appId
            };

            var result = (await sut.ExecuteAsync(vars, script)).ToString();

            Assert.Equal("3", result);
        }
Esempio n. 2
0
        public async Task ExecuteAsync_should_catch_script_syntax_errors()
        {
            const string script = @"
                invalid()
            ";

            await Assert.ThrowsAsync <ValidationException>(() => sut.ExecuteAsync(new ScriptVars(), script));
        }
        public async Task Should_throw_validation_exception_when_calling_reject()
        {
            const string script = @"
                reject()
            ";

            var ex = await Assert.ThrowsAsync <ValidationException>(() => sut.ExecuteAsync(new ScriptVars(), script));

            Assert.Empty(ex.Errors);
        }
Esempio n. 4
0
        public async Task Should_resolve_reference()
        {
            var(vars, _) = SetupReferenceVars(1);

            var expected = @"
                Text: Hello 1 World 1
            ";

            var script = @"
                getReference(data.references.iv[0], function (references) {
                    var result1 = `Text: ${references[0].data.field1.iv} ${references[0].data.field2.iv}`;

                    complete(`${result1}`);
                })";

            var result = (await sut.ExecuteAsync(vars, script)).ToString();

            Assert.Equal(Cleanup(expected), Cleanup(result));
        }
Esempio n. 5
0
        public async Task Should_resolve_asset()
        {
            var(vars, asset) = SetupAssetVars();

            var script = @"
                getAsset(data.assets.iv[0], function (assets) {
                    var result1 = `Text: ${assets[0].fileName} ${assets[0].id}`;

                    complete(`${result1}`);
                });";

            var expected = $@"
                Text: {asset.FileName} {asset.Id}
            ";

            var result = (await sut.ExecuteAsync(vars, script)).ToString();

            Assert.Equal(Cleanup(expected), Cleanup(result));
        }
Esempio n. 6
0
        public async Task Should_resolve_reference()
        {
            var referenceId1 = DomainId.NewGuid();
            var reference1 = CreateReference(referenceId1, 1);

            var user = new ClaimsPrincipal();

            var data =
                new ContentData()
                    .AddField("references",
                        new ContentFieldData()
                            .AddInvariant(JsonValue.Array(referenceId1)));

            A.CallTo(() => contentQuery.QueryAsync(
                    A<Context>.That.Matches(x => x.App.Id == appId.Id && x.User == user), A<Q>.That.HasIds(referenceId1), A<CancellationToken>._))
                .Returns(ResultList.CreateFrom(1, reference1));

            var vars = new ScriptVars
            {
                ["appId"] = appId.Id,
                ["data"] = data,
                ["dataOld"] = null,
                ["user"] = user
            };

            var expected = @"
                Text: Hello 1 World 1
            ";

            var script = @"
                getReference(data.references.iv[0], function (references) {
                    var result1 = `Text: ${references[0].data.field1.iv} ${references[0].data.field2.iv}`;

                    complete(`${result1}`);
                })";

            var result = (await sut.ExecuteAsync(vars, script)).ToString();

            Assert.Equal(Cleanup(expected), Cleanup(result));
        }
        public async Task Should_resolve_asset()
        {
            var assetId1 = DomainId.NewGuid();
            var asset1   = CreateAsset(assetId1, 1);

            var user = new ClaimsPrincipal();

            var data =
                new ContentData()
                .AddField("assets",
                          new ContentFieldData()
                          .AddInvariant(JsonValue.Array(assetId1)));

            A.CallTo(() => assetQuery.QueryAsync(
                         A <Context> .That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A <Q> .That.HasIds(assetId1)))
            .Returns(ResultList.CreateFrom(1, asset1));

            var vars = new ScriptVars {
                Data = data, AppId = appId.Id, User = user
            };

            var script = @"
                getAsset(data.assets.iv[0], function (assets) {
                    var result1 = `Text: ${assets[0].fileName}`;

                    complete(`${result1}`);
                })";

            var expected = @"
                Text: file1.jpg
            ";

            var result = (await sut.ExecuteAsync(vars, script)).ToString();

            Assert.Equal(Cleanup(expected), Cleanup(result));
        }
        public async Task Should_throw_validation_exception_when_calling_reject()
        {
            const string script = @"
                reject()
            ";

            var options = new ScriptOptions
            {
                CanReject = true
            };

            var vars = new ScriptVars();

            var ex = await Assert.ThrowsAsync <ValidationException>(() => sut.ExecuteAsync(vars, script, options));

            Assert.NotEmpty(ex.Errors);
        }