Beispiel #1
0
        public void Should_not_convert_asset_ids_to_urls_when_fields_is_null()
        {
            var field = Fields.Assets(1, "assets", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddJsonValue(JsonValue.Array(id1, id2));

            var expected =
                new ContentFieldData()
                .AddJsonValue(JsonValue.Array(id1, id2));

            var result = FieldConverters.ResolveAssetUrls(null, urlGenerato)(source, field);

            Assert.Equal(expected, result);
        }
        public void Should_not_convert_asset_ids_to_urls_when_field_does_not_match()
        {
            var field = Fields.Assets(1, "assets", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddJsonValue(JsonValue.Array("1", "2"));

            var expected =
                new ContentFieldData()
                .AddJsonValue(JsonValue.Array("1", "2"));

            var result = FieldConverters.ResolveAssetUrls(new HashSet <string>(new[] { "other" }), assetUrlGenerator)(source, field);

            Assert.Equal(expected, result);
        }
Beispiel #3
0
        public void Should_convert_asset_ids_to_urls_for_wildcard_fields()
        {
            var field = Fields.Assets(1, "assets", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddJsonValue(JsonValue.Array(id1, id2));

            var expected =
                new ContentFieldData()
                .AddJsonValue(JsonValue.Array($"url/to/{id1}", $"url/to/{id2}"));

            var result = FieldConverters.ResolveAssetUrls(new HashSet <string>(new[] { "*" }), urlGenerato)(source, field);

            Assert.Equal(expected, result);
        }
        public void Should_convert_asset_ids_to_urls()
        {
            var field = Fields.Assets(1, "assets", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddValue("iv", JsonValue.Array("1", "2"));

            var expected =
                new ContentFieldData()
                .AddValue("iv", JsonValue.Array("url/to/1", "url/to/2"));

            var result = FieldConverters.ResolveAssetUrls(new HashSet <string>(new[] { "assets" }), assetUrlGenerator)(source, field);

            Assert.Equal(expected, result);
        }
Beispiel #5
0
        private IEnumerable <FieldConverter> GenerateConverters(Context context, ValueConverter?cleanReferences)
        {
            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ExcludeHidden());

                yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden()));
            }

            yield return(FieldConverters.ExcludeChangedTypes());

            yield return(FieldConverters.ForNestedName2Name(ValueConverters.ExcludeChangedTypes()));

            if (cleanReferences != null)
            {
                yield return(FieldConverters.ForValues(cleanReferences));

                yield return(FieldConverters.ForNestedName2Name(cleanReferences));
            }

            yield return(FieldConverters.ResolveInvariant(context.App.LanguagesConfig));

            yield return(FieldConverters.ResolveLanguages(context.App.LanguagesConfig));

            if (!context.IsFrontendClient)
            {
                if (context.ShouldResolveLanguages())
                {
                    yield return(FieldConverters.ResolveFallbackLanguages(context.App.LanguagesConfig));
                }

                var languages = context.Languages();

                if (languages.Any())
                {
                    yield return(FieldConverters.FilterLanguages(context.App.LanguagesConfig, languages));
                }

                var assetUrls = context.AssetUrls();

                if (assetUrls.Any())
                {
                    yield return(FieldConverters.ResolveAssetUrls(assetUrls.ToList(), assetUrlGenerator));
                }
            }
        }