List<TestCase> GetTests () { if (cachedTests != null) return cachedTests; List<TestCase> tests = new List<TestCase> (); foreach (MethodInfo met in GetType().GetMethods ()) { foreach (TestStepAttribute sat in met.GetCustomAttributes (typeof(TestStepAttribute), true)) { TestCase tc = new TestCase () { Method = met, RunAfter = sat.RunAfter, Stage = sat.Stage }; AddSorted (tests, tc); } foreach (UndoTestStepAttribute sat in met.GetCustomAttributes (typeof(UndoTestStepAttribute), true)) { AddUndo (tests, sat.Undoes, met); } } cachedTests = tests; return tests; }
void AddSorted (List<TestCase> list, TestCase t) { for (int n=0; n<list.Count; n++) { if (list[n].Method.Name == t.RunAfter) { list.Insert (n+1, t); return; } if (list[n].RunAfter == t.Method.Name) { list.Insert (n, t); return; } } list.Add (t); }