示例#1
0
        public void SetDefaultValueTyped()
        {
            {
                var    schema          = new SimpleTypeSchema <string>("Currency");
                Action setDefaultValue = () => schema.SetDefaultValue(null);
                setDefaultValue.Should().NotThrow();
                schema.GetDefaultValue().Should().NotBeNull();
                schema.GetDefaultValue().GetDefaultValue().Should().Be(null);
            }

            {
                var    schema          = new SimpleTypeSchema <string>("Currency");
                Action setDefaultValue = () => schema.SetDefaultValue("empty");
                setDefaultValue.Should().NotThrow();
                schema.GetDefaultValue().Should().NotBeNull();
                schema.GetDefaultValue().GetDefaultValue().Should().Be("empty");
            }

            {
                var    schema          = new SimpleTypeSchema <double>("Money");
                Action setDefaultValue = () => schema.SetDefaultValue(0.0);
                setDefaultValue.Should().NotThrow();
                schema.GetDefaultValue().Should().NotBeNull();
                schema.GetDefaultValue().GetDefaultValue().Should().Be(0.0);
            }

            {
                var    schema          = new SimpleTypeSchema <double>("Money");
                Action setDefaultValue = () => schema.SetDefaultValue(100);
                setDefaultValue.Should().NotThrow();
                schema.GetDefaultValue().Should().NotBeNull();
                schema.GetDefaultValue().GetDefaultValue().Should().Be(100.0);
            }
        }
示例#2
0
        public void SetDefaultValueUntyped()
        {
            var schema = new SimpleTypeSchema("Currency", typeof(string));

            Action setDefaultValue = () => schema.SetDefaultValueUntyped(null);

            setDefaultValue.Should().NotThrow();
            schema.GetDefaultValue().Should().NotBeNull();
            schema.GetDefaultValue().GetDefaultValue().Should().BeNull();

            schema          = new SimpleTypeSchema("Currency", typeof(string));
            setDefaultValue = () => schema.SetDefaultValueUntyped(1);
            setDefaultValue.Should().Throw <Exception>().And.Message.Should().Be("Value 1 can not be set as default value for type System.String");
            schema.GetDefaultValue().Should().BeNull();

            schema          = new SimpleTypeSchema("Money", typeof(double));
            setDefaultValue = () => schema.SetDefaultValueUntyped(0.0);
            setDefaultValue.Should().NotThrow();
            schema.GetDefaultValue().Should().NotBeNull();
            schema.GetDefaultValue().GetDefaultValue().Should().Be(0.0);

            schema          = new SimpleTypeSchema("Money", typeof(double));
            setDefaultValue = () => schema.SetDefaultValueUntyped(100);
            setDefaultValue.Should().Throw <Exception>().And.Message.Should().Be("Value 100 can not be set as default value for type System.Double");
            schema.GetDefaultValue().Should().BeNull();

            schema          = new SimpleTypeSchema("Money", typeof(double));
            setDefaultValue = () => schema.SetDefaultValueUntyped(null);
            setDefaultValue.Should().Throw <Exception>().And.Message.Should().Be("null value can not be set as default value for type System.Double");
            schema.GetDefaultValue().Should().BeNull();
        }
        public void check_allowed_values()
        {
            IProperty <string> Sex1 = new Property <string>("Sex1")
                                      .SetAllowedValues("Male", "Female");

            IProperty <string> Sex2 = new Property <string>("Sex2")
                                      .SetAllowedValuesFromEnum(typeof(SexType));

            IProperty <SexType> Sex3 = new Property <SexType>("Sex3")
                                       .SetAllowedValuesFromEnum();

            IProperty <int> Sex4 = new Property <int>("Sex4")
                                   .SetAllowedValuesFromEnum(typeof(SexType));

            IProperty <int> Sex5 = new Property <int>("Sex5")
                                   .SetAllowedValuesFromEnum <SexType>();

            ISchema <string> sexSchema = new SimpleTypeSchema <string>("Sex")
                                         .SetAllowedValues("Male", "Female");

            IProperty <string> Sex6 = new Property <string>("Sex6")
                                      .SetSchema(sexSchema);

            Sex1.GetAllowedValues().Values.Should().BeEquivalentTo("Male", "Female");
            Sex2.GetAllowedValues().Values.Should().BeEquivalentTo("Male", "Female");
            Sex3.GetAllowedValues().Values.Should().BeEquivalentTo(SexType.Male, SexType.Female);
            Sex4.GetAllowedValues().Values.Should().BeEquivalentTo(0, 1);
            Sex5.GetAllowedValues().Values.Should().BeEquivalentTo(0, 1);
            Sex6.GetAllowedValues().Values.Should().BeEquivalentTo("Male", "Female");
        }
        public void StringMaxLength()
        {
            var schema = new SimpleTypeSchema("Currency", typeof(string))
                         .SetStringMaxLength(3);

            schema.GetStringMaxLength() !.MaxLength.Should().Be(3);

            Property <string> currency = new Property <string>("Currency")
                                         .SetSchema(schema);

            var validationRules = ValidationProvider.Instance.GetValidationRules(currency).ToList();

            validationRules.Should().HaveCount(1);

            var messages = new MutablePropertyContainer()
                           .WithValue(currency, "USD")
                           .Validate(validationRules)
                           .ToList();

            messages.Should().BeEmpty();

            messages = new MutablePropertyContainer()
                       .WithValue(currency, "abcd")
                       .Validate(validationRules)
                       .ToList();

            messages[0].FormattedMessage.Should().Be("Value 'abcd' is too long (length: 4, maxLength: 3)");
        }
示例#5
0
        public void SimpleSchema()
        {
            var schema = new SimpleTypeSchema("Currency", typeof(string))
                         .SetStringMinLength(3);

            schema.Name.Should().Be("Currency");
            schema.Type.Should().Be(typeof(string));

            schema.AsMetadataProvider().GetMetadataContainer().Count.Should().Be(1);
        }
        public void StringMinMaxLength()
        {
            var schema = new SimpleTypeSchema("Currency", typeof(string))
                         .SetStringMinLength(3)

                         .SetStringMaxLength(2)
                         .SetStringMaxLength(3);

            Property <string> currency = new Property <string>("Currency")
                                         .SetSchema(schema);

            var validationRules = ValidationProvider.Instance.GetValidationRules(currency).ToList();

            validationRules.Should().HaveCount(2);
        }