Пример #1
0
        public void Should_convert_to_id_model()
        {
            var input =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("en", "en_string")
                          .AddValue("de", "de_string"))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("iv", 3))
                .AddField("invalid",
                          new ContentFieldData()
                          .AddValue("iv", 3));

            var actual = input.ToIdModel(schema, false);

            var expected =
                new IdContentData()
                .AddField(1,
                          new ContentFieldData()
                          .AddValue("en", "en_string")
                          .AddValue("de", "de_string"))
                .AddField(2,
                          new ContentFieldData()
                          .AddValue("iv", 3));

            Assert.Equal(expected, actual);
        }
Пример #2
0
        public void SetData(Schema schema, NamedContentData newContentData)
        {
            if (newContentData != null)
            {
                var idModel = newContentData.ToIdModel(schema, true);

                var jsonString = JsonConvert.SerializeObject(idModel);

                DataObject = BsonDocument.Parse(jsonString);
                DataText   = ExtractText(idModel);

                ReferencedIds = idModel.GetReferencedIds(schema).ToList();
            }
            else
            {
                DataObject = null;
                DataText   = string.Empty;
            }
        }
Пример #3
0
        public void Should_convert_to_encoded_id_model()
        {
            var input =
                new NamedContentData()
                .AddField("json",
                          new ContentFieldData()
                          .AddValue("en", new JObject())
                          .AddValue("de", null)
                          .AddValue("it", JValue.CreateNull()));

            var actual = input.ToIdModel(schema, true);

            var expected =
                new IdContentData()
                .AddField(4,
                          new ContentFieldData()
                          .AddValue("en", "e30=")
                          .AddValue("de", null)
                          .AddValue("it", null));

            Assert.Equal(expected, actual);
        }
        public void Should_convert_to_id_model()
        {
            var input =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("en", "EN"))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("iv", 1))
                .AddField("invalid",
                          new ContentFieldData()
                          .AddValue("iv", 2));

            var actual = input.ToIdModel(schema, (data, field) => field.Name == "field2" ? null : data);

            var expected =
                new IdContentData()
                .AddField(1,
                          new ContentFieldData()
                          .AddValue("en", "EN"));

            Assert.Equal(expected, actual);
        }
Пример #5
0
 public static IdContentData ToMongoModel(this NamedContentData result, Schema schema)
 {
     return(result.ToIdModel(schema, FieldConverters.EncodeJson()));
 }