Esempio n. 1
0
        private IEnumerable <FieldConverter> GenerateConverters(QueryContext context)
        {
            if (!context.IsFrontendClient)
            {
                yield return(FieldConverters.ExcludeHidden());

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

            yield return(FieldConverters.ExcludeChangedTypes());

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

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

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

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

                if (context.Languages?.Any() == true)
                {
                    yield return(FieldConverters.FilterLanguages(context.App.LanguagesConfig, context.Languages));
                }

                if (context.AssetUrlsToResolve?.Any() == true)
                {
                    yield return(FieldConverters.ResolveAssetUrls(context.AssetUrlsToResolve, assetUrlGenerator));
                }
            }
        }
Esempio n. 2
0
        private IEnumerable<FieldConverter> GenerateConverters(QueryContext context, bool checkType)
        {
            if (!context.IsFrontendClient)
            {
                yield return FieldConverters.ExcludeHidden();
            }

            if (checkType)
            {
                yield return FieldConverters.ExcludeChangedTypes();
            }

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

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

                if (context.Languages?.Any() == true)
                {
                    yield return FieldConverters.FilterLanguages(context.App.LanguagesConfig, context.Languages);
                }
            }
        }
Esempio n. 3
0
        public void Should_return_same_values_if_resolving_invariant_from_language_field()
        {
            var source = new ContentFieldData();

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, stringLanguageField);

            Assert.Same(source, result);
        }
        public void Should_not_resolve_invariant_if_not_found()
        {
            var field = Fields.String(1, "string", Partitioning.Language);

            var source = new ContentFieldData();

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, field);

            Assert.Same(source, result);
        }
Esempio n. 5
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)));
                }
            }
        }
Esempio n. 6
0
        public void Should_resolve_invariant_and_resolve_invariant_from_first_language()
        {
            var source =
                new ContentFieldData()
                .AddValue("de", "DE")
                .AddValue("it", "IT");

            var expected =
                new ContentFieldData()
                .AddValue("iv", "DE");

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, stringInvariantField);

            Assert.Equal(expected, result);
        }
Esempio n. 7
0
        public void Should_resolve_invariant_and_use_direct_value()
        {
            var source =
                new ContentFieldData()
                .AddValue("iv", "A")
                .AddValue("it", "B");

            var expected =
                new ContentFieldData()
                .AddValue("iv", "A");

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, stringInvariantField);

            Assert.Equal(expected, result);
        }
        public void Should_resolve_invariant()
        {
            var field = Fields.String(1, "string", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddInvariant("A");

            var expected =
                new ContentFieldData()
                .AddInvariant("A");

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, field);

            Assert.Equal(expected, result);
        }
        public void Should_resolve_invariant_from_first_language()
        {
            var field = Fields.String(1, "string", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddLocalized("de", "DE")
                .AddLocalized("it", "IT");

            var expected =
                new ContentFieldData()
                .AddInvariant("DE");

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, field);

            Assert.Equal(expected, result);
        }
Esempio n. 10
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));
                }
            }
        }
Esempio n. 11
0
        public void Should_resolve_invariant_and_resolve_invariant_from_master_language()
        {
            var field = Fields.String(1, "string", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddValue("de", "DE")
                .AddValue("en", "EN");

            var expected =
                new ContentFieldData()
                .AddValue("iv", "EN");

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, field);

            Assert.Equal(expected, result);
        }
Esempio n. 12
0
        public void Should_resolve_invariant_from_master_language(IJsonValue?value)
        {
            var field = Fields.String(1, "string", Partitioning.Invariant);

            var source =
                new ContentFieldData()
                .AddLocalized("de", "DE")
                .AddLocalized("en", "EN");

            if (value != JsonValue.False)
            {
                source[InvariantPartitioning.Key] = value !;
            }

            var expected =
                new ContentFieldData()
                .AddInvariant("EN");

            var result = FieldConverters.ResolveInvariant(languagesConfig)(source, field);

            Assert.Equal(expected, result);
        }