public PostResultDTO RecordTestRun(TestStatusDTO dto) { FTPFileNameCleanup.CleanupAnyFiles(); return(testManager.RecordTestRun(dto)); }
public PostResultDTO RecordTestRun(TestStatusDTO dto) { string descriptor = ""; try { var application = this.RetrieveApplication(dto.ApplicationId); if (application == null) { throw new Exception("Unable to find application: " + dto.ApplicationId); } var test = dbContext.Tests.FirstOrDefault(t => t.TestNumber == dto.TestNumber && t.ApplicationId == application.ApplicationId); if (test == null) { throw new Exception("Unable to find test number: " + dto.TestNumber); } descriptor = "Check if run already exists"; Guid runId = Guid.Parse(dto.RunId); var run = dbContext.Runs.FirstOrDefault(r => r.RunGuid == runId); if (run == null) { descriptor = "Create new Run record"; run = new Run() { DateStarted = DateTime.Now, DateEnded = DateTime.Now, RunGuid = runId }; dbContext.Runs.Add(run); dbContext.SaveChanges(); run = dbContext.Runs.FirstOrDefault(r => r.RunGuid == runId); } descriptor = "Create new TestRun"; run.DateEnded = DateTime.Now; TestRun testRun = new TestRun() { TestId = test.TestId, RunId = run.RunId, RunDate = dto.RunDate, TestReportLink = "TestReports/" + dto.FTPPath, TimeToRun = dto.TestTime, RunStatus = (TestRun.TestRunStatusEnumeration)dto.Status, }; dbContext.TestRuns.Add(testRun); if (test.CurrentStatus == ORMModel.Test.TestDefinitionStatusEnumeration.UnderDevelopment) { test.CurrentStatus = ORMModel.Test.TestDefinitionStatusEnumeration.Active; test.FirstActivated = DateTime.Now; } dbContext.SaveChanges(); return(new PostResultDTO() { Successful = true }); } catch (Exception exp) { return(new PostResultDTO() { Successful = false, ErrorMessage = exp.ToString(), ErrorType = exp.GetType().ToString(), Payload = descriptor }); } }