public static void AppendAsXml(this TestCaseReport self, ref StringBuilder sb, string tabbing) { // We used to check self.message, but some tests write a message on passing tests. Despite this being against the standard, we've decided it's ok (because we can test other things with that feedback) var isSingleLine = self.IsXmlSingleLine(); self.AppendTestCaseLine(ref sb, isSingleLine, tabbing); if (isSingleLine) { return; // Nothing else is written if it's a single line } // Escape HTML Characters self.message = HttpUtility.HtmlEncode(self.message); self.failureText = HttpUtility.HtmlEncode(self.failureText); tabbing += " "; if (self.finishState == UUnitFinishState.SKIPPED) { sb.Append(tabbing).Append("<skipped />\n"); } else if (string.IsNullOrEmpty(self.failureText)) { sb.Append(tabbing).AppendFormat("<failure message=\"{0}\">{1}</failure>\n", self.message, self.finishState.ToString()); } else { sb.Append(tabbing).AppendFormat("<failure message=\"{0}\">{1}</failure>\n", self.message, self.failureText); } tabbing = tabbing.Substring(2); sb.Append(tabbing).Append("</testcase>\n"); }
public static void AppendAsXml(this TestCaseReport self, ref StringBuilder sb, string tabbing) { bool isSingleLine = string.IsNullOrEmpty(self.message) && self.finishState == TestFinishState.PASSED; self.AppendTestCaseLine(ref sb, isSingleLine, tabbing); if (isSingleLine) { return; // Nothing else is written if it's a single line } tabbing += " "; if (self.finishState == TestFinishState.SKIPPED) { sb.Append(tabbing).Append("<skipped />\n"); } else if (string.IsNullOrEmpty(self.failureText)) { sb.Append(tabbing).AppendFormat("<failure message=\"{0}\">{1}</failure>\n", self.message, self.finishState.ToString()); } else { sb.Append(tabbing).AppendFormat("<failure message=\"{0}\">{1}</failure>\n", self.message, self.failureText); } tabbing = tabbing.Substring(2); sb.Append(tabbing).Append("</testcase>\n"); }
public static List <TestSuiteReport> ParseXmlFile(string filename) { if (!File.Exists(filename)) { return(outputReport); } string xmlString = File.ReadAllText(filename); using (XmlReader reader = XmlReader.Create(new StringReader(xmlString))) { outputReport = null; curReport = null; _curSuiteReport = null; _curTestCaseReport = null; // Parse the file and display each of the nodes. while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.XmlDeclaration: case XmlNodeType.Whitespace: break; // We simply accept that this exists, but otherwise don't really process it case XmlNodeType.Element: bool isEmptyElement = reader.IsEmptyElement; ParseElementStart(reader, isEmptyElement); if (isEmptyElement) { ParseElementEnd(reader, true); } break; case XmlNodeType.Text: TestFinishState tempState; if (Enum.TryParse(reader.Value, true, out tempState)) { _curTestCaseReport.finishState = tempState; } else { _curTestCaseReport.failureText = reader.Value; } break; case XmlNodeType.EndElement: ParseElementEnd(reader, false); break; default: throw new Exception("Unexpected xml node: " + reader.NodeType); } } } return(outputReport); }
private static void ParseElementStart(XmlReader reader, bool isEmptyElement) { double tempSeconds; switch (reader.Name) { case ("testsuites"): _curReport = new List <TestSuiteReport>(); break; case ("testsuite"): _curSuiteReport = new TestSuiteReport { name = reader.GetAttribute("name") }; int.TryParse(reader.GetAttribute("errors"), out _curSuiteReport.errors); int.TryParse(reader.GetAttribute("tests"), out _curSuiteReport.tests); int.TryParse(reader.GetAttribute("failures"), out _curSuiteReport.failures); int.TryParse(reader.GetAttribute("skipped"), out _curSuiteReport.skipped); double.TryParse(reader.GetAttribute("time"), out tempSeconds); _curSuiteReport.time = TimeSpan.FromSeconds(tempSeconds); DateTime.TryParseExact(reader.GetAttribute("timestamp"), PlayFabUtil.DefaultDateTimeFormats, null, System.Globalization.DateTimeStyles.RoundtripKind, out _curSuiteReport.timestamp); break; case ("properties"): _curSuiteReport.properties = new Dictionary <string, string>(); break; case ("property"): _curSuiteReport.properties[reader.GetAttribute("name")] = reader.GetAttribute("value"); break; case ("testcase"): _curTestCaseReport = new TestCaseReport { classname = reader.GetAttribute("classname"), name = reader.GetAttribute("name"), finishState = isEmptyElement ? UUnitFinishState.PASSED : UUnitFinishState.FAILED, // Empty element means no notes about failure, non-empty will almost certainly override this value }; double.TryParse(reader.GetAttribute("time"), out tempSeconds); _curTestCaseReport.time = TimeSpan.FromSeconds(tempSeconds); break; case ("failure"): _curTestCaseReport.finishState = UUnitFinishState.FAILED; _curTestCaseReport.message = reader.GetAttribute("message"); break; case ("skipped"): _curTestCaseReport.finishState = UUnitFinishState.SKIPPED; _curTestCaseReport.message = reader.GetAttribute("message"); break; default: throw new Exception("Unexpected element: " + reader.Name); } }
public static void GradeSubmission(Submission submission, AutoGraderDbContext dbContext) { AssignmentDataService assignmentDataService = new AssignmentDataService(dbContext); Assignment assignment = assignmentDataService.GetAssignmentById(submission.AssignmentId); submission.Output.MemoryLimit = assignment.MemoryLimit; TestCaseDataService testCaseDataService = new TestCaseDataService(dbContext); IEnumerable <TestCaseSpecification> testCaseSpecifications = testCaseDataService.GetTestCaseByAssignmentId(submission.AssignmentId); foreach (TestCaseSpecification testCaseSpecification in testCaseSpecifications) { TestCaseReport testCaseReport = new TestCaseReport(); testCaseReport.CodeInput = testCaseSpecification.Input; testCaseReport.ExpectedOutput = testCaseSpecification.ExpectedOutput; testCaseReport.Feedback = testCaseSpecification.Feedback; submission.Output.TestCases.Add(testCaseReport); } /* if (submission.Compile()) * { * submission.RunAndCompare(); * } * else * { * for (int i = 0; i < submission.Output.TestCases.Count(); i++) * { * submission.Output.TestCases[i].Pass = false; * } * } * * SubmissionService submissionService = new SubmissionService(dbContext); * submissionService.AddSubmission(submission); */ // Send the Submission to the compiler and get the output back // Object returned with contain a pass or fail bool, and compiler output // if it did not compile correctly, make the output the error message // Print out compiler output // Mark all test cases on the report as failed in submissionOutput // else // Call the method to populate CodeInput, ExpectedOutput, Feedback -- Add in 10/30 // call the grading function passing the submission, ** 2d array of input output files/or assignment ID **, source code, language, runtime, and submission id // get back the submission with the chekced fields updated // Update the database for the report ID to say which test cases were passed and save the output string for each // return submission / submission output to the user }
private static void ParseElementEnd(XmlReader reader) { switch (reader.Name) { case ("testsuites"): _outputReport = _curReport; break; case ("testsuite"): _curReport.Add(_curSuiteReport); _curSuiteReport = null; break; case ("properties"): break; case ("property"): break; case ("testcase"): if (_curSuiteReport.testResults == null) { _curSuiteReport.testResults = new List <TestCaseReport>(); } _curSuiteReport.testResults.Add(_curTestCaseReport); _curTestCaseReport = null; break; case ("failure"): break; case ("skipped"): break; default: throw new Exception("Unexpected element: " + reader.Name); } }
private static void AppendTestCaseLine(this TestCaseReport self, ref StringBuilder sb, bool isSingleLine, string tabbing) { var suffix = isSingleLine ? " /" : ""; sb.Append(tabbing).AppendFormat("<testcase classname=\"{0}\" name=\"{1}\" time=\"{2}\"{3}>\n", self.classname, self.name, self.time.TotalSeconds.ToString("0.###"), suffix); }
public static bool IsXmlSingleLine(this TestCaseReport self) { return(self.finishState == UUnitFinishState.PASSED); }