private static void CreateDefaultValueForValueTypeProperty(IMockedObject mockedObject, PropertyInfo property)
 {
     mockedObject.HandleProperty(property.GetSetMethod(true),
                                 new object[] { Activator.CreateInstance(property.PropertyType) });
 }
 static void CreateDefaultValueForValueTypeProperty(IMockedObject mockedObject, PropertyInfo property)
 {
     mockedObject.HandleProperty(
         property.GetSetMethod(true),
         new[] { Activator.CreateInstance(property.PropertyType) });
 }
        private void SetPropertyBehavior(IMockedObject mockedObject, params Type[] types)
        {
            foreach (Type implementedType in types)
            {
                if (implementedType.BaseType != null && implementedType.BaseType != typeof(object))
                {
                    SetPropertyBehavior(mockedObject, implementedType.BaseType);
                }

                SetPropertyBehavior(mockedObject, implementedType.GetInterfaces());

                foreach (PropertyInfo property in implementedType.GetProperties())
                {
                    if (property.CanRead && property.CanWrite)
                    {
                        bool alreadyHasValue = mockedObject.RegisterPropertyBehaviorFor(property);
                        if (property.PropertyType.IsValueType && alreadyHasValue == false)
                        {
                            //make sure that it creates a default value for value types
                            mockedObject.HandleProperty(property.GetSetMethod(true),
                                                        new object[] { Activator.CreateInstance(property.PropertyType) });
                        }
                    }
                }

            }
        }
Exemple #4
0
 ///<summary>
 ///</summary>
 public void PerformAgainst(IInvocation invocation)
 {
     invocation.ReturnValue = proxyInstance.HandleProperty(invocation.GetConcreteMethod(), invocation.Arguments);
     mockRepository.RegisterPropertyBehaviorOn(proxyInstance);
     return;
 }