Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
        public Schema Update(SchemaProperties newProperties)
        {
            Guard.NotNull(newProperties, nameof(newProperties));

            return(Clone(clone =>
            {
                clone.properties = newProperties;
                clone.properties.Freeze();
            }));
        }
Exemple #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;
        }
Exemple #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));
        }
Exemple #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);
        }
Exemple #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();
            }));
        }
Exemple #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;
        }
Exemple #9
0
 public bool DeepEquals(SchemaProperties properties)
 {
     return(this.WithDeepEqual(properties).IgnoreProperty <Freezable>(x => x.IsFrozen).Compare());
 }
Exemple #10
0
        public void Update(SchemaProperties newProperties)
        {
            Guard.NotNull(newProperties, nameof(newProperties));

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

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