Exemplo n.º 1
0
 public Schema UpdateField(long fieldId, FieldProperties newProperties)
 {
     return(UpdateField(fieldId, field =>
     {
         return field.Update(newProperties);
     }));
 }
Exemplo n.º 2
0
        public override NestedField Update(FieldProperties newProperties)
        {
            var typedProperties = ValidateProperties(newProperties);

            return(Clone <NestedField <T> >(clone =>
            {
                clone.SetProperties(typedProperties);
            }));
        }
Exemplo n.º 3
0
        private void CheckProperties(FieldProperties properties)
        {
            Guard.NotNull(properties, nameof(properties));

            if (!supportedFields.Contains(properties.GetType()))
            {
                throw new InvalidOperationException($"The field property '{properties.GetType()}' is not supported.");
            }
        }
Exemplo n.º 4
0
        public override Field Update(FieldProperties newProperties)
        {
            var typedProperties = ValidateProperties(newProperties);

            return(Clone <Field <T> >(clone =>
            {
                clone.properties = typedProperties;
                clone.properties.Freeze();
            }));
        }
Exemplo n.º 5
0
        private T ValidateProperties(FieldProperties newProperties)
        {
            Guard.NotNull(newProperties);

            if (!(newProperties is T typedProperties))
            {
                throw new ArgumentException($"Properties must be of type '{typeof(T)}", nameof(newProperties));
            }

            return(typedProperties);
        }
Exemplo n.º 6
0
        public Field CreateField(long id, string name, Partitioning partitioning, FieldProperties properties)
        {
            Guard.NotNull(properties, nameof(properties));

            var factory = fieldsByPropertyType.GetOrDefault(properties.GetType());

            if (factory == null)
            {
                throw new InvalidOperationException($"The field property '{properties.GetType()}' is not supported.");
            }

            return(factory(id, name, partitioning, properties));
        }
Exemplo n.º 7
0
        public override RootField Update(FieldProperties newProperties)
        {
            var typedProperties = ValidateProperties(newProperties);

            if (properties.Equals(typedProperties))
            {
                return(this);
            }

            return(Clone <RootField <T> >(clone =>
            {
                clone.SetProperties(typedProperties);
            }));
        }
Exemplo n.º 8
0
        private T ValidateProperties(FieldProperties newProperties)
        {
            Guard.NotNull(newProperties, nameof(newProperties));

            newProperties.Freeze();

            if (!(newProperties is T typedProperties))
            {
                throw new ArgumentException($"Properties must be of type '{typeof(T)}", nameof(newProperties));
            }

            newProperties.Validate(() => $"Cannot update field with id '{Id}', because the settings are invalid.");

            return(typedProperties);
        }
Exemplo n.º 9
0
        public override NestedField Update(FieldProperties newProperties)
        {
            var typedProperties = ValidateProperties(newProperties);

            typedProperties.Freeze();

            if (properties.DeepEquals(typedProperties))
            {
                return(this);
            }

            return(Clone <NestedField <T> >(clone =>
            {
                clone.SetProperties(typedProperties);
            }));
        }
Exemplo n.º 10
0
        public static Schema UpdateField(this Schema schema, long fieldId, FieldProperties properties, long?parentId = null)
        {
            if (parentId != null)
            {
                return(schema.UpdateField(parentId.Value, f =>
                {
                    if (f is ArrayField arrayField)
                    {
                        return arrayField.UpdateField(fieldId, n => n.Update(properties));
                    }

                    return f;
                }));
            }

            return(schema.UpdateField(fieldId, f => f.Update(properties)));
        }
Exemplo n.º 11
0
        public void Should_set_or_freeze_sut(FieldProperties properties)
        {
            foreach (var property in properties.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
            {
                var value =
                    property.PropertyType.GetTypeInfo().IsValueType ?
                    Activator.CreateInstance(property.PropertyType) :
                    null;

                property.SetValue(properties, value);

                var result = property.GetValue(properties);

                Assert.Equal(value, result);
            }

            properties.Freeze();

            foreach (var property in properties.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
            {
                var value =
                    property.PropertyType.GetTypeInfo().IsValueType ?
                    Activator.CreateInstance(property.PropertyType) :
                    null;

                Assert.Throws <InvalidOperationException>(() =>
                {
                    try
                    {
                        property.SetValue(properties, value);
                    }
                    catch (Exception ex)
                    {
                        throw ex.InnerException;
                    }
                });
            }
        }
Exemplo n.º 12
0
        public override void Update(FieldProperties newProperties)
        {
            var typedProperties = ValidateProperties(newProperties);

            properties = typedProperties;
        }
Exemplo n.º 13
0
 public abstract NestedField Update(FieldProperties newProperties);
Exemplo n.º 14
0
        public NestedField CreateNestedField(long id, string name, FieldProperties properties, IFieldSettings settings = null)
        {
            CheckProperties(properties);

            return(properties.CreateNestedField(id, name, settings));
        }
Exemplo n.º 15
0
        public RootField CreateRootField(long id, string name, Partitioning partitioning, FieldProperties properties, IFieldSettings settings = null)
        {
            CheckProperties(properties);

            return(properties.CreateRootField(id, name, partitioning, settings));
        }
Exemplo n.º 16
0
 public bool DeepEquals(FieldProperties properties)
 {
     return(this.WithDeepEqual(properties).IgnoreProperty <Freezable>(x => x.IsFrozen).Compare());
 }
Exemplo n.º 17
0
        public RootField CreateRootField(long id, string name, Partitioning partitioning, FieldProperties properties)
        {
            CheckProperties(properties);

            return(properties.CreateRootField(id, name, partitioning));
        }
Exemplo n.º 18
0
        protected override Field UpdateInternal(FieldProperties newProperties)
        {
            var typedProperties = ValidateProperties(newProperties);

            return(Clone <Field <T> >(clone => clone.properties = typedProperties));
        }
Exemplo n.º 19
0
 public Field CreateField(long id, string name, Partitioning partitioning, FieldProperties properties)
 {
     return(fieldFactory(id, name, partitioning, properties));
 }
Exemplo n.º 20
0
        public Field Update(FieldProperties newProperties)
        {
            ThrowIfLocked();

            return(UpdateInternal(newProperties));
        }
Exemplo n.º 21
0
 public Field Update(FieldProperties newProperties)
 {
     return(UpdateInternal(newProperties));
 }
Exemplo n.º 22
0
        public NestedField CreateNestedField(long id, string name, FieldProperties properties)
        {
            CheckProperties(properties);

            return(properties.CreateNestedField(id, name));
        }
Exemplo n.º 23
0
 protected abstract Field UpdateInternal(FieldProperties newProperties);
Exemplo n.º 24
0
 public abstract RootField Update(FieldProperties newProperties);
Exemplo n.º 25
0
 public abstract void Update(FieldProperties newProperties);