AnalyzeSignature() public static method

public static AnalyzeSignature ( MethodBase method ) : CheckDescription
method System.Reflection.MethodBase
return CheckDescription
Example #1
0
        private static CheckDescription GetCheckAndType(FluentCheckException fluExc)
        {
            // identify failing test
            var trace = new StackTrace(fluExc);

            // get fluententrypoint stackframe
            var frameIndex = trace.FrameCount - 2;

            if (frameIndex < 0)
            {
                frameIndex = 0;
            }

            var frame = trace.GetFrame(frameIndex);

            // get method
            var method = frame.GetMethod();

            return(CheckDescription.AnalyzeSignature(method));
        }
Example #2
0
        public void ScanAssembliesForCheckAndGenerateReport()
        {
            var report = new FullRunDescription();

            // scan all assemblies
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.GetName().Name == "MonoDevelop.NUnit")
                {
                    // skip MonoDevelop.NUnit assembly because GetTypes fails
                    continue;
                }

                try
                {
                    // get all test fixtures
                    foreach (var type in
                             assembly.GetTypes()
                             .Where(
                                 type =>
                                 ((type.GetInterface("IForkableCheck") != null &&
                                   (type.Attributes & TypeAttributes.Abstract) == 0) ||
                                  type.GetCustomAttributes(typeof(ExtensionAttribute), false).Length > 0) &&
                                 ((type.Attributes & TypeAttributes.Public) == TypeAttributes.Public)))
                    {
                        try
                        {
                            // enumerate public methods
                            IEnumerable <MethodInfo> tests =
                                type.GetMethods(
                                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static
                                    | BindingFlags.DeclaredOnly)
                                .Where(
                                    method =>
                                    method.MemberType == MemberTypes.Method &&
                                    ((method.Attributes & MethodAttributes.SpecialName) == 0));
                            var publicMethods = tests as IList <MethodInfo> ?? tests.ToList();
                            if (publicMethods.Count > 0)
                            {
                                // scan all methods
                                foreach (var checkMethod in publicMethods)
                                {
                                    try
                                    {
                                        if (checkMethod.Name == "ForkInstance")
                                        {
                                            // skip forkinstance
                                            continue;
                                        }

                                        var desc = CheckDescription.AnalyzeSignature(checkMethod);

                                        if (desc != null)
                                        {
                                            if (desc.CheckedType == null)
                                            {
                                                RunnerHelper.Log(string.Format("Failed to identify checked type on test {0}", checkMethod.Name));
                                            }
                                            else
                                            {
                                                RunnerHelper.Log(string.Format("Method :{0}.{1}({2})", type.Name, checkMethod.Name, desc.CheckedType.Name));
                                                report.AddEntry(desc);
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        RunnerHelper.Log(string.Format("Exception while assessing test {2} on type:{0}\n{1}", type.FullName, e, checkMethod.Name));
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            RunnerHelper.Log(string.Format("Exception while working on type:{0}\n{1}", type.FullName, e));
                        }
                    }
                }
                catch (Exception e)
                {
                    RunnerHelper.Log(string.Format("Exception while working on assembly:{0}\n{1}", assembly.FullName, e));
                    throw new ApplicationException(string.Format("Exception while working on assembly:{0}\n{1}", assembly.FullName, e));
                }
            }

            // xml save
            const string Name = "FluentChecks.xml";

            report.Save(Name);

            const string Name2 = "FluentChecks.csv";

            // csv file
            using (var writer = new StreamWriter(Name2, false))
            {
                foreach (var typeChecks in report.RunDescription)
                {
                    foreach (var checkList in typeChecks.Checks)
                    {
                        foreach (var signature in checkList.CheckSignatures)
                        {
                            var message = string.Format(
                                "{0};{1};{2}", typeChecks.CheckedType.TypeToStringProperlyFormated(true), checkList.CheckName, signature.Signature);
                            writer.WriteLine(message);
                        }
                    }
                }
            }

            Debug.Write(string.Format("Report generated in {0}", Path.GetFullPath(Name)));
            Debug.Write(string.Format("Report generated in {0}", Path.GetFullPath(Name2)));
        }