public void SetPropertyByConfig(string objectId) { string testlibraryPath = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\TestLibrary\\bin\\Debug\\netcoreapp3.1"); DirectoryInfo di = new DirectoryInfo(testlibraryPath); IocUtils.AddSearchPath(di.FullName); string config = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\ioc.xml"); IocUtils.LoadConfig(config); object obj = IocUtils.GetObjectById(objectId); Assert.IsNotNull(obj); Console.WriteLine(objectId + ": " + obj); IocUtils.RemoveSearchPath(di.FullName); Assert.IsInstanceOfType(obj, typeof(TestLibrary.Person)); TestLibrary.Person pobj = obj as TestLibrary.Person; Assert.AreEqual(pobj.Name, "王小明"); Assert.AreEqual(pobj.Age, 18); Assert.AreEqual(pobj.IsPerson, true); }
public void BuildByConfigIdWithObjectReference(string objectId) { string testlibraryPath = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\TestLibrary\\bin\\Debug\\netcoreapp3.1"); DirectoryInfo di = new DirectoryInfo(testlibraryPath); IocUtils.AddSearchPath(di.FullName); string config = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\ioc.xml"); IocUtils.LoadConfig(config); object obj = IocUtils.GetObjectById(objectId); Assert.IsNotNull(obj); Console.WriteLine(objectId + ": " + obj); IocUtils.RemoveSearchPath(di.FullName); }
public void Create10000Object() { string testlibraryPath = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\TestLibrary\\bin\\Debug\\netcoreapp3.1"); DirectoryInfo di = new DirectoryInfo(testlibraryPath); IocUtils.AddSearchPath(di.FullName); string config = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\ioc.xml"); IocUtils.LoadConfig(config); Stopwatch w = new Stopwatch(); w.Start(); for (int i = 0; i < 1000000; i++) { object obj = IocUtils.GetObjectById("hhh"); } w.Stop(); IocUtils.RemoveSearchPath(di.FullName); }