public void ConstructorAndGetTypeDescriptor() {
            AssociatedMetadataTypeTypeDescriptionProvider provider1 = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(TestTable));
            Assert.IsTrue(provider1.GetTypeDescriptor(typeof(TestTable)).GetProperties().Find("Number", true).Attributes.ContainsEquivalent(new RangeAttribute(0, 10)));

            AssociatedMetadataTypeTypeDescriptionProvider provider2 = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(TestTable), typeof(TestTable_MetadataAlternative));
            Assert.IsTrue(provider2.GetTypeDescriptor(typeof(TestTable)).GetProperties().Find("Number", true).Attributes.ContainsEquivalent(new RequiredAttribute()));
        }
        public void GetTypeDescriptorGetProperties_WithAssociatedMetadataType_ReturnsExpected(Type associatedMetadataType, string expectedLastName)
        {
            // Perform multiple times to test static caching behaviour.
            for (int i = 0; i < 2; i++)
            {
                var provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(ClassWithMetadata), associatedMetadataType);
                ICustomTypeDescriptor        typeDescriptor    = provider.GetTypeDescriptor(typeof(ClassWithMetadata), null);
                PropertyDescriptorCollection properties        = typeDescriptor.GetProperties();
                PropertyDescriptor           firstNameProperty = properties[nameof(ClassWithMetadata.FirstName)];
                PropertyDescriptor           lastNameProperty  = properties[nameof(ClassWithMetadata.LastName)];

                Assert.Equal("First name", firstNameProperty.DisplayName);
                Assert.Equal(typeof(ClassWithMetadata), firstNameProperty.ComponentType);
                Assert.Equal(typeof(string), firstNameProperty.PropertyType);
                Assert.True(firstNameProperty.IsReadOnly);
                Assert.False(firstNameProperty.SupportsChangeEvents);

                Assert.Equal(expectedLastName, lastNameProperty.DisplayName);
                Assert.Equal(typeof(ClassWithMetadata), lastNameProperty.ComponentType);
                Assert.Equal(typeof(string), lastNameProperty.PropertyType);
                Assert.False(lastNameProperty.IsReadOnly);
                Assert.False(lastNameProperty.SupportsChangeEvents);
            }
        }
        public void GetTypeDescriptor_MetadataHasFieldsNotPresentOnClass_ThrowsInvalidOperationException()
        {
            var provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(ClassWithInvalidMetadata));

            Assert.Throws <InvalidOperationException>(() => provider.GetTypeDescriptor(typeof(ClassWithInvalidMetadata), null));
        }