Exemplo n.º 1
0
        public async Task Should_query_contents_by_query_from_repository_and_transform(int count, int total, bool isFrontend, bool archive, params Status[] status)
        {
            var contentId = Guid.NewGuid();
            var content   = CreateContent(contentId);

            SetupClaims(isFrontend);
            SetupScripting(contentId);

            A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId, false))
            .Returns(schema);

            A.CallTo(() => contentRepository.QueryAsync(app, schema, A <Status[]> .That.IsSameSequenceAs(status), A <ODataUriParser> .Ignored))
            .Returns(ResultList.Create(total, Enumerable.Repeat(content, count)));

            var result = await sut.QueryAsync(context.WithSchemaId(schemaId).WithArchived(archive), Query.Empty);

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

            Assert.Equal(total, result.Total);

            if (!isFrontend)
            {
                A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
                .MustHaveHappened(Repeated.Exactly.Times(count));
            }
            else
            {
                A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
                .MustNotHaveHappened();
            }
        }
Exemplo n.º 2
0
        private async Task TestManyRequest(bool isFrontend, bool archive, params Status[] status)
        {
            SetupClaims(isFrontend);

            SetupFakeWithOdataQuery(status);
            SetupFakeWithScripting();

            var result = await sut.QueryAsync(app, schemaId.ToString(), user, archive, string.Empty);

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

            Assert.Equal(123, result.Total);

            if (!isFrontend)
            {
                A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
                .MustHaveHappened(Repeated.Exactly.Times(result.Count));
            }
            else
            {
                A.CallTo(() => scriptEngine.Transform(A <ScriptContext> .Ignored, A <string> .Ignored))
                .MustNotHaveHappened();
            }
        }
Exemplo n.º 3
0
        public async Task Should_throw_for_query_if_no_permission()
        {
            SetupClaims(false, false);
            SetupSchema();

            var ctx = context;

            await Assert.ThrowsAsync <DomainForbiddenException>(() => sut.QueryAsync(ctx, schemaId.Name, Q.Empty));
        }
        private async Task TestManyRequest(bool isFrontend, bool archive, params Status[] status)
        {
            SetupClaims(isFrontend);

            SetupFakeWithOdataQuery(status);
            SetupFakeWithScripting();

            var result = await sut.QueryAsync(app, schemaId.ToString(), user, archive, string.Empty);

            Assert.Equal(schema, result.Schema);

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

            Assert.Equal(123, result.Contents.Total);
        }
Exemplo n.º 5
0
        public async Task Should_apply_default_page_size()
        {
            SetupClaims(isFrontend: false);
            SetupSchemaFound();

            var query = Q.Empty;

            await sut.QueryAsync(context, schemaId.Name, query);

            A.CallTo(() => contentRepository.QueryAsync(app, schema, A <Status[]> .That.Is(Status.Published), false, A <Query> .That.Is("Take: 30; Sort: lastModified Descending"), false))
            .MustHaveHappened();
        }