using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using System.Reflection; using ActiveRecordScaffolding.Controllers; using Castle.ActiveRecord; namespace ActiveRecordScaffolding.Tests { [TestFixture] public class ARControllerModuleTests { [ActiveRecord] private class ProjectType { } [Test] public void CanCacheTheObjects() { //this might be something better handled by the ioc....not sure Dictionary instances = new Dictionary(); Type g = typeof(ARController<>); Type ct = g.MakeGenericType(typeof(ProjectType)); object inst = Activator.CreateInstance(ct); instances.Add(typeof(ProjectType), inst); ARController controller = instances[typeof(ProjectType)] as ARController; Assert.IsNotNull(controller); } [Test] public void CanCreateARControllerFromTypeAtRuntime() { Type g = typeof(ARController<>); Type ct = g.MakeGenericType(typeof(ProjectType)); object inst = Activator.CreateInstance(ct); Assert.IsNotNull(inst); } [Test] public void CanFindActiveRecordClasses() { //just testing how maybe to go about it Assembly asm = typeof(ARController<>).Assembly; Type[] types = asm.GetExportedTypes(); foreach (Type type in types) { object[] attribs = type.GetCustomAttributes(typeof(ActiveRecordAttribute), false); if (attribs != null && attribs.Length == 1) { Console.WriteLine(type.Name); } } } } }