public void Initialize() { IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "Scalar"); PropertyBase propertyBase = new StubPropertyBase( CreateParameters( propertyInfo: propertyInfo, underlyingType: propertyInfo.PropertyType, concreteType: propertyInfo.PropertyType, listInfo: null, isRequired: true, isReadOnly: true)); Assert.That(propertyBase.PropertyInfo, Is.SameAs(propertyInfo)); Assert.That(propertyBase.PropertyType, Is.SameAs(propertyInfo.PropertyType)); Assert.That(propertyBase.IsRequired, Is.True); Assert.That(propertyBase.IsReadOnly(null), Is.True); Assert.That(propertyBase.BusinessObjectProvider, Is.SameAs(_bindableObjectProvider)); Assert.That(((IBusinessObjectProperty)propertyBase).BusinessObjectProvider, Is.SameAs(_bindableObjectProvider)); }
public void IsReadOnly_WithReadOnlyProperty_ReturnsTrue_DoesNotUseStrategy() { var bindablePropertyWriteAccessStrategyMock = MockRepository.GenerateMock <IBindablePropertyWriteAccessStrategy>(); IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ThrowingProperty"); PropertyBase propertyBase = new StubPropertyBase( CreateParameters( propertyInfo: propertyInfo, underlyingType: propertyInfo.PropertyType, concreteType: propertyInfo.PropertyType, listInfo: null, isReadOnly: true, bindablePropertyWriteAccessStrategy: bindablePropertyWriteAccessStrategyMock)); var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty); Assert.That(propertyBase.IsReadOnly((IBusinessObject)instance), Is.True); bindablePropertyWriteAccessStrategyMock.AssertWasNotCalled(mock => mock.CanWrite(null, null), options => options.IgnoreArguments()); }
public void IsReadOnly_WithWritableProperty_ReturnsValueFromStrategy() { var bindablePropertyWriteAccessStrategyMock = MockRepository.GenerateMock <IBindablePropertyWriteAccessStrategy>(); IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ThrowingProperty"); PropertyBase propertyBase = new StubPropertyBase( CreateParameters( propertyInfo: propertyInfo, underlyingType: propertyInfo.PropertyType, concreteType: propertyInfo.PropertyType, listInfo: null, isReadOnly: false, bindablePropertyWriteAccessStrategy: bindablePropertyWriteAccessStrategyMock)); var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty); var expectedValue = BooleanObjectMother.GetRandomBoolean(); bindablePropertyWriteAccessStrategyMock.Expect(mock => mock.CanWrite((IBusinessObject)instance, propertyBase)).Return(!expectedValue); Assert.That(propertyBase.IsReadOnly((IBusinessObject)instance), Is.EqualTo(expectedValue)); bindablePropertyWriteAccessStrategyMock.VerifyAllExpectations(); }