public void Constructor_ExpectedValues() { // Setup var target = new SomeTestClass(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(target); PropertyDescriptor getSetProperty = properties[0]; // Precondition: Assert.IsFalse(getSetProperty.IsReadOnly); // Call var readonlyPropertyDescriptor = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); // Assert Assert.IsInstanceOf <PropertyDescriptor>(readonlyPropertyDescriptor); Assert.IsTrue(readonlyPropertyDescriptor.IsReadOnly); Assert.AreEqual(getSetProperty.ComponentType, readonlyPropertyDescriptor.ComponentType); Assert.AreEqual(getSetProperty.PropertyType, readonlyPropertyDescriptor.PropertyType); Assert.AreEqual(getSetProperty.Attributes, readonlyPropertyDescriptor.Attributes); Assert.AreEqual(getSetProperty.Category, readonlyPropertyDescriptor.Category); Assert.AreEqual(getSetProperty.Converter, readonlyPropertyDescriptor.Converter); Assert.AreEqual(getSetProperty.Description, readonlyPropertyDescriptor.Description); Assert.AreEqual(getSetProperty.DesignTimeOnly, readonlyPropertyDescriptor.DesignTimeOnly); Assert.AreEqual(getSetProperty.DisplayName, readonlyPropertyDescriptor.DisplayName); Assert.AreEqual(getSetProperty.IsBrowsable, readonlyPropertyDescriptor.IsBrowsable); Assert.AreEqual(getSetProperty.IsLocalizable, readonlyPropertyDescriptor.IsLocalizable); Assert.AreEqual(getSetProperty.Name, readonlyPropertyDescriptor.Name); Assert.AreEqual(getSetProperty.SerializationVisibility, readonlyPropertyDescriptor.SerializationVisibility); Assert.AreEqual(getSetProperty.SupportsChangeEvents, readonlyPropertyDescriptor.SupportsChangeEvents); }
public void SetValue_Always_DelegateToWrappedPropertyDescriptor() { // Setup const double originalPropertyValue = 1.1; const double newValue = 2.2; var component = new SomeTestClass { SomeEditableProperty = originalPropertyValue }; PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component); PropertyDescriptor getSetProperty = properties[0]; getSetProperty.SetValue(component, newValue); double expectedPropertyValueAfterSet = component.SomeEditableProperty; var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); component.SomeEditableProperty = originalPropertyValue; // Call wrappedProperty.SetValue(component, newValue); // Assert Assert.AreEqual(expectedPropertyValueAfterSet, component.SomeEditableProperty); }
public void CanResetValue_Always_DelegateToWrappedPropertyDescriptor() { // Setup var component = new SomeTestClass(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component); PropertyDescriptor getSetProperty = properties[0]; var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); // Call bool result = wrappedProperty.CanResetValue(component); // Assert Assert.AreEqual(getSetProperty.CanResetValue(component), result); }
public void GetValue_Always_DelegateToWrappedPropertyDescriptor() { // Setup var component = new SomeTestClass { SomeEditableProperty = 1.1 }; PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component); PropertyDescriptor getSetProperty = properties[0]; var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); // Call object result = wrappedProperty.GetValue(component); // Assert Assert.AreEqual(getSetProperty.GetValue(component), result); Assert.AreEqual(component.SomeEditableProperty, result); }