Exemplo n.º 1
0
        public void Should_convert_id_to_name()
        {
            var field =
                Fields.Array(1, "1", Partitioning.Invariant,
                             Fields.Number(1, "field1"),
                             Fields.Number(2, "field2").Hide());

            var input =
                new ContentFieldData()
                .AddValue("iv",
                          JsonValue.Array(
                              JsonValue.Object()
                              .Add("1", 100)
                              .Add("2", 200)
                              .Add("99", 300)));

            var actual = FieldConverters.ForNestedId2Name(ValueConverters.ExcludeHidden())(input, field);

            var expected =
                new ContentFieldData()
                .AddValue("iv",
                          JsonValue.Array(
                              JsonValue.Object()
                              .Add("field1", 100)));

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
 public static NamedContentData FromMongoModel(this IdContentData result, Schema schema, IJsonSerializer serializer)
 {
     return(result.ConvertId2Name(schema,
                                  FieldConverters.ForValues(
                                      ValueConverters.DecodeJson(serializer)),
                                  FieldConverters.ForNestedId2Name(
                                      ValueConverters.DecodeJson(serializer))));
 }
Exemplo n.º 3
0
 public static NamedContentData FromMongoModel(this IdContentData result, Schema schema, List <Guid> deletedIds)
 {
     return(result.ConvertId2Name(schema,
                                  FieldConverters.ForValues(
                                      ValueConverters.DecodeJson(),
                                      ValueReferencesConverter.CleanReferences(deletedIds)),
                                  FieldConverters.ForNestedId2Name(
                                      ValueConverters.DecodeJson(),
                                      ValueReferencesConverter.CleanReferences(deletedIds))));
 }
Exemplo n.º 4
0
        public DataConverter(IJsonSerializer serializer)
        {
            decodeJsonConverters = new[]
            {
                FieldConverters.ForValues(
                    ValueConverters.DecodeJson(serializer)),
                FieldConverters.ForNestedId2Name(
                    ValueConverters.DecodeJson(serializer))
            };

            encodeJsonConverters = new[]
            {
                FieldConverters.ForValues(
                    ValueConverters.EncodeJson(serializer)),
                FieldConverters.ForNestedName2Id(
                    ValueConverters.EncodeJson(serializer))
            };
        }
Exemplo n.º 5
0
        public void Should_convert_id_to_name()
        {
            var input =
                new ContentFieldData()
                .AddValue("iv",
                          JsonValue.Array(
                              JsonValue.Object()
                              .Add("1", 100)
                              .Add("2", 200)
                              .Add("99", 300)));

            var actual = FieldConverters.ForNestedId2Name(ValueConverters.ExcludeHidden())(input, arrayField);

            var expected =
                new ContentFieldData()
                .AddValue("iv",
                          JsonValue.Array(
                              JsonValue.Object()
                              .Add("field1", 100)));

            Assert.Equal(expected, actual);
        }