コード例 #1
0
        /// <summary>
        /// Use the property as a simple property, getting/setting the values without
        /// causing mock expectations.
        /// </summary>
        public IMethodOptions <T> PropertyBehavior()
        {
            AssertExpectationOnPropertyWithGetterAndSetter();
            PropertyInfo prop = GetPropertyFromMethod(expectation.Method);

            proxy.RegisterPropertyBehaviorFor(prop);
            repository.Recorder.RemoveExpectation(expectation);
            expectation.RepeatableOption = RepeatableOption.PropertyBehavior;
            return(this);
        }
コード例 #2
0
        static void SetPropertyBehavior(IMockedObject mockedObject, IEnumerable<Type> implementedTypes)
        {
            foreach (Type type in implementedTypes)
            {
                if (type.BaseType != null && type.BaseType != typeof(object))
                    SetPropertyBehavior(mockedObject, new[] { type.BaseType });

                SetPropertyBehavior(mockedObject, type.GetInterfaces());
                
                foreach (PropertyInfo propertyInfo in type.GetProperties())
                {
                    if (propertyInfo.CanRead && CanWriteToPropertyThroughPublicSignature(propertyInfo) &&
                        !mockedObject.RegisterPropertyBehaviorFor(propertyInfo) &&
                            propertyInfo.PropertyType.IsValueType)
                    {
                        CreateDefaultValueForValueTypeProperty(mockedObject, propertyInfo);
                    }
                }
            }
        }
コード例 #3
0
        static void SetPropertyBehavior(IMockedObject mockedObject, IEnumerable <Type> implementedTypes)
        {
            foreach (Type type in implementedTypes)
            {
                if (type.BaseType != null && type.BaseType != typeof(object))
                {
                    SetPropertyBehavior(mockedObject, new[] { type.BaseType });
                }

                SetPropertyBehavior(mockedObject, type.GetInterfaces());

                foreach (PropertyInfo propertyInfo in type.GetProperties())
                {
                    if (propertyInfo.CanRead && CanWriteToPropertyThroughPublicSignature(propertyInfo) &&
                        !mockedObject.RegisterPropertyBehaviorFor(propertyInfo) &&
                        propertyInfo.PropertyType.IsValueType)
                    {
                        CreateDefaultValueForValueTypeProperty(mockedObject, propertyInfo);
                    }
                }
            }
        }
コード例 #4
0
        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 && CanWriteToPropertyThroughPublicSignature(property))
                    {
                        bool alreadyHasValue = mockedObject.RegisterPropertyBehaviorFor(property);
                        if (property.PropertyType.IsValueType && alreadyHasValue == false)
                        {
                            CreateDefaultValueForValueTypeProperty(mockedObject, property);
                        }
                    }
                }
            }
        }
コード例 #5
0
        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 && CanWriteToPropertyThroughPublicSignature(property))
                    {
                        bool alreadyHasValue = mockedObject.RegisterPropertyBehaviorFor(property);
                        if (property.PropertyType.IsValueType && alreadyHasValue == false)
                        {
                            CreateDefaultValueForValueTypeProperty(mockedObject, property);
                        }
                    }
                }

            }
        }
コード例 #6
0
        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) });
                        }
                    }
                }

            }
        }