private static void AssertAttributes(Type interfaceType, params MockAttribute[] expectedAttributes)
        {
            var attributes = InterfaceAttributeUtil.GetAttributes(interfaceType, true);

            Assert.IsNotNull(attributes);
            CollectionAssert.AreEquivalent(expectedAttributes, attributes);
        }
Example #2
0
 private static void AssertInvalid(Type interfaceType)
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         InterfaceAttributeUtil.GetAttributes(interfaceType, true);
     });
 }
Example #3
0
        private static Dictionary <string, PropertyDescriptor> GetPropertyDescriptors(Type type, PropertyDescriptor initializers, out object[] typeBehaviors)
        {
            var propertyMap        = new Dictionary <string, PropertyDescriptor>();
            var interfaceBehaviors = typeBehaviors = ExpandBehaviors(InterfaceAttributeUtil.GetAttributes(type, true)).ToArray();
            var defaultFetch       = typeBehaviors.OfType <FetchAttribute>().Select(b => (bool?)b.Fetch).FirstOrDefault().GetValueOrDefault();

            initializers.AddBehaviors(typeBehaviors.OfType <IDictionaryMetaInitializer>())
            .AddBehaviors(typeBehaviors.OfType <IDictionaryInitializer>());

            CollectProperties(type, (property, reflectedType) =>
            {
                var propertyBehaviors  = ExpandBehaviors(property.GetCustomAttributes(false)).ToArray();
                var propertyDescriptor = new PropertyDescriptor(property, propertyBehaviors)
                                         .AddBehaviors(propertyBehaviors.OfType <IDictionaryBehavior>())
                                         .AddBehaviors(interfaceBehaviors.OfType <IDictionaryBehavior>().Where(b => b is IDictionaryKeyBuilder == false));
                var expandedBehaviors = ExpandBehaviors(InterfaceAttributeUtil
                                                        .GetAttributes(reflectedType, true))
                                        .OfType <IDictionaryKeyBuilder>();
                propertyDescriptor = propertyDescriptor.AddBehaviors(expandedBehaviors);

                AddDefaultGetter(propertyDescriptor);

                var propertyFetch           = propertyBehaviors.OfType <FetchAttribute>().Select(b => (bool?)b.Fetch).FirstOrDefault();
                propertyDescriptor.IfExists = propertyBehaviors.OfType <IfExistsAttribute>().Any();
                propertyDescriptor.Fetch    = propertyFetch.GetValueOrDefault(defaultFetch);

                foreach (var descriptorInitializer in propertyDescriptor.Behaviors.OfType <IPropertyDescriptorInitializer>())
                {
                    descriptorInitializer.Initialize(propertyDescriptor, propertyBehaviors);
                }

                initializers.AddBehaviors(propertyBehaviors.OfType <IDictionaryMetaInitializer>());

                PropertyDescriptor existingDescriptor;
                if (propertyMap.TryGetValue(property.Name, out existingDescriptor))
                {
                    var existingProperty = existingDescriptor.Property;
                    if (existingProperty.PropertyType == property.PropertyType)
                    {
                        if (property.CanRead && property.CanWrite)
                        {
                            propertyMap[property.Name] = propertyDescriptor;
                        }
                        return;
                    }
                }

                propertyMap.Add(property.Name, propertyDescriptor);
            });

            return(propertyMap);
        }
Example #4
0
        private static void AssertAttributes(Type interfaceType, params MockAttribute[] expectedAttributes)
        {
            var attributes = InterfaceAttributeUtil.GetAttributes(interfaceType, true);

            Assert.That(attributes, Is.Not.Null & Is.EquivalentTo(expectedAttributes));
        }