public void TestRemoveProvider_Provider_Instance_3 () { var instance = new MyComponent (); var provider = new MyTypeDescriptionProvider (); bool refreshedCalled = false; bool refreshedCorrectComponentChanged = false; bool refreshedCorrectTypeChanged = false; RefreshEventHandler handler = (RefreshEventArgs args) => { refreshedCalled = true; refreshedCorrectComponentChanged = args.ComponentChanged == instance; refreshedCorrectTypeChanged = args.TypeChanged == typeof (MyComponent); }; try { TypeDescriptor.Refreshed += handler; TypeDescriptor.RemoveProvider (provider, instance); Assert.AreEqual (true, refreshedCalled, "#A1"); Assert.AreEqual (true, refreshedCorrectComponentChanged, "#A2"); Assert.AreEqual (true, refreshedCorrectTypeChanged, "#A3"); } finally { TypeDescriptor.Refreshed -= handler; } }
public void TestRemoveProvider_Provider_Type_2 () { var provider = new MyTypeDescriptionProvider (); TypeDescriptor.RemoveProvider (provider, null); }
public void TestRemoveProvider_Provider_Instance_2 () { var provider = new MyTypeDescriptionProvider (); TypeDescriptor.RemoveProvider (provider, (object)null); }
public void TestGetProvider_Instance_2 () { var instance = new MyComponent (); TypeDescriptionProvider provider = TypeDescriptor.GetProvider (instance); Assert.IsNotNull (provider, "#A1"); provider = new MyTypeDescriptionProvider ("One"); try { TypeDescriptor.AddProvider (provider, instance); ICustomTypeDescriptor descriptor = provider.GetTypeDescriptor (instance); Assert.IsNotNull (descriptor, "#B1"); Assert.AreEqual ("One", descriptor.GetClassName (), "#B1-1"); } finally { TypeDescriptor.RemoveProvider (provider, instance); } }
public void TestGetProvider_Type_2 () { TypeDescriptionProvider provider = TypeDescriptor.GetProvider (typeof (string)); Assert.IsNotNull (provider, "#A1"); provider = new MyTypeDescriptionProvider ("One"); try { TypeDescriptor.AddProvider (provider, typeof (string)); ICustomTypeDescriptor descriptor = provider.GetTypeDescriptor (typeof (string)); Assert.IsNotNull (descriptor, "#B1"); Assert.AreEqual ("One", descriptor.GetClassName (), "#B1-1"); } finally { TypeDescriptor.RemoveProvider (provider, typeof (string)); } }
public void TestAddProvider_Provider_Type_3 () { var type = typeof (MyComponent); var providers = new MyTypeDescriptionProvider[] { new MyTypeDescriptionProvider ("One"), new MyTypeDescriptionProvider ("Two"), new MyTypeDescriptionProvider ("Three"), new MyTypeDescriptionProvider ("Four") }; try { TypeDescriptionProvider provider; ICustomTypeDescriptor descriptor; TypeDescriptor.AddProvider (providers[0], type); provider = TypeDescriptor.GetProvider (type); Assert.IsNotNull (provider, "#A1"); descriptor = provider.GetTypeDescriptor (type); Assert.IsNotNull (descriptor, "#A1-1"); Assert.AreEqual ("One", descriptor.GetClassName (), "#A1-2"); Assert.AreEqual (false, providers[0].CreateInstanceCalled, "#A1-3"); TypeDescriptor.AddProvider (providers[1], type); provider = TypeDescriptor.GetProvider (type); Assert.IsNotNull (provider, "#B1"); descriptor = provider.GetTypeDescriptor (type.GetType (), type); Assert.IsNotNull (descriptor, "#B1-1"); Assert.AreEqual ("Two", descriptor.GetClassName (), "#B1-2"); // Providers are stored in a stack according to docs, but it's in reality // a FIFO linked list TypeDescriptor.AddProvider (providers[2], type); TypeDescriptor.AddProvider (providers[3], type); provider = TypeDescriptor.GetProvider (type); Assert.IsNotNull (provider, "#C1"); descriptor = provider.GetTypeDescriptor (type.GetType (), type); Assert.IsNotNull (descriptor, "#C1-1"); Assert.AreEqual ("Four", descriptor.GetClassName (), "#C1-2"); TypeDescriptor.RemoveProvider (providers[2], type); provider = TypeDescriptor.GetProvider (type); Assert.IsNotNull (provider, "#D1"); descriptor = provider.GetTypeDescriptor (type.GetType (), type); Assert.IsNotNull (descriptor, "#D1-1"); Assert.AreEqual ("Four", descriptor.GetClassName (), "#D1-2"); TypeDescriptor.RemoveProvider (providers[3], type); provider = TypeDescriptor.GetProvider (type); Assert.IsNotNull (provider, "#E1"); descriptor = provider.GetTypeDescriptor (type.GetType (), type); Assert.IsNotNull (descriptor, "#E1-1"); Assert.AreEqual ("Two", descriptor.GetClassName (), "#E1-2"); } finally { TypeDescriptor.RemoveProvider (providers[0], type); TypeDescriptor.RemoveProvider (providers[1], type); TypeDescriptor.RemoveProvider (providers[2], type); TypeDescriptor.RemoveProvider (providers[3], type); } }
public void TestAddProvider_Provider_Type_2 () { var provider = new MyTypeDescriptionProvider (); TypeDescriptor.AddProvider (provider, (Type) null); }
public MyCustomTypeDescriptor (MyTypeDescriptionProvider provider) { Provider = provider; }