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)); } } }
public void Should_convert_name_to_name() { var field = Fields.Array(1, "1", Partitioning.Invariant, Fields.Number(1, "field1"), Fields.Number(2, "field2").Hide()); var input = new ContentFieldData() .AddJsonValue( JsonValue.Array( JsonValue.Object() .Add("field1", 100) .Add("field2", 200) .Add("invalid", 300))); var actual = FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden())(input, field); var expected = new ContentFieldData() .AddJsonValue( JsonValue.Array( JsonValue.Object() .Add("field1", 100))); Assert.Equal(expected, actual); }
public void Should_return_null_if_field_hidden() { var source = JsonValue.Create(123); var result = ValueConverters.ExcludeHidden(source, stringField.Hide()); Assert.Null(result); }
public void Should_return_unset_if_field_hidden() { var source = JsonValue.Create(123); var result = ValueConverters.ExcludeHidden()(source, stringField.Hide()); Assert.Same(Value.Unset, result); }
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)); } } }
public void Should_convert_name_to_name() { var input = new ContentFieldData() .AddValue("iv", JsonValue.Array( JsonValue.Object() .Add("field1", 100) .Add("field2", 200) .Add("invalid", 300))); var actual = FieldConverters.ForNestedName2Name(ValueConverters.ExcludeHidden())(input, arrayField); var expected = new ContentFieldData() .AddValue("iv", JsonValue.Array( JsonValue.Object() .Add("field1", 100))); Assert.Equal(expected, actual); }
public void Should_convert_id_to_id() { var input = new ContentFieldData() .AddValue("iv", JsonValue.Array( JsonValue.Object() .Add("1", 100) .Add("2", 200) .Add("99", 300))); var actual = FieldConverters.ForNestedId2Id(ValueConverters.ExcludeHidden())(input, arrayField); var expected = new ContentFieldData() .AddValue("iv", JsonValue.Array( JsonValue.Object() .Add("1", 100))); Assert.Equal(expected, actual); }
public void Should_convert_name_to_id() { var input = new ContentFieldData() .AddValue("iv", new JArray( new JObject( new JProperty("field1", 100), new JProperty("field2", 200), new JProperty("invalid", 300)))); var actual = FieldConverters.ForNestedName2Id(ValueConverters.ExcludeHidden())(input, arrayField); var expected = new ContentFieldData() .AddValue("iv", new JArray( new JObject( new JProperty("1", 100)))); Assert.Equal(expected, actual); }