예제 #1
0
        public void GetCustomAttributes_RangeDataTypeIsProvided_ZeroAttributesAreCreated()
        {
            var fieldProvider        = MockRepository.GenerateMock <IDynamicRecordFieldProvider>();
            var dynamicRecordFactory = new DynamicRecordFactory(fieldProvider);

            var dynamicRecordField = new DataAnnotatedDynamicRecordField()
            {
                Name           = "Test",
                DotNetDataType = typeof(int),
                RangeDataType  = typeof(int)
            };

            var fields = new List <IDynamicRecordField>()
            {
                dynamicRecordField
            };

            fieldProvider.Stub(x => x.GetFields()).Return(fields);

            var record = dynamicRecordFactory.Create(null);

            var property         = record.GetType().GetProperty(dynamicRecordField.Name);
            var customAttributes = property.GetCustomAttributes(true);

            Assert.AreEqual(0, customAttributes.Count());
        }
예제 #2
0
        public void GetCustomAttributes_EnumDataTypeIsProvided_EnumDataTypeAttributeIsCreated()
        {
            var fieldProvider        = MockRepository.GenerateMock <IDynamicRecordFieldProvider>();
            var dynamicRecordFactory = new DynamicRecordFactory(fieldProvider);

            var dynamicRecordField = new DataAnnotatedDynamicRecordField()
            {
                Name           = "Test",
                DotNetDataType = typeof(MockEnum),
                EnumDataType   = typeof(MockEnum)
            };

            var fields = new List <IDynamicRecordField>()
            {
                dynamicRecordField
            };

            fieldProvider.Stub(x => x.GetFields()).Return(fields);

            var record = dynamicRecordFactory.Create(null);

            var property = record.GetType().GetProperty(dynamicRecordField.Name);
            var enumDataTypeAttribute = (EnumDataTypeAttribute)property
                                        .GetCustomAttributes(true)
                                        .Single(x => x is EnumDataTypeAttribute);

            Assert.AreEqual(typeof(MockEnum), enumDataTypeAttribute.EnumType);
        }
예제 #3
0
        public void GetCustomAttributes_CustomValidatorTypeAndMethodIsProvided_CustomValidatorAttributeIsCreated()
        {
            var fieldProvider        = MockRepository.GenerateMock <IDynamicRecordFieldProvider>();
            var dynamicRecordFactory = new DynamicRecordFactory(fieldProvider);

            var dynamicRecordField = new DataAnnotatedDynamicRecordField()
            {
                Name                  = "Test",
                DotNetDataType        = typeof(string),
                CustomValidatorType   = typeof(object),
                CustomValidatorMethod = "CustomValidatorMethod"
            };

            var fields = new List <IDynamicRecordField>()
            {
                dynamicRecordField
            };

            fieldProvider.Stub(x => x.GetFields()).Return(fields);

            var record = dynamicRecordFactory.Create(null);

            var property = record.GetType().GetProperty(dynamicRecordField.Name);
            var customValidationAttribute = (CustomValidationAttribute)property
                                            .GetCustomAttributes(true)
                                            .Single(x => x is CustomValidationAttribute);

            Assert.AreEqual("CustomValidatorMethod", customValidationAttribute.Method);
        }
예제 #4
0
        public void GetCustomAttributes_MaxLengthIsProvided_MaxLengthAttributeIsCreated()
        {
            var fieldProvider        = MockRepository.GenerateMock <IDynamicRecordFieldProvider>();
            var dynamicRecordFactory = new DynamicRecordFactory(fieldProvider);

            var dynamicRecordField = new DataAnnotatedDynamicRecordField()
            {
                Name           = "Test",
                DotNetDataType = typeof(string),
                MaxLength      = 10
            };

            var fields = new List <IDynamicRecordField>()
            {
                dynamicRecordField
            };

            fieldProvider.Stub(x => x.GetFields()).Return(fields);

            var record = dynamicRecordFactory.Create(null);

            var property           = record.GetType().GetProperty(dynamicRecordField.Name);
            var maxLengthAttribute = (MaxLengthAttribute)property
                                     .GetCustomAttributes(true)
                                     .Single(x => x is MaxLengthAttribute);

            Assert.AreEqual(10, maxLengthAttribute.Length);
        }
예제 #5
0
        public void GetCustomAttributes_RequiredIsProvided_RequiredAttributeIsCreated()
        {
            var fieldProvider        = MockRepository.GenerateMock <IDynamicRecordFieldProvider>();
            var dynamicRecordFactory = new DynamicRecordFactory(fieldProvider);

            var dynamicRecordField = new DataAnnotatedDynamicRecordField()
            {
                Name           = "Test",
                DotNetDataType = typeof(string),
                Required       = true
            };

            var fields = new List <IDynamicRecordField>()
            {
                dynamicRecordField
            };

            fieldProvider.Stub(x => x.GetFields()).Return(fields);

            var record = dynamicRecordFactory.Create(null);

            var property          = record.GetType().GetProperty(dynamicRecordField.Name);
            var requiredAttribute = (RequiredAttribute)property
                                    .GetCustomAttributes(true)
                                    .Single(x => x is RequiredAttribute);
        }
예제 #6
0
        public void GetCustomAttributes_RangeDataTypeAndMinMaxValuesAreProvided_RangeAttributeIsCreated()
        {
            var fieldProvider        = MockRepository.GenerateMock <IDynamicRecordFieldProvider>();
            var dynamicRecordFactory = new DynamicRecordFactory(fieldProvider);

            var dynamicRecordField = new DataAnnotatedDynamicRecordField()
            {
                Name           = "Test",
                DotNetDataType = typeof(int),
                RangeDataType  = typeof(int),
                RangeMinimum   = "1",
                RangeMaximum   = "10"
            };

            var fields = new List <IDynamicRecordField>()
            {
                dynamicRecordField
            };

            fieldProvider.Stub(x => x.GetFields()).Return(fields);

            var record = dynamicRecordFactory.Create(null);

            var property       = record.GetType().GetProperty(dynamicRecordField.Name);
            var rangeAttribute = (RangeAttribute)property
                                 .GetCustomAttributes(true)
                                 .Single(x => x is RangeAttribute);

            Assert.AreEqual(typeof(int), rangeAttribute.OperandType);
            Assert.AreEqual("1", rangeAttribute.Minimum);
            Assert.AreEqual("10", rangeAttribute.Maximum);
        }