Ejemplo n.º 1
0
        public void Should_convert_asset_ids_to_urls(string path)
        {
            var field = Fields.Assets(1, "assets", Partitioning.Invariant);

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

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

            var result = ValueConverters.ResolveAssetUrls(HashSet.Of(path), urlGenerator)(source, field);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 2
0
        public void Should_not_convert_nested_asset_ids_when_field_name_does_not_match(string path)
        {
            var field = Fields.Array(1, "parent", Partitioning.Invariant, Fields.Assets(11, "assets"));

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

            var expected = source;

            var result = ValueConverters.ResolveAssetUrls(HashSet.Of(path), urlGenerator)(source, field.Fields[0], field);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 3
0
        public void Should_not_convert_asset_ids_if_field_name_does_not_match(string path)
        {
            var field = Fields.Assets(1, "assets", Partitioning.Invariant);

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

            var expected = source;

            var result = ValueConverters.ResolveAssetUrls(appId, HashSet.Of(path), urlGenerator)(source, field, null);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 4
0
        private IEnumerable <FieldConverter> GenerateConverters(Context context, ValueConverter?cleanReferences)
        {
            if (!context.IsFrontendClient)
            {
                yield return(excludedHiddenField);

                yield return(excludedHiddenValue);
            }

            yield return(excludedChangedField);

            yield return(excludedChangedValue);

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

                yield return(FieldConverters.ForValues(ValueConverters.ForNested(cleanReferences)));
            }

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

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

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

                var languages = context.Languages();

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

                var assetUrls = context.AssetUrls().ToList();

                if (assetUrls.Count > 0)
                {
                    var appId = context.App.NamedId();

                    var resolveAssetUrls = ValueConverters.ResolveAssetUrls(appId, assetUrls, urlGenerator);

                    yield return(FieldConverters.ForValues(resolveAssetUrls));

                    yield return(FieldConverters.ForValues(ValueConverters.ForNested(resolveAssetUrls)));
                }
            }
        }