Exemplo n.º 1
0
        public IActionResult RunTests()
        {
            foreach (var assemblyPath in Directory.EnumerateFiles($"{environment.WebRootPath}/Temp"))
            {
                try
                {
                    var results        = TestRunner.Test(assemblyPath);
                    var assemblyName   = Path.GetFileName(assemblyPath);
                    var testedAssembly = testArchive.AssemblyModels.FirstOrDefault(a => a.Name == assemblyName);

                    if (testedAssembly == null)
                    {
                        testedAssembly = testArchive.AssemblyModels.Add(new AssemblyModel {
                            Name = assemblyName
                        }).Entity;
                        testArchive.SaveChanges();
                    }

                    foreach (var result in results)
                    {
                        var test = new TestModel
                        {
                            Name          = result.Name,
                            ClassName     = result.ClassName,
                            IsPassed      = result.IsPassed,
                            IsIgnored     = result.IsIgnored,
                            IgnoreReason  = result.IgnoreReason,
                            RunTime       = result.RunTime,
                            AssemblyModel = testedAssembly
                        };

                        currentState.Tests.Add(test);
                        testedAssembly.TestModels.Add(test);
                        testArchive.SaveChanges();
                    }
                }
                catch (AggregateException e) when(e.InnerException.GetType() == typeof(TestRunnerException))
                {
                    return(View("TestRunnerError", e.InnerException.Message));
                }
            }

            return(View("TestRunner", currentState));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs tests in all assemblies in the temporary directory
        /// </summary>
        public IActionResult Test()
        {
            try
            {
                var reports  = TestRunner.RunTests($"{environment.WebRootPath}/Temp");
                var dateTime = DateTime.Now;
                var results  = new List <AssemblyReportModel>();
                foreach (var testClassReport in reports)
                {
                    var assemblyReports = currentState.AssemblyReports.Where(r => r.Name == testClassReport.AssemblyName);
                    var assemblyReport  = assemblyReports.FirstOrDefault();
                    if (assemblyReports.Count() == 0)
                    {
                        assemblyReport = new AssemblyReportModel {
                            Name = testClassReport.AssemblyName, Id = dateTime.ToString() + testClassReport.AssemblyName
                        };
                        currentState.AssemblyReports.Add(assemblyReport);
                        results.Add(assemblyReport);
                    }
                    foreach (var test in testClassReport.Reports)
                    {
                        var newTestReportModel = new TestReportModel
                        {
                            ClassName = testClassReport.ClassName,
                            Valid     = true,
                            Name      = test.Name,
                            Passed    = test.Ignored ? null : test.Passed,
                            Time      = test.Ignored ? null : test.Time,
                            Message   = test.Message,
                            Id        = dateTime.ToString() + test.Name + testClassReport.ClassName
                        };
                        if (test.Passed == true)
                        {
                            assemblyReport.Passed++;
                        }
                        else if (test.Passed == false)
                        {
                            assemblyReport.Failed++;
                        }
                        else
                        {
                            assemblyReport.Ignored++;
                        }

                        assemblyReport.TestReports.Add(newTestReportModel);
                    }
                }
                var newRunReport = new TestRunModel
                {
                    DateTime        = DateTime.Now,
                    AssemblyReports = results
                };
                archive.Add(newRunReport);
                archive.SaveChanges();
            }
            catch (InvalidAssemlyException e)
            {
                var reports = e.InvalidClasses;
                foreach (var testClassReport in reports)
                {
                    var assemblyReports = currentState.AssemblyReports.Where(r => r.Name == testClassReport.AssemblyName);
                    var assemblyReport  = assemblyReports.FirstOrDefault();
                    if (assemblyReports.Count() == 0)
                    {
                        assemblyReport = new AssemblyReportModel {
                            Name = testClassReport.AssemblyName
                        };
                        currentState.AssemblyReports.Add(assemblyReport);
                    }
                    foreach (var test in testClassReport.InvalidMethods)
                    {
                        var newTestReportModel = new TestReportModel
                        {
                            ClassName = testClassReport.Name,
                            Valid     = false,
                            Name      = test.Name,
                            Passed    = null,
                            Time      = null,
                            Message   = String.Join("\n", test.Errors)
                        };

                        assemblyReport.TestReports.Add(newTestReportModel);
                    }
                }
            }

            return(View("Index", currentState));
        }