public void AddExtensionPropertyShouldNotAllowNullAccessor()
        {
            var target = new CustomTypeDescriptor<object>();
            var ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "Name", (Func<object,string>) null ) );
            Assert.Equal( "accessor", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "Name", (Func<object, string>) null, ObjectExtensions.SetName ) );
            Assert.Equal( "accessor", ex.ParamName );
        }
        public void AddExtensionPropertyShouldNotAllowNullOrEmptyPropertyName()
        {
            var target = new CustomTypeDescriptor<object>();
            var ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( null, ObjectExtensions.GetName ) );
            Assert.Equal( "propertyName", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "", ObjectExtensions.GetName ) );
            Assert.Equal( "propertyName", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( null, ObjectExtensions.GetName, ObjectExtensions.SetName ) );
            Assert.Equal( "propertyName", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "", ObjectExtensions.GetName, ObjectExtensions.SetName ) );
            Assert.Equal( "propertyName", ex.ParamName );
        }
        public void GetPropertiesShouldIncludeExtensionProperties()
        {
            var parent = TypeDescriptor.GetProvider( typeof( string ) ).GetTypeDescriptor( typeof( string ) );
            var target = new CustomTypeDescriptor<string>( parent );

            target.AddExtensionProperty( "Name", ObjectExtensions.GetName );

            var properties = target.GetProperties();

            Assert.Equal( 2, properties.Count );
            Assert.Equal( "Name", properties[1].Name );
        }
        public void GetTypeDescriptorShouldReturnExpectedValue()
        {
            // arrange
            Func<ICustomTypeDescriptor, ICustomTypeDescriptor> factory = parent =>
            {
                var descriptor = new CustomTypeDescriptor<string>( parent );
                descriptor.AddExtensionProperty( "Name", s => s.GetType().Name );
                return descriptor;
            };
            var target = new TypeDescriptionProvider<string>( factory );

            // act
            var actual = target.GetTypeDescriptor( typeof( string ), "" );
            
            // assert
            Assert.NotNull( actual );
            Assert.IsType( typeof( CustomTypeDescriptor<string> ), actual );
        }
        public void GetPropertiesWithFilterShouldIncludeExtensionProperties()
        {
            var target = new CustomTypeDescriptor<string>();

            target.AddExtensionProperty( "Name", ObjectExtensions.GetName, ObjectExtensions.SetName );

            var properties = target.GetProperties( null );

            Assert.Equal( 1, properties.Count );
            Assert.Equal( "Name", properties[0].Name );
        }