Exemplo n.º 1
0
 /// <summary>
 /// Returns a IEnumerable on <see cref="IReadOnlyFieldList"/>
 /// </summary>
 /// <param name="fields"></param>
 /// <returns></returns>
 public static IEnumerable <PrimitiveField> ToEnumerable(this IReadOnlyFieldList fields)
 {
     for (int i = 0; i < fields.Count; i++)
     {
         yield return(fields[i]);
     }
 }
Exemplo n.º 2
0
        public void Verify_does_not_throw_when_id_missing()
        {
            var schema = Schema.Builder()
                         .Field <Struct>(x =>
            {
                return(x.Id("field1")
                       .Field <Primitive>(f => f.Id("fieldA").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Primitive>(f => f.Id("fieldB").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Primitive>(f => f.Id("fieldC").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Decimal>(f => f.Id("fieldD").Precision(5).Scale(2).IsNullable().Build())
                       .Build());
            })
                         .Field <Primitive>(x => x.Id("field2").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field3").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field4").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field5").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field6").IsNullable().Build())
                         .Build();

            Assert.IsTrue(schema.Fields.HasValues);
            Assert.AreEqual(6, schema.Fields.Count);

            IReadOnlyFieldList fields = schema.RemoveAll <PrimitiveField>(x => x.Id == "field7");

            Assert.AreEqual(0, fields.Count);
        }
Exemplo n.º 3
0
        public void Verify_can_remove_multiple_fields_with_same_id()
        {
            var schema = Schema.Builder()
                         .Field <Struct>(x =>
            {
                return(x.Id("field1")
                       .Field <Primitive>(f => f.Id("fieldA").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Primitive>(f => f.Id("fieldB").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Primitive>(f => f.Id("fieldC").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Decimal>(f => f.Id("fieldD").Precision(5).Scale(2).IsNullable().Build())
                       .Build());
            })
                         .Field <Primitive>(x => x.Id("field3").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field4").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field5").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field3").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field3").IsNullable().Build())
                         .Build();

            Assert.IsTrue(schema.Fields.HasValues);
            Assert.AreEqual(6, schema.Fields.Count);

            IReadOnlyFieldList fields = schema.RemoveAll <PrimitiveField>(x => x.Id == "field3");

            Assert.AreEqual(3, fields.Count);
        }
Exemplo n.º 4
0
        public bool Equals(IReadOnlyFieldList other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (_count != other.Count)
            {
                return(false);
            }

            for (int i = 0; i < other.Count; i++)
            {
                if (!Contains(other[i].Id))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
 public StructFieldImpl(string id, int index, IReadOnlyFieldList fields, bool isNullable = false)
 {
     Id         = id;
     Index      = index;
     IsNullable = isNullable;
     DataType   = SchemaDataType.Struct;
     Fields     = fields;
     HasValue   = !string.IsNullOrWhiteSpace(id);
 }
Exemplo n.º 6
0
        public void Verify_does_not_throw_when_attempting_to_access_greater_than_count_index()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsFalse(temp.TryGetValue(temp.Count + 1, out _));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Converts a IReadOnlyFieldList into a <see cref="IList{T}"/>
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static IList <PrimitiveField> ToList(this IReadOnlyFieldList source)
        {
            var list = new List <PrimitiveField>();

            for (int i = 0; i < source.Count; i++)
            {
                list.Add(source[i]);
            }

            return(list);
        }
Exemplo n.º 8
0
        public void Verify_can_access_list_with_multiple_field_types()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Map).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.List).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            for (int i = 0; i < temp.Count; i++)
            {
                switch (temp[i].DataType)
                {
                case SchemaDataType.None:
                    break;

                case SchemaDataType.Primitive:
                    PrimitiveField specification = temp[i];
                    Assert.IsNotNull(specification);
                    Assert.That(specification.Id, Is.EqualTo("field1").Or.EqualTo("field4").Or.EqualTo("field5"));
                    break;

                case SchemaDataType.Map:
//                        MapField mapField = schema.Fields[i].Cast<MapField>();
//                        Assert.IsNotNull(mapField);
//                        Assert.AreEqual("field2", mapField.Id);
                    break;

                case SchemaDataType.List:
//                        ListField listField = schema.Fields[i].Cast<ListField>();
//                        Assert.IsNotNull(listField);
//                        Assert.AreEqual("field3", listField.Id);
                    break;

                case SchemaDataType.Decimal:
                    DecimalField spec = temp[i].Cast <DecimalField>();
                    Assert.IsNotNull(spec);
                    Assert.AreEqual("field6", spec.Id);
                    break;

                case SchemaDataType.Struct:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Exemplo n.º 9
0
        public void Verify_cannot_find_field_by_field_id()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsFalse(temp.Contains("field7"));
        }
Exemplo n.º 10
0
        public void Verify_TryGetValue_will_not_throw_when_index_less_than_zero()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsFalse(temp.TryGetValue(-1, out PrimitiveField field));
            Assert.IsNotNull(field);
        }
Exemplo n.º 11
0
        public void Verify_TryGetValue_will_return_field()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsTrue(temp.TryGetValue(3, out PrimitiveField field));
            Assert.IsNotNull(field);
            Assert.AreEqual("field4", field.Id);
            Assert.AreEqual(SchemaDataType.Primitive, field.DataType);
        }
Exemplo n.º 12
0
        public void Verify_can_remove_first_field_matching_criteria2()
        {
            var schema = Schema.Builder()
                         .Field <Primitive>(x => x.Id("field1").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field2").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field1").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field4").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field1").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field6").IsNullable().Build())
                         .Build();

            Assert.IsTrue(schema.Fields.HasValues);
            Assert.AreEqual(6, schema.Fields.Count);

            IReadOnlyFieldList fields = schema.RemoveAll <PrimitiveField>(x => x.Id == "field1");

            Assert.AreEqual(3, schema.Fields.Count);
            Assert.AreEqual(3, fields.Count);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Iterates through a list of fields and returns a flattened list of fields.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static IReadOnlyFieldList SelectMany(this IReadOnlyFieldList source)
        {
            var fields = new FieldList(false);

            for (int i = 0; i < source.Count; i++)
            {
                switch (source[i])
                {
                case StructField field:
                    fields.Add(field);
                    for (int j = 0; j < field.Fields.Count; j++)
                    {
                        fields.Add(field.Fields[j]);
                    }
                    break;

                case ListField field:
                    fields.AddRange(field);
                    break;

                case MapField field:
                    fields.AddRange(field);
                    break;

                case DecimalField field:
                    fields.AddRange(field);
                    break;

                case DateTimeField field:
                    fields.AddRange(field);
                    break;

                case PrimitiveField field:
                    fields.AddRange(field);
                    break;

                default:
                    throw new ArgumentException();
                }
            }

            return(fields);
        }
Exemplo n.º 14
0
        public void Verify_can_find_field_in_readonly_list()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            PrimitiveField field = Field.Builder <Primitive>()
                                   .Id("field4")
                                   .DataType(SchemaDataType.Primitive)
                                   .IsNullable()
                                   .Build();

            IReadOnlyFieldList temp = fields;

            Assert.IsTrue(temp.Contains(field));
        }
Exemplo n.º 15
0
        public void Verify_readonly_list_are_equal()
        {
            var fields1 = new FieldList();

            fields1.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields1.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields1.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields1.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields1.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            var fields2 = new FieldList();

            fields2.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields2.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields2.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields2.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields2.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp1 = fields1;
            IReadOnlyFieldList temp2 = fields2;

            Assert.IsTrue(temp1.Equals(temp2));
        }
        public void Test()
        {
            var schema = Schema.Builder()
                         .Field <Struct>(x =>
            {
                return(x.Id("field1")
                       .Field <Primitive>(f => f.Id("fieldA").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Primitive>(f => f.Id("fieldB").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Primitive>(f => f.Id("fieldC").DataType(SchemaDataType.Primitive).IsNullable().Build())
                       .Field <Decimal>(f => f.Id("fieldD").Precision(5).Scale(2).IsNullable().Build())
                       .Build());
            })
                         .Field <Primitive>(x => x.Id("field6").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field7").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field8").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field9").IsNullable().Build())
                         .Field <Primitive>(x => x.Id("field10").IsNullable().Build())
                         .Build();

            IReadOnlyFieldList fieldList = schema.Fields.SelectMany();

            Assert.AreEqual(10, fieldList.Count);
        }
Exemplo n.º 17
0
        public void Verify_can_access_list_using_indexer()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsNotNull(temp[0]);
            Assert.IsNotNull(temp[1]);
            Assert.IsNotNull(temp[2]);
            Assert.IsNotNull(temp[3]);
            Assert.IsNotNull(temp[4]);
            Assert.AreEqual("field1", temp[0].Id);
            Assert.AreEqual("field2", temp[1].Id);
            Assert.AreEqual("field3", temp[2].Id);
            Assert.AreEqual("field4", temp[3].Id);
            Assert.AreEqual("field5", temp[4].Id);
        }
Exemplo n.º 18
0
        public ISchemaBuilder Fields(IReadOnlyFieldList fields)
        {
            _specifications.AddRange(fields.ToList());

            return(this);
        }
Exemplo n.º 19
0
        public Struct Fields(IReadOnlyFieldList fields)
        {
            _fields.AddRange(fields.ToList());

            return(this);
        }
Exemplo n.º 20
0
 public bool Equals(IReadOnlyFieldList other) => false;