private static MbUnit2Test CreateTest(RunPipe runPipe)
        {
            IMemberInfo      member      = GuessMemberInfoFromRunPipe(runPipe);
            ICodeElementInfo codeElement = member ?? Reflector.Wrap(runPipe.FixtureType);

            MbUnit2Test test = new MbUnit2Test(runPipe.ShortName, codeElement, runPipe.Fixture, runPipe);

            test.Kind       = TestKinds.Test;
            test.IsTestCase = true;

            if (member != null)
            {
                MbUnit2MetadataUtils.PopulateTestMetadata(test, member);
            }

            return(test);
        }
        /// <summary>
        /// MbUnit v2 does not expose the MemberInfo directly.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Arguably that allows more general filtering rules than Gallio's simple
        /// CodeReference but it is a bit of a nuisance for us here.
        /// So to avoid breaking the MbUnit v2 API, we resort to a
        /// hack based on guessing the right method.
        /// </para>
        /// </remarks>
        private static IMemberInfo GuessMemberInfoFromRunPipe(RunPipe runPipe)
        {
            foreach (RunInvokerVertex vertex in runPipe.Invokers)
            {
                if (!vertex.HasInvoker)
                {
                    continue;
                }

                IRunInvoker invoker = vertex.Invoker;
                if (invoker.Generator.IsTest)
                {
                    // Note: This is the hack.
                    //       We assume the run invoker's name matches the name of
                    //       the actual member and that the member is public and is
                    //       declared by the fixture type.  That should be true with
                    //       all built-in MbUnit v2 invokers.  -- Jeff.
                    Type   fixtureType        = runPipe.FixtureType;
                    string probableMemberName = invoker.Name;

                    // Strip off arguments from a RowTest's member name.  eg. FooMember(123, 456)
                    int parenthesis = probableMemberName.IndexOf('(');
                    if (parenthesis >= 0)
                    {
                        probableMemberName = probableMemberName.Substring(0, parenthesis);
                    }

                    foreach (MemberInfo member in fixtureType.GetMember(probableMemberName,
                                                                        BindingFlags.Public | BindingFlags.Instance))
                    {
                        if (invoker.ContainsMemberInfo(member))
                        {
                            return(Reflector.Wrap(member));
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// MbUnit v2 does not expose the MemberInfo directly.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Arguably that allows more general filtering rules than Gallio's simple
        /// CodeReference but it is a bit of a nuisance for us here.
        /// So to avoid breaking the MbUnit v2 API, we resort to a
        /// hack based on guessing the right method.
        /// </para>
        /// </remarks>
        private static IMemberInfo GuessMemberInfoFromRunPipe(RunPipe runPipe)
        {
            foreach (RunInvokerVertex vertex in runPipe.Invokers)
            {
                if (!vertex.HasInvoker)
                    continue;

                IRunInvoker invoker = vertex.Invoker;
                if (invoker.Generator.IsTest)
                {
                    // Note: This is the hack.
                    //       We assume the run invoker's name matches the name of
                    //       the actual member and that the member is public and is
                    //       declared by the fixture type.  That should be true with
                    //       all built-in MbUnit v2 invokers.  -- Jeff.
                    Type fixtureType = runPipe.FixtureType;
                    string probableMemberName = invoker.Name;

                    // Strip off arguments from a RowTest's member name.  eg. FooMember(123, 456)
                    int parenthesis = probableMemberName.IndexOf('(');
                    if (parenthesis >= 0)
                        probableMemberName = probableMemberName.Substring(0, parenthesis);

                    foreach (MemberInfo member in fixtureType.GetMember(probableMemberName,
                        BindingFlags.Public | BindingFlags.Instance))
                    {
                        if (invoker.ContainsMemberInfo(member))
                            return Reflector.Wrap(member);
                    }
                }
            }

            return null;
        }
        private static MbUnit2Test CreateTest(RunPipe runPipe)
        {
            IMemberInfo member = GuessMemberInfoFromRunPipe(runPipe);
            ICodeElementInfo codeElement = member ?? Reflector.Wrap(runPipe.FixtureType);

            MbUnit2Test test = new MbUnit2Test(runPipe.ShortName, codeElement, runPipe.Fixture, runPipe);
            test.Kind = TestKinds.Test;
            test.IsTestCase = true;

            if (member != null)
                MbUnit2MetadataUtils.PopulateTestMetadata(test, member);

            return test;
        }