コード例 #1
0
    static void _Run(IList <string> names, BHL_TestBase test, bool verbose)
    {
        int c = 0;

        foreach (var method in test.GetType().GetMethods())
        {
            if (IsMemberTested(method))
            {
                if (IsAllowedToRun(names, test, method))
                {
                    if (verbose)
                    {
                        Console.WriteLine(">>>> Testing " + test.GetType().Name + "." + method.Name + " <<<<");
                    }

                    ++c;
                    method.Invoke(test, new object[] {});
                }
            }
        }

        if (c > 0)
        {
            Console.WriteLine("Done running " + c + " tests");
        }
    }
コード例 #2
0
    static bool IsAllowedToRun(IList <string> names, BHL_TestBase test, MemberInfo member)
    {
        if (names?.Count == 0)
        {
            return(true);
        }

        for (int i = 0; i < names.Count; ++i)
        {
            var parts = names[i].Split('.');

            string test_filter   = parts.Length >= 1 ? parts[0] : null;
            string method_filter = parts.Length > 1 ? parts[1] : null;

            bool exact = true;
            if (test_filter != null && test_filter.EndsWith("~"))
            {
                exact       = false;
                test_filter = test_filter.Substring(0, test_filter.Length - 1);
            }

            if (method_filter != null && method_filter.EndsWith("~"))
            {
                exact         = false;
                method_filter = method_filter.Substring(0, method_filter.Length - 1);
            }

            if (test_filter == null || (test_filter != null && (exact ? test.GetType().Name == test_filter : test.GetType().Name.IndexOf(test_filter) != -1)))
            {
                if (method_filter == null || (method_filter != null && (exact ? member.Name == method_filter : member.Name.IndexOf(method_filter) != -1)))
                {
                    return(true);
                }
            }
        }

        return(false);
    }