public IActionResult ExecuteTests() { var nunit = new HW5T1.MyNUnit($"{environment.WebRootPath}/Temp"); nunit.Execute(); var results = nunit.GetAllData(); var assemblyReport = new AssemblyReportModel(); var idPart = DateTime.Now; foreach (var test in results) { var currentReport = new TestReportModel(); currentReport.Name = test.Name; currentReport.Time = test.TimeOfExecution; currentReport.WhyIgnored = test.WhyIgnored; currentReport.Id = idPart.ToString() + '%' + test.Name; if (test.Result == "Success") { currentReport.Passed = true; assemblyReport.Passed++; } else if (test.Result == "Failed") { currentReport.Passed = false; assemblyReport.Failed++; } else { currentReport.Passed = null; assemblyReport.Ignored++; } infoContainer.TestReports.Add(currentReport); archive.Add(currentReport); archive.SaveChanges(); assemblyReport.TestReports.Add(currentReport); } this.currentAssembly = assemblyReport; currentState.AssemblyReports.Add(assemblyReport); return(View("Index", infoContainer.TestReports)); }
/// <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)); }