Hosts several methods helping to execute unit tests in a controlled fashion.
Example #1
0
        // run a set of test
        private static FullRunDescription RunFailingTests(bool log)
        {
            var report = new FullRunDescription();

            // get all test fixtures
            foreach (var type in typeof(GenerateErrorMessages).GetTypeInfo().Assembly.GetExportedTypes())
            {
                try
                {
                    // enumerate testmethods with expectedexception attribute with an FluentException type
                    var tests =
                        type.GetMethods()
                        .Where(method => method.GetCustomAttributes(typeof(TestAttribute), false).Any())
                        .Where(
                            method =>
                    {
                        //var attributes = method.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false);
                        //if (attributes.Length == 1)
                        //{
                        //    var attrib = attributes[0] as ExpectedExceptionAttribute;
                        //    return attrib == null || attrib.ExpectedException == typeof(FluentCheckException);
                        //}
                        throw new NotImplementedException("we have to find a new way since NUnit's ExceptedException has disapeared.");
                    });
                    RunnerHelper.RunThoseTests(tests, type, report, log);
                }
                catch (Exception e)
                {
                    RunnerHelper.Log(string.Format("Exception while working on type:{0}" + Environment.NewLine + "{1}", type.FullName, e));
                }
            }

            return(report);
        }
Example #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)));
        }
Example #3
0
        public void SpecificTest()
        {
            var test = new LambdaRelatedTests();

            // test.SetUp();
            MethodInfo method = test.GetType()
                                .GetMethod(
                "FailDurationTest",
                BindingFlags.Instance | BindingFlags.Public);

            if (method != null)
            {
                RunnerHelper.RunMethod(method, test, null);
            }

            // test.TearDown();
        }
Example #4
0
        public void ScanUnitTestsAndGenerateReport()
        {
            var report = new FullRunDescription();

            // get all test fixtures
            foreach (
                var type in
                Assembly.GetExecutingAssembly()
                .GetTypes())
            {
                try
                {
                    // enumerate testmethods with expectedexception attribute with an FluentException type
                    IEnumerable <MethodInfo> tests =
                        type.GetMethods()
                        .Where(method => method.GetCustomAttributes(typeof(TestAttribute), false).Length > 0)
                        .Where(
                            method =>
                    {
                        object[] attributes =
                            method.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false);
                        if (attributes.Length == 1)
                        {
                            var attrib =
                                attributes[0] as ExpectedExceptionAttribute;
                            return(attrib == null ||
                                   attrib.ExpectedException == typeof(FluentAssertionException));
                        }

                        return(false);
                    });
                    RunnerHelper.RunThoseTests(tests, type, report);
                }
                catch (Exception e)
                {
                    RunnerHelper.Log(string.Format("Exception while working on type:{0}\n{1}", type.FullName, e));
                }
            }

            const string Name = "FluentReport.xml";

            report.Save(Name);
            Debug.Write(string.Format("Report generated in {0}", Path.GetFullPath(Name)));
        }
Example #5
0
        public void ScanUnitTestsAndAssessMessages()
        {
            var report = RunFailingTests(false);

            foreach (var typeChecks in report.RunDescription)
            {
                foreach (var check in typeChecks.Checks)
                {
                    foreach (var checkDescription in check.CheckSignatures)
                    {
                        string error;
                        if (!CheckMessage(checkDescription.ErrorSampleMessage, out error))
                        {
                            // failing
                            RunnerHelper.Log(string.Format("Error for {0}: {1}", checkDescription.Signature, error));
                            RunnerHelper.Log(checkDescription.ErrorSampleMessage);
                            break;
                        }
                    }
                }
            }
        }
Example #6
0
        // run a set of test
        private static FullRunDescription RunFailingTests(bool log)
        {
            var report = new FullRunDescription();

            // get all test fixtures
            foreach (var type in
                     Assembly.GetExecutingAssembly().GetTypes())
            {
                try
                {
                    // enumerate testmethods with expectedexception attribute with an FluentException type
                    var tests =
                        type.GetMethods()
                        .Where(method => method.GetCustomAttributes(typeof(TestAttribute), false).Length > 0)
                        .Where(
                            method =>
                    {
                        var attributes = method.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false);
                        if (attributes.Length == 1)
                        {
                            var attrib = attributes[0] as ExpectedExceptionAttribute;
                            return(attrib == null ||
                                   attrib.ExpectedException == typeof(FluentCheckException));
                        }

                        return(false);
                    });
                    RunnerHelper.RunThoseTests(tests, type, report, log);
                }
                catch (Exception e)
                {
                    RunnerHelper.Log(string.Format("Exception while working on type:{0}\n{1}", type.FullName, e));
                }
            }

            return(report);
        }
Example #7
0
 public void SpecificTest()
 {
     RunnerHelper.RunAction(new LambdaRelatedTests().DidNotRaiseAny);
 }
Example #8
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)));
        }
Example #9
0
 public void Japanese()
 {
     RunnerHelper.RunAllTests();
 }
Example #10
0
 public void CanadianFrench()
 {
     RunnerHelper.RunAllTests();
 }
Example #11
0
 public void Chinese()
 {
     RunnerHelper.RunAllTests();
 }
Example #12
0
 public void Spanish()
 {
     RunnerHelper.RunAllTests();
 }