public async Task <ActionResult> Upload(IFormFileCollection files) { await using var repository = new Repository(); var currentTestRun = new TestRun { LaunchedAt = DateTime.Now, Source = new List <AssemblyFile>(), Report = new List <TestInfoModel>() }; if (files.Count > 0) { foreach (var file in files) { using var reader = new BinaryReader(file.OpenReadStream()); currentTestRun.Source.Add(new AssemblyFile { Id = Guid.NewGuid(), Name = file.FileName, Content = reader.ReadBytes((int)file.Length) }); } } else { return(RedirectToAction("NoFilesAttached", "home"));; } files = new FormFileCollection(); var result = MyNUnit.RunTestsAndGetReport(currentTestRun.Source. Select(s => s.Content)). SelectMany(dict => dict.Value). Select(testInfo => new TestInfoModel { Id = Guid.NewGuid(), ActualException = testInfo.ActualException?.ToString(), ExpectedException = testInfo.ExpectedException?.ToString(), IsIgnored = testInfo.IsIgnored, IsSuccessful = testInfo.IsSuccessful, MethodName = testInfo.MethodName, ReasonToIgnore = testInfo.ReasonToIgnore, Time = testInfo.Time.ToString() }) .ToList(); foreach (var testInfoModel in result) { currentTestRun.Report.Add(testInfoModel); } await repository.AddAsync(currentTestRun); await repository.SaveChangesAsync(); return(RedirectToAction("ListReports", "home")); }
public void PassedTests() { tests = new MyNUnit("../../../../PassedTests"); tests.ClassQueue.TryDequeue(out var info); var infoArray = info.ToArray(); var answer1 = IsEqual(infoArray[0], "SucceededTest1", "Passed", null) && IsEqual(infoArray[1], "SucceededTest2", "Passed", null); var answer2 = IsEqual(infoArray[0], "SucceededTest2", "Passed", null) && IsEqual(infoArray[1], "SucceededTest1", "Passed", null); Assert.IsTrue(answer1 || answer2); }
public void FailedTests() { tests = new MyNUnit("../../../../FailedTests"); tests.ClassQueue.TryDequeue(out var info); var infoArray = info.ToArray(); var answer1 = IsEqual(infoArray[0], "FailedTest1", "Failed", "Exception has been thrown by the target of an invocation.") && IsEqual(infoArray[1], "FailedTest2", "Failed", "Exception has been thrown by the target of an invocation."); var answer2 = IsEqual(infoArray[1], "FailedTest1", "Failed", "Exception has been thrown by the target of an invocation.") && IsEqual(infoArray[0], "FailedTest2", "Failed", "Exception has been thrown by the target of an invocation."); Assert.IsTrue(answer1 || answer2); }
public void SetOfSuccessCaseTest() { nunit = new MyNUnit("../../../../SuccessTests"); nunit.Execute(); var allData = nunit.GetAllData(); Assert.AreEqual(1, allData.Count); Assert.AreEqual(allData[0].Result, Result.Success); Assert.IsTrue(String.Equals(allData[0].Name, "RandomTest1") && String.Equals(allData[0].WhyIgnored, null) && allData[0].TimeOfExecution == 0); }
public void RegularTestPassedTest() { var resultsTestPath = path; var regularTestsReport = MyNUnit.RunTestsAndGetReport(resultsTestPath); foreach (var list in regularTestsReport.Values) { foreach (var info in list) { TestsResults.Add(info); } } var successInfo = TestsResults.Find(i => i.MethodName == "SuccessfulMethod"); Assert.IsTrue(successInfo.IsSuccessful); }
public void ExpectedExceptionTest() { var resultsTestPath = path; var regularTestsReport = MyNUnit.RunTestsAndGetReport(resultsTestPath); foreach (var list in regularTestsReport.Values) { foreach (var info in list) { TestsResults.Add(info); } } var expectedInfo = TestsResults.Find(i => i.MethodName == "ExpectedExceptionThrown"); Assert.AreEqual(expectedInfo.ExpectedException, expectedInfo.ActualException); Assert.IsTrue(expectedInfo.IsSuccessful); }
public void FailExceptionTest() { var resultsTestPath = path; var regularTestsReport = MyNUnit.RunTestsAndGetReport(resultsTestPath); foreach (var list in regularTestsReport.Values) { foreach (var info in list) { TestsResults.Add(info); } } var failInfo = TestsResults.Find(i => i.MethodName == "ExceptionOnFail"); Assert.IsNull(failInfo.ExpectedException); Assert.IsNotNull(failInfo.ActualException); Assert.IsFalse(failInfo.IsSuccessful); }
public void IgnoreTest() { var resultsTestPath = path; var regularTestsReport = MyNUnit.RunTestsAndGetReport(resultsTestPath); foreach (var list in regularTestsReport.Values) { foreach (var info in list) { TestsResults.Add(info); } } var ignoreInfo = TestsResults.Find(i => i.MethodName == "IgnoreMethod"); var exceptionIgnoreInfo = TestsResults.Find(i => i.MethodName == "IgnoreMethodThrowingException"); Assert.IsTrue(ignoreInfo.IsIgnored); Assert.AreEqual("Some reason to ignore this test.", ignoreInfo.ReasonToIgnore); Assert.IsTrue(exceptionIgnoreInfo.IsIgnored); }
public void CorrectMethodsAreTestedTest() { var resultsTestPath = path; var regularTestsReport = MyNUnit.RunTestsAndGetReport(resultsTestPath); foreach (var list in regularTestsReport.Values) { foreach (var info in list) { TestsResults.Add(info); } } var names = new List <string>(); foreach (var res in TestsResults) { names.Add(res.MethodName); } Assert.AreEqual(names.Intersect(expectedResultsMethods).Count(), expectedResultsMethods.Count); }
public void Setup() { myNUnit = new(); }
/// <summary> /// Controller constructor. /// </summary> public HomeController() { homeRepository = new(); myNUnit = new(); }