Example #1
0
        public async Task Should_return_single_content_for_api_with_transform(StatusForApi request, int includeDraft, Status[] status)
        {
            var content = CreateContent(contentId);

            SetupClaims(isFrontend: false);
            SetupSchemaFound();
            SetupScripting(contentId);
            SetupContent(status, content, includeDraft == 1);

            var ctx = context.WithApiStatus(request);

            var result = await sut.FindContentAsync(ctx, schemaId.Name, contentId);

            Assert.Equal(contentTransformed, result.Data);
            Assert.Equal(content.Id, result.Id);

            A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
            .MustHaveHappened(1, Times.Exactly);
        }
Example #2
0
        public async Task Should_query_all_contents_by_id_for_api_and_transform(StatusForApi request, int includeDraft, Status[] status)
        {
            const int count = 5;

            var ids = Enumerable.Range(0, count).Select(x => Guid.NewGuid()).ToList();

            SetupClaims(isFrontend: false);
            SetupSchemaFound();
            SetupScripting(ids.ToArray());
            SetupContents(status, ids, includeDraft == 1);

            var ctx = context.WithApiStatus(request);

            var result = await sut.QueryAsync(ctx, ids);

            Assert.Equal(ids, result.Select(x => x.Id).ToList());

            A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
            .MustHaveHappened(count, Times.Exactly);
        }
Example #3
0
        public async Task Should_query_contents_by_query_for_api_and_transform(StatusForApi request, int includeDraft, Status[] status)
        {
            const int count = 5, total = 200;

            var content = CreateContent(contentId);

            SetupClaims(isFrontend: false);
            SetupSchemaFound();
            SetupScripting(contentId);
            SetupContents(status, count, total, content, inDraft: false, includeDraft == 1);

            var ctx = context.WithApiStatus(request);

            var result = await sut.QueryAsync(ctx, schemaId.Name, Q.Empty);

            Assert.Equal(contentData, result[0].Data);
            Assert.Equal(contentId, result[0].Id);

            Assert.Equal(total, result.Total);

            A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
            .MustHaveHappened(count, Times.Exactly);
        }
Example #4
0
 public QueryContext WithApiStatus(StatusForApi status)
 {
     return(Clone(c => c.ApiStatus = status));
 }