public ContentEnricherAssetsTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId, Language.DE));

            var schemaDef =
                new Schema(schemaId.Name)
                .AddAssets(1, "asset1", Partitioning.Invariant, new AssetsFieldProperties
            {
                ResolveImage = true,
                MinItems     = 2,
                MaxItems     = 3
            })
                .AddAssets(2, "asset2", Partitioning.Language, new AssetsFieldProperties
            {
                ResolveImage = true,
                MinItems     = 1,
                MaxItems     = 1
            })
                .ConfigureFieldsInLists("asset1", "asset2");

            A.CallTo(() => assetUrlGenerator.GenerateUrl(A <string> .Ignored))
            .ReturnsLazily(new Func <string, string>(id => $"url/to/{id}"));

            void SetupSchema(NamedId <Guid> id, Schema def)
            {
                var schemaEntity = Mocks.Schema(appId, id, def);

                A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, id.Id.ToString()))
                .Returns(schemaEntity);
            }

            SetupSchema(schemaId, schemaDef);

            sut = new ContentEnricher(assetQuery, assetUrlGenerator, new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
        public async Task Should_not_clone_data_when_not_requested()
        {
            var source = CreateContent(new ContentData());

            var sut = new ContentEnricher(Enumerable.Empty <IContentEnricherStep>(), new Lazy <IContentQueryService>(() => contentQuery));

            var result = await sut.EnrichAsync(source, false, requestContext);

            Assert.Same(source.Data, result.Data);
        }
Beispiel #3
0
        public async Task Should_not_clone_data_if_not_requested()
        {
            var source = CreateContent(new ContentData());

            var sut = new ContentEnricher(Enumerable.Empty <IContentEnricherStep>(), appProvider);

            var result = await sut.EnrichAsync(source, false, requestContext, ct);

            Assert.Same(source.Data, result.Data);
        }
Beispiel #4
0
        public ContentEnricherTests()
        {
            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema = Mocks.Schema(appId, schemaId);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(A <Context> .Ignored, schemaId.Id.ToString()))
            .Returns(schema);

            sut = new ContentEnricher(assetQuery, assetUrlGenerator, new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
Beispiel #5
0
        public ContentEnricherReferencesTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId, Language.DE));

            var refSchemaDef =
                new Schema("my-ref")
                .AddString(1, "name", Partitioning.Invariant,
                           new StringFieldProperties {
                IsReferenceField = true
            })
                .AddNumber(2, "number", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsReferenceField = true
            });

            var schemaDef =
                new Schema(schemaId.Name)
                .AddReferences(1, "ref1", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                IsListField      = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId1.Id
            })
                .AddReferences(2, "ref2", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                IsListField      = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId2.Id
            });

            void SetupSchema(NamedId <Guid> id, Schema def)
            {
                var schemaEntity = Mocks.Schema(appId, id, def);

                A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, id.Id.ToString()))
                .Returns(schemaEntity);
            }

            SetupSchema(schemaId, schemaDef);
            SetupSchema(refSchemaId1, refSchemaDef);
            SetupSchema(refSchemaId2, refSchemaDef);

            sut = new ContentEnricher(new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
Beispiel #6
0
        public async Task Should_provide_and_cache_schema()
        {
            var source = CreateContent();

            var step1 = new ResolveSchema();
            var step2 = new ResolveSchema();

            var sut = new ContentEnricher(new[] { step1, step2 }, new Lazy <IContentQueryService>(() => contentQuery));

            await sut.EnrichAsync(source, requestContext);

            Assert.Same(schema, step1.Schema);
            Assert.Same(schema, step1.Schema);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, schemaId.Id.ToString()))
            .MustHaveHappenedOnceExactly();
        }
Beispiel #7
0
        public async Task Should_invoke_steps()
        {
            var source = CreateContent();

            var step1 = A.Fake <IContentEnricherStep>();
            var step2 = A.Fake <IContentEnricherStep>();

            var sut = new ContentEnricher(new[] { step1, step2 }, new Lazy <IContentQueryService>(() => contentQuery));

            await sut.EnrichAsync(source, requestContext);

            A.CallTo(() => step1.EnrichAsync(requestContext, A <IEnumerable <ContentEntity> > .Ignored, A <ProvideSchema> .Ignored))
            .MustHaveHappened();

            A.CallTo(() => step2.EnrichAsync(requestContext, A <IEnumerable <ContentEntity> > .Ignored, A <ProvideSchema> .Ignored))
            .MustHaveHappened();
        }
Beispiel #8
0
        public async Task Should_provide_and_cache_schema()
        {
            var source = CreateContent();

            var step1 = new ResolveSchema();
            var step2 = new ResolveSchema();

            var sut = new ContentEnricher(new[] { step1, step2 }, appProvider);

            await sut.EnrichAsync(source, false, requestContext, ct);

            Assert.Same(schema, step1.Schema);
            Assert.Same(schema, step1.Schema);

            A.CallTo(() => appProvider.GetSchemaAsync(appId.Id, schemaId.Id, false, ct))
            .MustHaveHappenedOnceExactly();
        }
Beispiel #9
0
        public async Task Should_only_invoke_pre_enrich_for_empty_results()
        {
            var source = new IContentEntity[0];

            var step1 = A.Fake <IContentEnricherStep>();
            var step2 = A.Fake <IContentEnricherStep>();

            var sut = new ContentEnricher(new[] { step1, step2 }, new Lazy <IContentQueryService>(() => contentQuery));

            await sut.EnrichAsync(source, requestContext);

            A.CallTo(() => step1.EnrichAsync(requestContext))
            .MustHaveHappened();

            A.CallTo(() => step2.EnrichAsync(requestContext))
            .MustHaveHappened();

            A.CallTo(() => step1.EnrichAsync(requestContext, A <IEnumerable <ContentEntity> > ._, A <ProvideSchema> ._))
            .MustNotHaveHappened();

            A.CallTo(() => step2.EnrichAsync(requestContext, A <IEnumerable <ContentEntity> > ._, A <ProvideSchema> ._))
            .MustNotHaveHappened();
        }
Beispiel #10
0
        public async Task Should_invoke_steps()
        {
            var source = CreateContent();

            var step1 = A.Fake <IContentEnricherStep>();
            var step2 = A.Fake <IContentEnricherStep>();

            var sut = new ContentEnricher(new[] { step1, step2 }, appProvider);

            await sut.EnrichAsync(source, false, requestContext, ct);

            A.CallTo(() => step1.EnrichAsync(requestContext, ct))
            .MustHaveHappened();

            A.CallTo(() => step2.EnrichAsync(requestContext, ct))
            .MustHaveHappened();

            A.CallTo(() => step1.EnrichAsync(requestContext, A <IEnumerable <ContentEntity> > ._, A <ProvideSchema> ._, ct))
            .MustHaveHappened();

            A.CallTo(() => step2.EnrichAsync(requestContext, A <IEnumerable <ContentEntity> > ._, A <ProvideSchema> ._, ct))
            .MustHaveHappened();
        }