public void UploadResult(int?id, IFormCollection Form) { TestRun testRun = _context.TestRun.Single(t => t.TestRunID == id); Test test = _context.Test.Single(t => t.TestID == testRun.TestID); var TestReportContents = Form.Single(t => t.Key == "TestReportDetails").Value; TestReportDetails testReportDetails = JsonConvert.DeserializeObject <TestReportDetails>(TestReportContents); var DateTimeForFilename = StringClass.sanitiseDateTimeStringForFilename(testReportDetails.strStartTime); var frameworkLogDirectory = Path.Combine("TestRunnerLogs", DateTimeForFilename); Directory.CreateDirectory(frameworkLogDirectory); var frameworkLogFilePath = Path.Combine("TestRunnerLogs", DateTimeForFilename, Form.First().Key); System.IO.File.WriteAllText(frameworkLogFilePath, Form.First().Value); AddTestRunnerLog(frameworkLogFilePath, Form.First().Key, testRun.TestRunner.Value, DateTimeForFilename); var resultDirectory = Path.Combine(strResultsDirectory, testRun.TestRunID.ToString(), DateTimeForFilename); Directory.CreateDirectory(resultDirectory); string screenshotList = Form.Single(t => t.Key == "ListOfScreenshots").Value; List <ScreenshotDetails> ListOfScreenshotDetails = JsonConvert.DeserializeObject <List <ScreenshotDetails> >(screenshotList); var screenshotFolder = Path.Combine(strScreenshotsDirectory, testRun.TestRunID.ToString(), DateTimeForFilename); Directory.CreateDirectory(screenshotFolder); var ResultID = AddResultOfID(testRun, resultDirectory, screenshotFolder, testReportDetails, test, testRun.TestEnvironmentID.Value); string stepDetailsList = Form.Single(t => t.Key == "ListOfStepDetails").Value; List <StepDetails> ListOfStepDetails = JsonConvert.DeserializeObject <List <StepDetails> >(stepDetailsList); StoreStepDetailsList(ListOfStepDetails, ResultID); StoreScreenshotDetailsList(ListOfScreenshotDetails, screenshotFolder, ResultID); foreach (var item in ListOfScreenshotDetails) { string imageString = Form.Single(t => t.Key == item.strStepID).Value; byte[] imageByteArray = JsonConvert.DeserializeObject <byte[]>(imageString); var screenshotFilePath = Path.Combine(screenshotFolder, item.strStepID); System.IO.File.WriteAllBytes(screenshotFilePath + ".png", imageByteArray); } }
private int AddResultOfID(TestRun TestRun, string ResultDirectory, string ScreenshotsDirectory, TestReportDetails TestReportDetails, Test Test, int TestEnvironmentID) { Result result = new Result(); _context.Result.Add(result); result.ResultName = TestReportDetails.TestName; result.ResultDirectory = ResultDirectory; result.ScreenshotsDirectory = ScreenshotsDirectory; result.StoredStatus = TestReportDetails.TestStatus; result.StepsPassed = TestReportDetails.StepsPassed; result.StepsFailed = TestReportDetails.StepsFailed; result.StepsBlocked = TestReportDetails.StepsBlocked; result.StoredStartTime = Convert.ToDateTime(TestReportDetails.strStartTime); result.StoredEndTime = Convert.ToDateTime(TestReportDetails.strEndTime); result.Duration = Convert.ToDateTime(TestReportDetails.Duration); result.StoredBrowser = TestReportDetails.Browser; result.TestRunID = TestRun.TestRunID; result.StoredTestID = Test.TestID; result.StoredTestName = Test.Name; if (Test.TestDataSource == "Excel") { var ExcelFilename = Test.ExcelFilePath; result.StoredTestDataFileName = ExcelFilename; var TestDataFilePath = Path.Combine(_environment.WebRootPath, "uploads", "tests", Test.TestID.ToString(), ExcelFilename); var testDirectory = Path.Combine(ResultDirectory, "test"); Directory.CreateDirectory(testDirectory); var StoredTestDataFilePath = Path.Combine(testDirectory, ExcelFilename); System.IO.File.Copy(TestDataFilePath, StoredTestDataFilePath); result.StoredTestDataFileContentType = Test.ContentType; } var environmentDirectory = Path.Combine(ResultDirectory, "environment"); Directory.CreateDirectory(environmentDirectory); TestEnvironment testEnvironment = _context.TestEnvironment.Single(t => t.TestEnvironmentID == TestEnvironmentID); result.StoredTestEnvironmentID = TestEnvironmentID; var TestEnvironmentFileName = testEnvironment.XMLFilePath; result.StoredTestEnvironmentFileName = TestEnvironmentFileName; result.StoredTestEnvironmentName = testEnvironment.Name; var EnvironmentDataFilePath = Path.Combine(_environment.WebRootPath, "uploads", "environments", TestEnvironmentID.ToString(), TestEnvironmentFileName); var StoredEnvironmentFilePath = Path.Combine(environmentDirectory, TestEnvironmentFileName); System.IO.File.Copy(EnvironmentDataFilePath, StoredEnvironmentFilePath); result.StoredTestEnvironmentFileContentType = testEnvironment.ContentType; result.StoredTestRunnerID = TestRun.TestRunner.Value; result.StoredTestRunnerName = _context.TestRunner.Single(t => t.TestRunnerID == TestRun.TestRunner.Value).Name; _context.SaveChanges(); return result.ResultID; }
private int AddResultOfID(TestRun TestRun, string ResultDirectory, string ScreenshotsDirectory, TestReportDetails TestReportDetails, Test Test, int TestEnvironmentID) { Result result = new Result(); _context.Result.Add(result); result.ResultName = TestReportDetails.TestName; result.ResultDirectory = ResultDirectory; result.ScreenshotsDirectory = ScreenshotsDirectory; result.StoredStatus = TestReportDetails.TestStatus; result.StepsPassed = TestReportDetails.StepsPassed; result.StepsFailed = TestReportDetails.StepsFailed; result.StepsBlocked = TestReportDetails.StepsBlocked; result.StoredStartTime = Convert.ToDateTime(TestReportDetails.strStartTime); result.StoredEndTime = Convert.ToDateTime(TestReportDetails.strEndTime); result.Duration = Convert.ToDateTime(TestReportDetails.Duration); result.StoredBrowser = TestReportDetails.Browser; result.TestRunID = TestRun.TestRunID; result.StoredTestID = Test.TestID; result.StoredTestName = Test.Name; if (Test.TestDataSource == "Excel") { var ExcelFilename = Test.ExcelFilePath; result.StoredTestDataFileName = ExcelFilename; var TestDataFilePath = Path.Combine(_environment.WebRootPath, "uploads", "tests", Test.TestID.ToString(), ExcelFilename); var testDirectory = Path.Combine(ResultDirectory, "test"); Directory.CreateDirectory(testDirectory); var StoredTestDataFilePath = Path.Combine(testDirectory, ExcelFilename); System.IO.File.Copy(TestDataFilePath, StoredTestDataFilePath); result.StoredTestDataFileContentType = Test.ContentType; } var environmentDirectory = Path.Combine(ResultDirectory, "environment"); Directory.CreateDirectory(environmentDirectory); TestEnvironment testEnvironment = _context.TestEnvironment.Single(t => t.TestEnvironmentID == TestEnvironmentID); result.StoredTestEnvironmentID = TestEnvironmentID; var TestEnvironmentFileName = testEnvironment.XMLFilePath; result.StoredTestEnvironmentFileName = TestEnvironmentFileName; result.StoredTestEnvironmentName = testEnvironment.Name; var EnvironmentDataFilePath = Path.Combine(_environment.WebRootPath, "uploads", "environments", TestEnvironmentID.ToString(), TestEnvironmentFileName); var StoredEnvironmentFilePath = Path.Combine(environmentDirectory, TestEnvironmentFileName); System.IO.File.Copy(EnvironmentDataFilePath, StoredEnvironmentFilePath); result.StoredTestEnvironmentFileContentType = testEnvironment.ContentType; result.StoredTestRunnerID = TestRun.TestRunner.Value; result.StoredTestRunnerName = _context.TestRunner.Single(t => t.TestRunnerID == TestRun.TestRunner.Value).Name; _context.SaveChanges(); return(result.ResultID); }