/// <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); }
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); } } } }
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); } } } }
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); } } } } }
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) }); } } } } }