public SuiteDesc ProvideSuite(string className) { SuiteDesc res; if (!suites.TryGetValue(className, out res)) { res = new SuiteDesc(); suites.Add(className, res); } return(res); }
private void GenTests(string className, string pkg, SuiteDesc desc, StringBuilder suiteStr) { StringBuilder caseStr = new StringBuilder(); desc.tests.Sort(); foreach (string t in desc.tests) { caseStr.AppendFormat(TEST_CASE_TEMPLATE, t); } StringBuilder otherStr = new StringBuilder(); AppendOpt(INIT_TEMPLATE, desc.init, otherStr); AppendOpt(CLEANUP_TEMPLATE, desc.cleanup, otherStr); // TODO test init suiteStr.AppendFormat(SUITE_TEMPLATE, className, pkg, caseStr, otherStr); }
private void ProcessAssembly(MetaData md) { // Look for the annotation that tells us that this assembly is a stand-alone // test app. MetaDataAssembly mda = (MetaDataAssembly)md.Assemblies[0]; foreach (MetaDataCustomAttribute attrib in md.CustomAttributes) { MetaDataObject parent = attrib.Parent; //Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext); if (!attrib.Name.StartsWith(ATTRIBUTE_PREFIX)) { continue; } Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext); string attribName = attrib.Name.Substring(ATTRIBUTE_PREFIX.Length); string className; string item = Tail(attrib.Parent, out className); if (attribName == "TestClassAttribute") { m_suites.Add(attrib.Parent.FullName, attrib); } else if (attribName == "TestMethodAttribute") { m_module.ProvideSuite(className).tests.Add(item); } else if (attribName == "ClassInitializeAttribute") { m_module.ProvideSuite(className).init = item; } else if (attribName == "ClassCleanupAttribute") { m_module.ProvideSuite(className).cleanup = item; } else if (attribName == "TestInitializeAttribute") { m_module.ProvideSuite(className).testInit = item; } else if (attribName == "TestCleanupAttribute") { m_module.ProvideSuite(className).testCleanup = item; } else if (attribName == "AssemblyInitializeAttribute") { m_module.init = item; } else if (attribName == "TestCleanupAttribute") { m_module.cleanup = item; } else { // IGNORE } } StringBuilder suiteStr = new StringBuilder(); StringBuilder jigsStr = new StringBuilder(); foreach (KeyValuePair <string, SuiteDesc> kvp in m_module.suites) { string fullname = kvp.Key; if (!m_suites.ContainsKey(fullname)) { Console.WriteLine("TestMethod declared outside of a TestClass: {0}", fullname); continue; } string pkg; string className = Tail(fullname, '.', out pkg); SuiteDesc desc = kvp.Value; GenTests(className, pkg, desc, suiteStr); jigsStr.AppendFormat(SUITE_CASE_TEMPLATE, className, pkg); } string modulename = "Foo"; StringBuilder otherStr = new StringBuilder(); //AppendOpt(MODULE_INIT_TEMPLATE, m_module.init, otherStr); //AppendOpt(MODULE_INIT_TEMPLATE, m_module.cleanup, otherStr); string content = string.Format(FILE_TEMPLATE, modulename, jigsStr, otherStr, suiteStr); File.WriteAllText(m_outpath, content); }