AddEntry() публичный Метод

public AddEntry ( CheckDescription desc ) : void
desc CheckDescription
Результат void
Пример #1
0
        public void ScanAssembliesForCheckAndGenerateReport()
        {
            var report = new FullRunDescription();

            // scan all assemblies
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                // get all test fixtures
                foreach (var type in
                         assembly.GetTypes()
                         .Where(
                             type =>
                             ((type.GetInterface("IForkableFluentAssertion") != 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)
                        {
                            // run all tests
                            foreach (var checkMethod in publicMethods)
                            {
                                CheckDescription desc = RunnerHelper.AnalyzeSignature(checkMethod);

                                if (desc != null)
                                {
                                    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 working on type:{0}\n{1}", type.FullName, e));
                    }
                }
            }

            const string Name = "FluentChecks.xml";

            report.Save(Name);
            Debug.Write(string.Format("Report generated in {0}", Path.GetFullPath(Name)));
        }
Пример #2
0
        public void ScanAssembliesForCheckAndGenerateReport()
        {
            var report = new FullRunDescription();

            // scan all assemblies
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                // get all test fixtures
                foreach (var type in
                    assembly.GetTypes()
                            .Where(
                                type =>
                                ((type.GetInterface("IForkableFluentAssertion") != 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)
                        {
                            // run all tests
                            foreach (var checkMethod in publicMethods)
                            {
                                CheckDescription desc = RunnerHelper.AnalyzeSignature(checkMethod);

                                if (desc != null)
                                {
                                    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 working on type:{0}\n{1}", type.FullName, e));
                    }
                }
            }

            const string Name = "FluentChecks.xml";
            report.Save(Name);
            Debug.Write(string.Format("Report generated in {0}", Path.GetFullPath(Name)));
        }
Пример #3
0
        private static void RunMethod(MethodBase specificTest, object test, FullRunDescription report, bool log)
        {
            try
            {
                specificTest.Invoke(test, new object[] { });
            }
            catch (Exception e)
            {
                if (specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false).Length == 0)
                {
                    if (CheckContext.DefaulNegated == false)
                    {
                        return;
                    }

                    throw;
                }

                Type expectedType =
                    ((ExpectedExceptionAttribute)
                     specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false)[0]).ExpectedException;
                if (e.InnerException != null)
                {
                    if (e.InnerException is FluentCheckException)
                    {
                        var fluExc = e.InnerException as FluentCheckException;
                        var desc = GetCheckAndType(fluExc);
                        if (desc != null)
                        {
                            var method = desc.Check;
                            var testedtype = desc.CheckedType;
                            desc.ErrorSampleMessage = fluExc.Message;

                            // are we building a report
                            if (log)
                            {
                                Log(
                                    string.Format(
                                        "Check.That({1} sut).{0} failure message\n****\n{2}\n****",
                                        method.Name,
                                        testedtype.Name,
                                        fluExc.Message));
                            }

                            if (report != null)
                            {
                                report.AddEntry(desc);
                            }

                            if (CheckContext.DefaulNegated == false)
                            {
                                Log(string.Format("(Forced) Negated test '{0}' should have succeeded, but it failed (method {1}).", specificTest.Name, desc.Signature));
                            }
                        }
                        else
                        {
                            Log(string.Format("Failed to parse the method signature {0}", specificTest.Name));
                        }

                        return;
                    }

                    if (report != null)
                    {
                        Log(
                            string.Format(
                                "{0} did not generate a fluent check:\n{1}",
                                specificTest.Name,
                                e.InnerException.Message));
                    }

                    if (e.InnerException.GetType() != expectedType && expectedType != null)
                    {
                        throw;
                    }
                }
                else
                {
                    if (report != null)
                    {
                        Log(string.Format("{0} failed to run:\n{1}", specificTest.Name, e));
                    }

                    throw;
                }
            }
        }
Пример #4
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)));
        }
Пример #5
0
        public static void RunMethod(MethodInfo specificTest, object test, FullRunDescription report)
        {
            try
            {
                specificTest.Invoke(test, new object[] { });
            }
            catch (Exception e)
            {
                if (specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false).Length == 0)
                {
                    throw;
                }

                Type expectedType =
                    ((ExpectedExceptionAttribute)
                     specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false)[0]).ExpectedException;
                if (e.InnerException != null)
                {
                    if (e.InnerException is FluentAssertionException)
                    {
                        var              fluExc = e.InnerException as FluentAssertionException;
                        Type             testedtype;
                        CheckDescription desc   = GetCheckAndType(fluExc);
                        MethodBase       method = desc.Check;
                        testedtype = desc.CheckedType;
                        desc.ErrorSampleMessage = fluExc.Message;

                        // are we building a report
                        if (report != null)
                        {
                            Log(
                                string.Format(
                                    "Check.That({1} sut).{0} failure message\n****\n{2}\n****",
                                    method.Name,
                                    testedtype.Name,
                                    fluExc.Message));
                            report.AddEntry(desc);
                        }

                        return;
                    }

                    if (report != null)
                    {
                        Log(
                            string.Format(
                                "{0} did not generate a FLUENT ASSERTION:\n{1}",
                                specificTest.Name,
                                e.InnerException.Message));
                    }

                    if (e.InnerException.GetType() != expectedType && expectedType != null)
                    {
                        throw;
                    }
                }
                else
                {
                    if (report != null)
                    {
                        Log(string.Format("{0} failed to run:\n{1}", specificTest.Name, e));
                    }

                    throw;
                }
            }
        }
Пример #6
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)));
        }
Пример #7
0
        public static void RunMethod(MethodInfo specificTest, object test, FullRunDescription report)
        {
            try
            {
                specificTest.Invoke(test, new object[] { });
            }
            catch (Exception e)
            {
                if (specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false).Length == 0)
                {
                    throw;
                }

                Type expectedType =
                    ((ExpectedExceptionAttribute)
                     specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false)[0]).ExpectedException;
                if (e.InnerException != null)
                {
                    if (e.InnerException is FluentAssertionException)
                    {
                        var fluExc = e.InnerException as FluentAssertionException;
                        Type testedtype;
                        CheckDescription desc = GetCheckAndType(fluExc);
                        MethodBase method = desc.Check;
                        testedtype = desc.CheckedType;
                        desc.ErrorSampleMessage = fluExc.Message;

                        // are we building a report
                        if (report != null)
                        {
                            Log(
                                string.Format(
                                    "Check.That({1} sut).{0} failure message\n****\n{2}\n****",
                                    method.Name,
                                    testedtype.Name,
                                    fluExc.Message));
                            report.AddEntry(desc);
                        }

                        return;
                    }

                    if (report != null)
                    {
                        Log(
                            string.Format(
                                "{0} did not generate a FLUENT ASSERTION:\n{1}",
                                specificTest.Name,
                                e.InnerException.Message));
                    }

                    if (e.InnerException.GetType() != expectedType && expectedType != null)
                    {
                        throw;
                    }
                }
                else
                {
                    if (report != null)
                    {
                        Log(string.Format("{0} failed to run:\n{1}", specificTest.Name, e));
                    }

                    throw;
                }
            }
        }
Пример #8
0
        private static void RunMethod(MethodBase specificTest, object test, FullRunDescription report, bool log)
        {
            try
            {
                specificTest.Invoke(test, new object[] { });
            }
            catch (Exception e)
            {
                if (specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false).Length == 0)
                {
                    if (CheckContext.DefaulNegated == false)
                    {
                        return;
                    }

                    throw;
                }

                Type expectedType =
                    ((ExpectedExceptionAttribute)
                     specificTest.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false)[0]).ExpectedException;
                if (e.InnerException != null)
                {
                    if (e.InnerException is FluentCheckException)
                    {
                        var fluExc = e.InnerException as FluentCheckException;
                        var desc   = GetCheckAndType(fluExc);
                        if (desc != null)
                        {
                            var method     = desc.Check;
                            var testedtype = desc.CheckedType;
                            desc.ErrorSampleMessage = fluExc.Message;

                            // are we building a report
                            if (log)
                            {
                                Log(
                                    string.Format(
                                        "Check.That({1} sut).{0} failure message\n****\n{2}\n****",
                                        method.Name,
                                        testedtype.Name,
                                        fluExc.Message));
                            }

                            if (report != null)
                            {
                                report.AddEntry(desc);
                            }

                            if (CheckContext.DefaulNegated == false)
                            {
                                Log(string.Format("(Forced) Negated test '{0}' should have succeeded, but it failed (method {1}).", specificTest.Name, desc.Signature));
                            }
                        }
                        else
                        {
                            Log(string.Format("Failed to parse the method signature {0}", specificTest.Name));
                        }

                        return;
                    }

                    if (report != null)
                    {
                        Log(
                            string.Format(
                                "{0} did not generate a fluent check:\n{1}",
                                specificTest.Name,
                                e.InnerException.Message));
                    }

                    if (e.InnerException.GetType() != expectedType && expectedType != null)
                    {
                        throw;
                    }
                }
                else
                {
                    if (report != null)
                    {
                        Log(string.Format("{0} failed to run:\n{1}", specificTest.Name, e));
                    }

                    throw;
                }
            }
        }