Esempio n. 1
0
        public void Should_convert_name_to_id()
        {
            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.ForNestedName2Id(ValueConverters.ExcludeHidden())(input, field);

            var expected =
                new ContentFieldData()
                .AddJsonValue(
                    JsonValue.Array(
                        JsonValue.Object()
                        .Add("1", 100)));

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
 public static IdContentData ToMongoModel(this NamedContentData result, Schema schema)
 {
     return(result.ConvertName2Id(schema,
                                  FieldConverters.ForValues(
                                      ValueConverters.EncodeJson()),
                                  FieldConverters.ForNestedName2Id(
                                      ValueConverters.EncodeJson())));
 }
Esempio n. 3
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))
            };
        }
Esempio n. 4
0
        public void Should_convert_name_to_id()
        {
            var input =
                new ContentFieldData()
                .AddValue("iv",
                          JsonValue.Array(
                              JsonValue.Object()
                              .Add("field1", 100)
                              .Add("field2", 200)
                              .Add("invalid", 300)));

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

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

            Assert.Equal(expected, actual);
        }