Esempio n. 1
0
        public void Should_convert_to_name_model()
        {
            var input =
                new IdContentData()
                .AddField(1,
                          new ContentFieldData()
                          .AddValue("en", "en_string")
                          .AddValue("de", "de_string"))
                .AddField(2,
                          new ContentFieldData()
                          .AddValue("iv", 3))
                .AddField(99,
                          new ContentFieldData()
                          .AddValue("iv", 3));

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

            var expected =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("en", "en_string")
                          .AddValue("de", "de_string"))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("iv", 3));

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        public IdContentData ToCleanedReferences(Schema schema, ISet <Guid> deletedReferencedIds)
        {
            var result = new IdContentData(this);

            foreach (var field in schema.Fields)
            {
                if (field is IReferenceField referenceField)
                {
                    var fieldKey  = GetKey(field);
                    var fieldData = this.GetOrDefault(fieldKey);

                    if (fieldData == null)
                    {
                        continue;
                    }

                    foreach (var partitionValue in fieldData.Where(x => !x.Value.IsNull()).ToList())
                    {
                        var newValue = referenceField.RemoveDeletedReferences(partitionValue.Value, deletedReferencedIds);

                        fieldData[partitionValue.Key] = newValue;
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        public void Should_convert_to_encoded_name_model()
        {
            var input =
                new IdContentData()
                .AddField(4,
                          new ContentFieldData()
                          .AddValue("en", "e30=")
                          .AddValue("de", null)
                          .AddValue("it", null));

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

            Assert.True(actual["json"]["en"] is JObject);
        }
Esempio n. 4
0
        public void Should_cleanup_deleted_ids()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

            var input =
                new IdContentData()
                .AddField(5,
                          new ContentFieldData()
                          .AddValue("iv", new JArray(id1.ToString(), id2.ToString())));

            var actual = input.ToCleanedReferences(schema, new HashSet <Guid>(new[] { id2 }));

            var cleanedValue = (JArray)actual[5]["iv"];

            Assert.Equal(1, cleanedValue.Count);
            Assert.Equal(id1.ToString(), cleanedValue[0]);
        }
Esempio n. 5
0
        public IdContentData ToIdModel(Schema schema, bool encodeJsonField)
        {
            Guard.NotNull(schema, nameof(schema));

            var result = new IdContentData();

            foreach (var fieldValue in this)
            {
                if (!schema.FieldsByName.TryGetValue(fieldValue.Key, out var field))
                {
                    continue;
                }

                var fieldId = field.Id;

                if (encodeJsonField && field is JsonField)
                {
                    var encodedValue = new ContentFieldData();

                    foreach (var partitionValue in fieldValue.Value)
                    {
                        if (partitionValue.Value.IsNull())
                        {
                            encodedValue[partitionValue.Key] = null;
                        }
                        else
                        {
                            var value = Convert.ToBase64String(Encoding.UTF8.GetBytes(partitionValue.Value.ToString()));

                            encodedValue[partitionValue.Key] = value;
                        }
                    }

                    result[fieldId] = encodedValue;
                }
                else
                {
                    result[fieldId] = fieldValue.Value;
                }
            }

            return(result);
        }
Esempio n. 6
0
        public void Should_remove_null_values_from_id_model_when_cleaning()
        {
            var input =
                new IdContentData()
                .AddField(1, null)
                .AddField(2,
                          new ContentFieldData()
                          .AddValue("en", 2)
                          .AddValue("it", null));

            var actual = input.ToCleaned();

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

            Assert.Equal(expected, actual);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public void Should_merge_two_id_models()
        {
            var lhs =
                new IdContentData()
                .AddField(1,
                          new ContentFieldData()
                          .AddValue("iv", 1))
                .AddField(2,
                          new ContentFieldData()
                          .AddValue("de", 2));

            var rhs =
                new IdContentData()
                .AddField(2,
                          new ContentFieldData()
                          .AddValue("en", 3))
                .AddField(3,
                          new ContentFieldData()
                          .AddValue("iv", 4));

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

            var actual = lhs.MergeInto(rhs);

            Assert.Equal(expected, actual);
        }
Esempio n. 9
0
 public IdContentData MergeInto(IdContentData target)
 {
     return(Merge(this, target));
 }
Esempio n. 10
0
 public IdContentData(IdContentData copy)
     : base(copy, EqualityComparer <long> .Default)
 {
 }
Esempio n. 11
0
 public bool Equals(IdContentData other)
 {
     return(base.Equals(other));
 }
Esempio n. 12
0
 public bool Equals([AllowNull] IdContentData other)
 {
     return(base.Equals(other));
 }