Пример #1
0
        public async Task Should_add_referenced_id_as_dependency()
        {
            var ref1_1 = CreateRefContent(Guid.NewGuid(), "ref1_1", 13);
            var ref1_2 = CreateRefContent(Guid.NewGuid(), "ref1_2", 17);
            var ref2_1 = CreateRefContent(Guid.NewGuid(), "ref2_1", 23);
            var ref2_2 = CreateRefContent(Guid.NewGuid(), "ref2_2", 29);

            var source = new IContentEntity[]
            {
                CreateContent(new[] { ref1_1.Id }, new[] { ref2_1.Id }),
                CreateContent(new[] { ref1_2.Id }, new[] { ref2_2.Id })
            };

            A.CallTo(() => contentQuery.QueryAsync(A <Context> .Ignored, A <IReadOnlyList <Guid> > .That.Matches(x => x.Count == 4)))
            .Returns(ResultList.CreateFrom(4, ref1_1, ref1_2, ref2_1, ref2_2));

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

            var enriched1 = enriched.ElementAt(0);
            var enriched2 = enriched.ElementAt(1);

            Assert.Contains(refSchemaId1.Id.ToString(), enriched1.CacheDependencies);
            Assert.Contains(refSchemaId2.Id.ToString(), enriched1.CacheDependencies);

            Assert.Contains(refSchemaId1.Id.ToString(), enriched2.CacheDependencies);
            Assert.Contains(refSchemaId2.Id.ToString(), enriched2.CacheDependencies);
        }
Пример #2
0
        public async Task Should_add_app_version_and_schema_as_dependency()
        {
            var source = PublishedContent();

            A.CallTo(() => contentWorkflow.GetInfoAsync(source))
            .Returns(new StatusInfo(Status.Published, StatusColors.Published));

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

            Assert.Contains(requestContext.App.Version, result.CacheDependencies);

            Assert.Contains(schema.Id, result.CacheDependencies);
            Assert.Contains(schema.Version, result.CacheDependencies);
        }
Пример #3
0
        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);
        }
Пример #4
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);
        }
        public async Task Should_add_assets_id_and_versions_as_dependency()
        {
            var image1 = CreateAsset(Guid.NewGuid(), 1, true);
            var image2 = CreateAsset(Guid.NewGuid(), 2, true);

            var document1 = CreateAsset(Guid.NewGuid(), 3, false);
            var document2 = CreateAsset(Guid.NewGuid(), 4, false);

            var source = new IContentEntity[]
            {
                CreateContent(
                    new[] { document1.Id, image1.Id },
                    new[] { document1.Id }),
                CreateContent(
                    new[] { document1.Id },
                    new[] { document2.Id, image2.Id })
            };

            A.CallTo(() => assetQuery.QueryAsync(A <Context> .That.Matches(x => x.IsNoAssetEnrichment()), A <Q> .That.Matches(x => x.Ids.Count == 4)))
            .Returns(ResultList.CreateFrom(4, image1, image2, document1, document2));

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

            var enriched1 = enriched.ElementAt(0);

            Assert.Contains(image1.Id, enriched1.CacheDependencies);
            Assert.Contains(image1.Version, enriched1.CacheDependencies);

            var enriched2 = enriched.ElementAt(1);

            Assert.Contains(image2.Id, enriched2.CacheDependencies);
            Assert.Contains(image2.Version, enriched2.CacheDependencies);
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }