public void TestUnsupportedTypes() { var factory = new DefaultModelFactory(); Assert.IsFalse(factory.CanCreate(typeof(TestCreatePrivateConstructor))); Assert.IsFalse(factory.CanCreate(typeof(TestCreateArgConstructor))); // Cannot create interface types Assert.IsFalse(factory.CanCreate(typeof(ICloneable))); // Cannot create arrays, since we don't know size upfront Assert.IsFalse(factory.CanCreate(typeof(int[]))); }
public void FindModelClassFactory() { ModelFactoryList facs = new ModelFactoryList(); var specificFactory = new SpecificModelClassFactory(); facs.Add(specificFactory); var defaultFactory = new DefaultModelFactory(); facs.Add(defaultFactory); var selectedFactory = facs.FindFactory(typeof(SpecificModelClass)); Assert.AreEqual(specificFactory, selectedFactory); selectedFactory = facs.FindFactory(typeof(GenericModelClass)); Assert.AreEqual(defaultFactory, selectedFactory); }
public void TestSupportedTypes() { var factory = new DefaultModelFactory(); // Test creation of a class with no constructor Assert.IsTrue(factory.CanCreate(typeof(TestCreate))); Assert.IsNotNull(factory.Create(typeof(TestCreate))); // Test creation of class with a public no-args constructor Assert.IsTrue(factory.CanCreate(typeof(TestCreatePublicConstructor))); Assert.IsNotNull(factory.Create(typeof(TestCreatePublicConstructor))); // Test creation of primitives Assert.IsTrue(factory.CanCreate(typeof(int))); Assert.IsNotNull(factory.Create(typeof(int))); // Test creation of Nullable<T> Assert.IsTrue(factory.CanCreate(typeof(int?))); Assert.IsNotNull(factory.Create(typeof(int?))); // Test handling of collection interfaces object collection = null; Assert.IsTrue(factory.CanCreate(typeof(ICollection <string>))); collection = factory.Create(typeof(ICollection <string>)); Assert.IsNotNull(collection); Assert.IsTrue(collection is List <string>); Assert.IsTrue(factory.CanCreate(typeof(IList <HumanName>))); Assert.IsNotNull(factory.Create(typeof(ICollection <HumanName>))); Assert.IsTrue(factory.CanCreate(typeof(IList <int?>))); collection = factory.Create(typeof(ICollection <int?>)); Assert.IsNotNull(collection); Assert.IsTrue(collection is List <int?>); // Test handling of closed generics Assert.IsTrue(factory.CanCreate(typeof(Code <Address.AddressUse>))); Assert.IsNotNull(factory.Create(typeof(Code <Address.AddressUse>))); }