Exemplo n.º 1
0
        public void Test_With_Valid_Values()
        {
            // ARRANGE
            AuditIgnoreAttribute paramAuditIgnore = new AuditIgnoreAttribute();
            ForeignKeyAttribute  paramForeignKey  = new ForeignKeyAttribute("ForeignKeyProperty");
            KeyAttribute         paramKey         = new KeyAttribute();
            NotMappedAttribute   paramNotMapped   = new NotMappedAttribute();
            RangeAttribute       paramRange       = new RangeAttribute(
                minimum: 1D,
                maximum: 5D);

            // ACT
            PropertyAttributeSummary propertyAttributeSummary = new PropertyAttributeSummary(
                auditIgnore: paramAuditIgnore,
                foreignKey: paramForeignKey,
                key: paramKey,
                notMapped: paramNotMapped,
                range: paramRange);

            // ASSERT
            Assert.AreSame(paramAuditIgnore, propertyAttributeSummary.AuditIgnore);
            Assert.AreSame(paramForeignKey, propertyAttributeSummary.ForeignKey);
            Assert.AreSame(paramKey, propertyAttributeSummary.Key);
            Assert.AreSame(paramNotMapped, propertyAttributeSummary.NotMapped);
            Assert.AreSame(paramRange, propertyAttributeSummary.Range);
        }
Exemplo n.º 2
0
        public void Test_With_Null_Values()
        {
            // ACT
            PropertyAttributeSummary propertyAttributeSummary = new PropertyAttributeSummary(
                auditIgnore: null,
                foreignKey: null,
                key: null,
                notMapped: null,
                range: null);

            // ASSERT
            Assert.IsNull(propertyAttributeSummary.AuditIgnore);
            Assert.IsNull(propertyAttributeSummary.ForeignKey);
            Assert.IsNull(propertyAttributeSummary.Key);
            Assert.IsNull(propertyAttributeSummary.NotMapped);
            Assert.IsNull(propertyAttributeSummary.Range);
        }
Exemplo n.º 3
0
        public void Test_Reading_Property_Without_Attributes()
        {
            // ARRANGE
            const string propertyName = nameof(MyTestClass.PropertyWithoutAttributes);
            MyTestClass  testObj      = new MyTestClass();
            Type         type         = testObj.GetType();

            PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(type);
            PropertyDescriptor           propertyDescriptor  = propertyDescriptors[propertyName];

            // ACT
            PropertyAttributeSummary attributes = propertyDescriptor.GetAttributes();

            // ASSERT
            Assert.IsNotNull(attributes);
            Assert.IsNull(attributes.AuditIgnore);
            Assert.IsNull(attributes.ForeignKey);
            Assert.IsNull(attributes.Key);
            Assert.IsNull(attributes.NotMapped);
            Assert.IsNull(attributes.Range);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether [is auditable column] [the specified property descriptors].
        /// </summary>
        /// <param name="propertyDescriptors">Property Descriptors.</param>
        /// <param name="propertyInfo">Property Information.</param>
        /// <returns>
        ///   <c>true</c> if [is auditable column] [the specified property descriptors]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsAuditableColumn(
            PropertyDescriptorCollection propertyDescriptors,
            PropertyInfo propertyInfo)
        {
            if (propertyDescriptors == null)
            {
                throw new ArgumentNullException(nameof(propertyDescriptors));
            }

            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            // Get property descriptor details for model property
            PropertyDescriptor propertyDescriptor = propertyDescriptors[propertyInfo.Name];

            if (propertyDescriptor == null)
            {
                return(false);
            }

            PropertyAttributeSummary propertyAttributes = propertyDescriptor.GetAttributes();

            // Auditable if
            // - Has a setter
            // - Not got [Key] attribute
            // - Not got [ForeignKey] attribute
            // - Not got [NotMapped] attribute
            // - Not got [AuditIgnore] attribute
            // - Not a collection
            return(propertyInfo.CanWrite &&
                   propertyAttributes.Key == null &&
                   propertyAttributes.ForeignKey == null &&
                   propertyAttributes.NotMapped == null &&
                   propertyAttributes.AuditIgnore == null &&
                   !propertyInfo.IsCollection());
        }