예제 #1
0
        private PropertyDescriptor[] OrderPropertyDescriptors(IEnumerable <PropertyDescriptor> propertyDescriptorsToReturn)
        {
            var unorderedProperties    = new List <PropertyDescriptor>();
            var propertiesWithOrdering = new List <Tuple <int, PropertyDescriptor> >();

            foreach (PropertyDescriptor pd in propertyDescriptorsToReturn)
            {
                PropertyOrderAttribute propertyOrderAttribute = pd.Attributes.OfType <PropertyOrderAttribute>().FirstOrDefault();
                if (propertyOrderAttribute != null)
                {
                    propertiesWithOrdering.Add(Tuple.Create(propertyOrderAttribute.Order, pd));
                    continue;
                }

                DynamicPropertyOrderAttribute dynamicPropertyOrderAttribute = pd.Attributes.OfType <DynamicPropertyOrderAttribute>().FirstOrDefault();
                if (dynamicPropertyOrderAttribute != null)
                {
                    propertiesWithOrdering.Add(Tuple.Create(DynamicPropertyOrderAttribute.PropertyOrder(WrappedObject, pd.Name), pd));
                    continue;
                }

                unorderedProperties.Add(pd);
            }

            IEnumerable <PropertyDescriptor> orderedProperties = propertiesWithOrdering.OrderBy(p => p.Item1).Select(p => p.Item2);

            return(orderedProperties.Concat(unorderedProperties).ToArray());
        }
예제 #2
0
        public void PropertyOrder_NoPropertyName_ReturnZero(string propertyName)
        {
            // Call
            int propertyOrder = DynamicPropertyOrderAttribute.PropertyOrder(new object(), propertyName);

            // Assert
            Assert.AreEqual(0.0, propertyOrder);
        }
예제 #3
0
        public void DefaultConstructor_ExpectedValues()
        {
            // Call
            var attribute = new DynamicPropertyOrderAttribute();

            // Assert
            Assert.IsInstanceOf <Attribute>(attribute);
        }
예제 #4
0
        public void PropertyOrder_GivenPropertyDoesNotHaveDynamicPropertyOrderAttribute_ReturnZero()
        {
            // Setup
            var o = new ClassWithPropertyWithoutDynamicPropertyOrderAttribute();

            // Call
            int propertyOrder = DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            Assert.AreEqual(0, propertyOrder);
        }
예제 #5
0
        public void PropertyOrder_ClassWithDynamicPropertyOrderProperty_ReturnResultFromEvaluationMethod(int propertyOrder)
        {
            // Setup
            var o = new ClassWithDynamicPropertyOrderProperty(propertyOrder);

            // Call
            int result = DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            Assert.AreEqual(propertyOrder, result);
        }
예제 #6
0
        public void PropertyOrder_GivenPropertyNameDoesNotExistOnObject_ThrowMissingMemberException()
        {
            // Setup
            var o = new object();

            // Call
            TestDelegate call = () => DynamicPropertyOrderAttribute.PropertyOrder(o, "NotExistingProperty");

            // Assert
            string exceptionMessage = Assert.Throws <MissingMemberException>(call).Message;

            Assert.AreEqual($"Kon eigenschap NotExistingProperty van type {o.GetType()} niet vinden.", exceptionMessage);
        }
예제 #7
0
        public void PropertyOrder_ClassHasMultipleDynamicPropertyOrderEvaluationMethods_ThrowsMissingMethodException()
        {
            // Setup
            var o = new InvalidClassWithDynamicPropertyOrderPropertyAndMultipleEvaluationMethods();

            // Call
            TestDelegate call = () => DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            string exceptionMessage = Assert.Throws <MissingMethodException>(call).Message;
            string expectedMessage  = $"Slechts één DynamicPropertyOrderEvaluationMethod toegestaan per klasse: {o.GetType()}.";

            Assert.AreEqual(expectedMessage, exceptionMessage);
        }
예제 #8
0
        public void PropertyOrder_ClassLacksDynamicPropertyOrderValidationMethod_ThrowsMissingMethodException()
        {
            // Setup
            var o = new InvalidClassWithDynamicPropertyOrderPropertyButNoEvaluationMethod();

            // Call
            TestDelegate call = () => DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            string exceptionMessage = Assert.Throws <MissingMethodException>(call).Message;
            string expectedMessage  = $"DynamicPropertyOrderEvaluationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {o.GetType()}.";

            Assert.AreEqual(expectedMessage, exceptionMessage);
        }
예제 #9
0
        public void PropertyOrder_ClassHasDynamicPropertyOrderEvaluationMethodWithIncorrectArgumentType_ThrowsMissingMethodException()
        {
            // Setup
            var o = new InvalidClassWithDynamicPropertyOrderPropertyButEvaluationMethodArgumentNotString();

            // Call
            TestDelegate call = () => DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            string exceptionMessage = Assert.Throws <MissingMethodException>(call).Message;
            string expectedMessage  = $"Argument van DynamicPropertyOrderEvaluationMethod moet van het type 'string' zijn. Klasse: {o.GetType()}.";

            Assert.AreEqual(expectedMessage, exceptionMessage);
        }
예제 #10
0
        public void PropertyOrder_ClassHasDynamicPropertyOrderEvaluationMethodWithIncorrectArgumentCount_ThrowsMissingMethodException()
        {
            // Setup
            var o = new InvalidClassWithDynamicPropertyOrderPropertyButEvaluationMethodNotOneArgument();

            // Call
            TestDelegate call = () => DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            string exceptionMessage = Assert.Throws <MissingMethodException>(call).Message;
            string expectedMessage  = $"DynamicPropertyOrderEvaluationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {o.GetType()}.";

            Assert.AreEqual(expectedMessage, exceptionMessage);
        }
예제 #11
0
        public void PropertyOrder_ClassHasDynamicPropertyOrderEvaluationMethodWithNonIntReturnType_ThrowsMissingMethodException()
        {
            // Setup
            var o = new InvalidClassWithDynamicPropertyOrderPropertyButEvaluationMethodReturnsIncorrectValueType();

            // Call
            TestDelegate call = () => DynamicPropertyOrderAttribute.PropertyOrder(o, "Property");

            // Assert
            string exceptionMessage = Assert.Throws <MissingMethodException>(call).Message;
            string expectedMessage  = $"DynamicPropertyOrderEvaluationMethod moet 'int' als 'return type' hebben. Klasse: {o.GetType()}.";

            Assert.AreEqual(expectedMessage, exceptionMessage);
        }