Esempio n. 1
0
        public void Should_update_schema()
        {
            var properties = new SchemaProperties {
                Hints = "my-hint", Label = "my-label"
            };

            sut = sut.Update(properties);

            Assert.Equal(properties, sut.Properties);
        }
Esempio n. 2
0
        public Schema(string name, Field[] fields, SchemaProperties properties, bool isPublished)
            : this(name, properties)
        {
            Guard.NotNullOrEmpty(name, nameof(name));
            Guard.NotNull(fields, nameof(fields));

            this.isPublished = isPublished;

            fieldsOrdered = ImmutableArray.Create(fields);
        }
Esempio n. 3
0
        public Schema Update(SchemaProperties newProperties)
        {
            Guard.NotNull(newProperties, nameof(newProperties));

            return(Clone(clone =>
            {
                clone.properties = newProperties;
                clone.properties.Freeze();
            }));
        }
Esempio n. 4
0
        public Schema(string name, SchemaProperties?properties = null, bool isSingleton = false)
        {
            Guard.NotNullOrEmpty(name);

            this.name = name;

            this.properties = properties ?? new SchemaProperties();
            this.properties.Freeze();

            this.isSingleton = isSingleton;
        }
Esempio n. 5
0
        public static Schema Create(string name, SchemaProperties newProperties)
        {
            if (!name.IsSlug())
            {
                var error = new ValidationError("Name must be a valid slug", "Name");

                throw new ValidationException("Cannot create a new schema", error);
            }

            return(new Schema(name, false, newProperties, ImmutableList <Field> .Empty));
        }
Esempio n. 6
0
        public void Should_instantiate_field()
        {
            var properties = new SchemaProperties {
                Hints = "my-hint", Label = "my-label"
            };

            var schema = Schema.Create("my-name", properties);

            Assert.Equal("my-name", schema.Name);
            Assert.Equal(properties, schema.Properties);
        }
Esempio n. 7
0
        public Schema Update(SchemaProperties newProperties)
        {
            newProperties ??= new SchemaProperties();

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

            return(Clone(clone =>
            {
                clone.properties = newProperties;
                clone.Properties.Freeze();
            }));
        }
Esempio n. 8
0
        public Schema(string name, bool isPublished, SchemaProperties properties, ImmutableList <Field> fields)
        {
            Guard.NotNull(fields, nameof(fields));
            Guard.NotNull(properties, nameof(properties));
            Guard.ValidSlug(name, nameof(name));

            fieldsById   = fields.ToImmutableDictionary(x => x.Id);
            fieldsByName = fields.ToImmutableDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase);

            this.name = name;

            this.fields = fields;

            this.properties = properties;
            this.properties.Freeze();

            this.isPublished = isPublished;
        }
Esempio n. 9
0
 public bool DeepEquals(SchemaProperties properties)
 {
     return(this.WithDeepEqual(properties).IgnoreProperty <Freezable>(x => x.IsFrozen).Compare());
 }
Esempio n. 10
0
        public void Update(SchemaProperties newProperties)
        {
            Guard.NotNull(newProperties, nameof(newProperties));

            properties = newProperties;
        }
Esempio n. 11
0
        public Schema Update(SchemaProperties newProperties)
        {
            Guard.NotNull(newProperties, nameof(newProperties));

            return(new Schema(name, isPublished, newProperties, fields));
        }
Esempio n. 12
0
 public bool DeepEquals(SchemaProperties properties)
 {
     return(SimpleEquals.IsEquals(this, properties));
 }
Esempio n. 13
0
 public static Schema Create(string name, SchemaProperties newProperties)
 {
     return(new Schema(name, false, newProperties, ImmutableList <Field> .Empty));
 }