public void GetAssociationReturnsDesigner()
        {
            var designer     = new MockDesigner();
            var designerHost = new MockDesignerHost();
            var component    = new DescriptorTestComponent();

            designerHost.AddDesigner(component, designer);
            component.AddService(typeof(IDesignerHost), designerHost);

            object associatedObject = TypeDescriptor.GetAssociation(designer.GetType(), component);

            Assert.IsType <MockDesigner>(associatedObject);
            Assert.Same(designer, associatedObject);
        }
        public void PropertyDescriptorCanBeCreatedThatAccessesNonPublicPropertyOnAssociatedDesigner()
        {
            var designer     = new MockDesigner();
            var designerHost = new MockDesignerHost();
            var component    = new DescriptorTestComponent();

            designerHost.AddDesigner(component, designer);
            component.AddService(typeof(IDesignerHost), designerHost);

            PropertyDescriptorCollection properties     = TypeDescriptor.GetProperties(component);
            PropertyDescriptor           stringProperty = properties[nameof(DescriptorTestComponent.StringProperty)];

            Assert.NotNull(stringProperty);

            // Create new property that "wraps" stringProperty and redirects to the designer.
            // Note that a ReadOnlyAttribute is added to ensure that we can set it
            PropertyDescriptor newStringProperty = TypeDescriptor.CreateProperty(
                componentType: typeof(MockDesigner),
                oldPropertyDescriptor: stringProperty,
                attributes: new[] { ReadOnlyAttribute.No });

            // The property descriptor should be redirected to reflect over the designer.
            const string PropertyValue = "Test";

            Assert.False(designer.StringPropertyHasBeenSet);
            newStringProperty.SetValue(component, PropertyValue);
            Assert.Empty(component.StringProperty);
            Assert.Equal(PropertyValue, newStringProperty.GetValue(component));
            Assert.True(designer.StringPropertyHasBeenSet);

            Assert.False(designer.ShouldSerializeStringPropertyCalled);
            Assert.True(newStringProperty.ShouldSerializeValue(component));
            Assert.True(designer.ShouldSerializeStringPropertyCalled);

            Assert.False(designer.ResetStringPropertyCalled);
            newStringProperty.ResetValue(component);
            Assert.True(designer.ResetStringPropertyCalled);
        }