static void Tests() { testcase[] cases = new testcase[] { new testcase(new int[] { 0, 0, 1, 0, 0, 1, 1, 0 }, 2, 92) }; bool fail = false; for (int i = 0; i < cases.Length; i++) { int givenAns = jumpingOnClouds(cases[i].c, cases[i].k); if (givenAns != cases[i].expectedAns) { Console.WriteLine("Error test {0}\nGiven ans:{1}\nCorrect ans:{2}", i + 1, givenAns, cases[i].expectedAns); fail = true; } } if (!fail) { Console.WriteLine("All tests passed!"); Console.Beep(); } Console.ReadKey(); }
public JsonResult GetTestCaseAsJSON(int?id) { int testId = Convert.ToInt32(id); testcase test = problmService.GetTestCaseById(testId); return(Json(new { input = test.input, output = test.output }, JsonRequestBehavior.AllowGet)); }
private testcase CreateXmlFromUFTRunResults(TestRunResults testRes) { string baseClassName = "GUI-Tests"; string testName = testRes.TestName; if (string.IsNullOrEmpty(testName) && !string.IsNullOrEmpty(testRes.ReportLocation)) { testName = Directory.GetParent(testRes.ReportLocation).Name; } testcase tc = new testcase { name = testName, systemout = testRes.ConsoleOut, systemerr = testRes.ConsoleErr, report = testRes.ReportLocation, classname = baseClassName + "." + ((testRes.TestGroup == null) ? "" : testRes.TestGroup.Replace(".", "_")), type = testRes.TestType, time = testRes.Runtime.TotalSeconds.ToString() }; if (!string.IsNullOrWhiteSpace(testRes.FailureDesc)) { tc.AddFailure(new failure { message = testRes.FailureDesc }); } switch (testRes.TestState) { case TestState.Passed: tc.status = "pass"; break; case TestState.Failed: tc.status = "fail"; break; case TestState.Error: tc.status = "error"; break; case TestState.Warning: tc.status = "warning"; break; default: tc.status = "pass"; break; } if (!string.IsNullOrWhiteSpace(testRes.ErrorDesc)) { tc.AddError(new error { message = testRes.ErrorDesc }); } return(tc); }
public static IEnv GetEnv(this testcase testcase) { var env = new Env(); env.Patient = testcase.Patient.ToEhr(testcase.Doses); env.AssessmentDate = testcase.AssessmentDate; return(env); }
/// <summary> /// converts all data from the test results in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public bool CreateXmlFromRunResults(TestSuiteRunResults results, out string error) { error = string.Empty; _testSuites = new testsuites(); testsuite uftts = new testsuite { errors = IntToString(results.NumErrors), tests = IntToString(results.NumTests), failures = IntToString(results.NumFailures), name = results.SuiteName, package = ClassName, time = DoubleToString(results.TotalRunTime.TotalSeconds) }; foreach (TestRunResults testRes in results.TestRuns) { if (testRes.TestType == TestType.LoadRunner.ToString()) { testsuite lrts = CreateXmlFromLRRunResults(testRes); _testSuites.AddTestsuite(lrts); } else { testcase ufttc = CreateXmlFromUFTRunResults(testRes); uftts.AddTestCase(ufttc); } } if (uftts.testcase.Length > 0) { _testSuites.AddTestsuite(uftts); } try { if (File.Exists(XmlName)) { File.Delete(XmlName); } using (Stream s = File.OpenWrite(XmlName)) { _serializer.Serialize(s, _testSuites); } return(File.Exists(XmlName)); } catch (Exception ex) { error = ex.Message; return(false); } }
private testsuite CreateXmlFromLRRunResults(TestRunResults testRes) { testsuite lrts = new testsuite(); int totalTests = 0, totalFailures = 0, totalErrors = 0; string resultFileFullPath = testRes.ReportLocation + "\\SLA.xml"; if (File.Exists(resultFileFullPath)) { try { XmlDocument xdoc = new XmlDocument(); xdoc.Load(resultFileFullPath); foreach (XmlNode childNode in xdoc.DocumentElement.ChildNodes) { if (childNode.Attributes != null && childNode.Attributes["FullName"] != null) { testRes.TestGroup = testRes.TestPath; testcase lrtc = CreateXmlFromUFTRunResults(testRes); lrtc.name = childNode.Attributes["FullName"].Value; if (childNode.InnerText.ToLowerInvariant().Contains("failed")) { lrtc.status = "fail"; totalFailures++; } else if (childNode.InnerText.ToLowerInvariant().Contains("passed")) { lrtc.status = "pass"; lrtc.error = new error[] { }; } totalErrors += lrtc.error.Length; lrts.AddTestCase(lrtc); totalTests++; } } } catch (System.Xml.XmlException) { } } lrts.name = testRes.TestPath; lrts.tests = totalTests.ToString(); lrts.errors = totalErrors.ToString(); lrts.failures = totalFailures.ToString(); lrts.time = testRes.Runtime.TotalSeconds.ToString(); return(lrts); }
public JsonResult DeleteProblem(string id) { if (id == null) { return(Json(new { status = "failed" }, JsonRequestBehavior.AllowGet)); } int prbId = Convert.ToInt32(id); problem prob = db.problem.Find(prbId); problems prob2 = problmService.GetConnectionById(prbId); int aId = prob2.id; //because errors problems probs = db.problems.Find(aId); List <testcase> cases = problmService.getTestCasesOfProblem(prbId); foreach (var item in cases) { db.testcaseOutput.RemoveRange(db.testcaseOutput.Where(b => b.testcaseId == item.id)); } foreach (var item in cases) { int bId = item.id; testcase tst = db.testcase.Find(bId); db.testcase.Remove(tst); } db.testcases.RemoveRange(db.testcases.Where(b => b.problemId == prbId)); List <clarification> clars = clarificationService.getClarificationsOfProblem(prbId); foreach (var item in clars) { db.clarificationAnswer.RemoveRange(db.clarificationAnswer.Where(b => b.clarificationId == item.id)); } foreach (var item in clars) { int cId = item.id; clarification clr = db.clarification.Find(cId); db.clarification.Remove(clr); } db.clarifications.RemoveRange(db.clarifications.Where(b => b.problemId == prbId)); db.problem.Remove(prob); db.problems.Remove(probs); db.SaveChanges(); return(Json(new { status = "successRemove" }, JsonRequestBehavior.AllowGet)); }
public void TestCreateUnspent() { var p = new cipher_PubKey(); var s = new cipher_SecKey(); var a = new cipher__Address(); var err = SKY_cipher_GenerateKeyPair(p, s); Assert.AreEqual(err, SKY_OK); err = SKY_cipher_AddressFromPubKey(p, a); Assert.AreEqual(err, SKY_OK); var h = new cipher_SHA256(); var handle = new_Transaction__Handlep(); makeEmptyTransaction(handle); err = SKY_coin_Transaction_PushOutput(handle, a, 11000000, 255); Assert.AreEqual(err, SKY_OK); var bh = new coin__BlockHeader(); bh.Time = 0; bh.BkSeq = 1; testcase[] t = new testcase[2]; var tc = new testcase(); tc.index = 0; tc.failure = SKY_OK; t[0] = tc; tc = new testcase(); tc.failure = SKY_ERROR; tc.index = 10; t[1] = tc; var ux = new coin__UxOut(); var tests_count = t.Length; for (int i = 0; i < tests_count; i++) { err = SKY_coin_CreateUnspent(bh, handle, t[i].index, ux); if (t[i].failure == SKY_ERROR) { continue; } Assert.AreEqual(bh.Time, ux.Head.Time); Assert.AreEqual(bh.BkSeq, ux.Head.BkSeq); } }
/// <summary> /// converts all data from the test results in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public void CreateXmlFromRunResults(TestSuiteRunResults results) { _testSuites = new testsuites(); testsuite uftts = new testsuite { errors = results.NumErrors.ToString(), tests = results.NumTests.ToString(), failures = results.NumFailures.ToString(), name = results.SuiteName, package = ClassName }; foreach (TestRunResults testRes in results.TestRuns) { if (testRes.TestType == TestType.LoadRunner.ToString()) { testsuite lrts = CreateXmlFromLRRunResults(testRes); _testSuites.AddTestsuite(lrts); } else { testcase ufttc = CreateXmlFromUFTRunResults(testRes); uftts.AddTestCase(ufttc); } } if (uftts.testcase.Length > 0) { _testSuites.AddTestsuite(uftts); } if (File.Exists(XmlName)) { File.Delete(XmlName); } using (Stream s = File.OpenWrite(XmlName)) { _serializer.Serialize(s, _testSuites); } }
public JsonResult DeleteTestCase(string id) { if (id == null) { return(Json(new { status = "failed" }, JsonRequestBehavior.AllowGet)); } int tstId = Convert.ToInt32(id); testcase test = db.testcase.Find(tstId); testcases tests = problmService.GetTestCaseConnectionById(tstId); int aId = tests.id; //because errors testcases tests2 = db.testcases.Find(aId); db.testcaseOutput.RemoveRange(db.testcaseOutput.Where(b => b.testcaseId == tstId)); db.testcase.Remove(test); db.testcases.Remove(tests2); db.SaveChanges(); return(Json(new { status = "successRemove" }, JsonRequestBehavior.AllowGet)); }
private testcase MapToTestCase(Keyword keyword) { testcase testCase = new testcase(); testCase.name = keyword.Description; if (KeywordStatus.Error.ToString().Equals(keyword.Status)) { error caseError = new error(); caseError.message = keyword.StatusDetail; testCase.error = new [] { caseError }; } if (KeywordStatus.Skipped.ToString().Equals(keyword.Status) || keyword.Status == null) { testCase.skipped = new skipped(); } testCase.time = keyword.Time.ToString(); return(testCase); }
public JsonResult AddTestCase(int?id, FormCollection collection) { if (id == null || collection["input"] == null) { return(Json(new { status = "failed" }, JsonRequestBehavior.AllowGet)); } testcase newTest = new testcase { input = collection["input"], output = collection["output"] }; db.testcase.Add(newTest); db.SaveChanges(); testcases newConnection = new testcases { testcaseId = db.testcase.Max(x => x.id), problemId = Convert.ToInt32(id) }; db.testcases.Add(newConnection); db.SaveChanges(); int testId = db.problem.Max(x => x.id); return(Json(new { status = "SuccessAdd", testcaseId = testId }, JsonRequestBehavior.AllowGet)); }
public int addTestcases(Excel.Worksheet sheet, DefaultTC itc, int row) { itc.InitialTestcase(sheet, row); // testsuite ts=addItems(4,itc.GetCell(DefaultTC.colName.FEATUREID),itc.GetCell(DefaultTC.colName.FEATURE_DESC)); string detail = itc.GetCell(DefaultTC.colName.FEATUREID) + ":" + itc.GetCell(DefaultTC.colName.CASE_DESC); testsuite ts = addItems(4, itc.GetCell(DefaultTC.colName.FEATURE_DESC), detail); string preset = itc.GetCell(DefaultTC.colName.PRESET); List <string> steps = itc.getSteps(); List <string> exp = itc.getExpRsts(); string req = itc.GetCell(DefaultTC.colName.DS_ID); bool can_auto = itc.GetCell(DefaultTC.colName.CAN_AUTO).ToLower().Equals("true"); string importance = itc.GetCell(DefaultTC.colName.PRIORITY).ToLower(); string testtype = itc.GetCell(DefaultTC.colName.TYPE); uint order = 0; while (true) { row++; string c0 = itc.GetSubCase(row, DefaultTC.subColName.ID0); string c1 = itc.GetSubCase(row, DefaultTC.subColName.ID); if (c0.Length != 0 || c1.Length == 0) { row--; return(row); } string c2 = itc.GetSubCase(row, DefaultTC.subColName.SAMPLES); testcase tc = new testcase(); tc.name = c1; tc.externalid = externalid++; tc.internalid = externalid + ""; tc.node_order = order++; tc.version = 1; tc.summary = c2; tc.preconditions = preset; tc.execution_type = (uint)(can_auto ? 2 : 1); if (importance.Length > 5) { tc.importance = Convert.ToUInt32(importance.Substring(5, 1)); } else { tc.importance = 1; } custom_field test_type = new custom_field(); test_type.name = "test_type"; test_type.value = testtype; tc.custom_fields.Add(test_type); //todo 需求没有处理 //string reqs= itc.GetSubCase(row,DefaultTC.subColName.REQ); //requirement rq=new requirement(); //tc.requirements.Add for (int i = 0; i < steps.Count; i++) { step s = new step(); s.actions = steps[i]; s.expectedresults = exp[i]; s.step_number = (uint)(i + 1); s.execution_type = tc.execution_type; tc.steps.Add(s); } ts.Items.Add(tc); } }
private testcase CreateXmlFromUFTRunResults(TestRunResults testRes) { testcase tc = new testcase { systemout = testRes.ConsoleOut, systemerr = testRes.ConsoleErr, report = testRes.ReportLocation, classname = "All-Tests." + ((testRes.TestGroup == null) ? "" : testRes.TestGroup.Replace(".", "_")), name = testRes.TestPath, type = testRes.TestType, time = testRes.Runtime.TotalSeconds.ToString() }; if (!string.IsNullOrWhiteSpace(testRes.FailureDesc)) tc.AddFailure(new failure { message = testRes.FailureDesc }); switch (testRes.TestState) { case TestState.Passed: tc.status = "pass"; break; case TestState.Failed: tc.status = "fail"; break; case TestState.Error: tc.status = "error"; break; case TestState.Warning: tc.status = "warning"; break; default: tc.status = "pass"; break; } if (!string.IsNullOrWhiteSpace(testRes.ErrorDesc)) tc.AddError(new error { message = testRes.ErrorDesc }); return tc; }
internal void AddTestCase(testcase theTestCase) { testcaseField.Add(theTestCase); }
private testsuite CreateXmlFromLRRunResults(TestRunResults testRes) { testsuite lrts = new testsuite(); int totalTests = 0, totalFailures = 0, totalErrors = 0; // two LR report files may be generated: RunReport.xml, SLA.xml string lrRunReportFile = Path.Combine(testRes.ReportLocation, "RunReport.xml"); string lrSLAFile = Path.Combine(testRes.ReportLocation, "SLA.xml"); LRRunGeneralInfo generalInfo = new LRRunGeneralInfo(); List <LRRunSLAGoalResult> slaGoals = new List <LRRunSLAGoalResult>(); try { XmlDocument xdoc = new XmlDocument(); XmlElement slaNode = null; if (File.Exists(lrRunReportFile)) { xdoc.Load(lrRunReportFile); // General node var generalNode = xdoc.DocumentElement.SelectSingleNode("General"); if (generalNode != null) { var vUsersNode = generalNode.SelectSingleNode("VUsers") as XmlElement; if (vUsersNode != null) { if (vUsersNode.HasAttribute("Count")) { int vUsersCount = 0; if (int.TryParse(vUsersNode.Attributes["Count"].Value, out vUsersCount)) { generalInfo.VUsersCount = vUsersCount; } } } } // SLA node slaNode = xdoc.DocumentElement.SelectSingleNode("SLA") as XmlElement; } else if (File.Exists(lrSLAFile)) { xdoc.Load(lrSLAFile); slaNode = xdoc.DocumentElement; } if (slaNode != null) { var slaGoalNodes = slaNode.SelectNodes("SLA_GOAL"); if (slaGoalNodes != null) { foreach (var slaGoalNode in slaGoalNodes) { var slaGoalElement = slaGoalNode as XmlElement; if (slaGoalElement != null) { slaGoals.Add(new LRRunSLAGoalResult { TransactionName = slaGoalElement.GetAttribute("TransactionName"), Percentile = slaGoalElement.GetAttribute("Percentile"), FullName = slaGoalElement.GetAttribute("FullName"), Measurement = slaGoalElement.GetAttribute("Measurement"), GoalValue = slaGoalElement.GetAttribute("GoalValue"), ActualValue = slaGoalElement.GetAttribute("ActualValue"), Status = slaGoalElement.InnerText }); } } } } } catch (XmlException) { } lrts.name = testRes.TestPath; // testsuite properties lrts.properties = new property[] { new property { name = "Total vUsers", value = IntToString(generalInfo.VUsersCount) } }; double totalSeconds = testRes.Runtime.TotalSeconds; lrts.time = DoubleToString(totalSeconds); // testcases foreach (var slaGoal in slaGoals) { testcase tc = new testcase { name = slaGoal.TransactionName, classname = slaGoal.FullName + ": " + slaGoal.Percentile, report = testRes.ReportLocation, type = testRes.TestType, time = DoubleToString(totalSeconds / slaGoals.Count) }; switch (slaGoal.Status.Trim().ToLowerInvariant()) { case "failed": case "fail": tc.status = "fail"; tc.AddFailure(new failure { message = string.Format("The goal value '{0}' does not equal to the actual value '{1}'", slaGoal.GoalValue, slaGoal.ActualValue) }); totalFailures++; break; case "error": case "err": tc.status = "error"; tc.AddError(new error { message = testRes.ErrorDesc }); totalErrors++; break; case "warning": case "warn": tc.status = "warning"; break; default: tc.status = "pass"; break; } lrts.AddTestCase(tc); totalTests++; } lrts.tests = IntToString(totalTests); lrts.errors = IntToString(totalErrors); lrts.failures = IntToString(totalFailures); return(lrts); }
public JUnitXmlSerializer(PackageSource source, string time, string outputFile) { var testSuites = new testsuites(); var testSuite = new testsuite(); testSuite.name = string.Format("DevAudit {0} package source audit.", source.PackageManagerLabel); testSuite.package = "org.ossindex.devaudit"; testSuite.time = time; testSuite.tests = source.Vulnerabilities.Count.ToString(); testSuite.failures = source.Vulnerabilities.Where(v => v.Value.Count > 0).Count().ToString(); testSuite.testcase = new testcase[source.Vulnerabilities.Count]; int tcount = 0; foreach (var pv in source.Vulnerabilities.OrderByDescending(sv => sv.Value.Count(v => v.PackageVersionIsInRange))) { IPackage package = pv.Key; List <IVulnerability> package_vulnerabilities = pv.Value; var tc = new testcase(); tc.name = package.Name; tc.classname = package.Name; tc.assertions = "1"; if (package_vulnerabilities.Count() == 0) { continue; } else if (package_vulnerabilities.Count(v => v.PackageVersionIsInRange) == 0) { continue; } else { var matched_vulnerabilities = package_vulnerabilities.Where(v => v.PackageVersionIsInRange).ToList(); int matched_vulnerabilities_count = matched_vulnerabilities.Count; tc.failure = new failure[matched_vulnerabilities_count]; int c = 0; foreach (var v in matched_vulnerabilities) { failure f = new failure(); f.message = "Package vulnerable"; VulnText.AppendFormat("--[{0}/{1}] ", (c + 1), matched_vulnerabilities_count); VulnText.AppendFormat("{0} ", v.Title.Trim()); PrintAuditResultMultiLineField(2, "Description", v.Description.Trim().Replace("\n", "").Replace(". ", "." + Environment.NewLine)); VulnText.AppendFormat("{0}", string.Join(", ", v.Versions.ToArray())); if (v.CVE != null && v.CVE.Count() > 0) { VulnText.AppendFormat(" --CVE(s): {0}", string.Join(", ", v.CVE.ToArray())); } if (!string.IsNullOrEmpty(v.Reporter)) { VulnText.AppendFormat(" --Reporter: {0} ", v.Reporter.Trim()); } if (!string.IsNullOrEmpty(v.CVSS.Score)) { VulnText.AppendFormat(" --CVSS Score: {0}. Vector: {1}", v.CVSS.Score, v.CVSS.Vector); } if (v.Published != DateTime.MinValue) { VulnText.AppendFormat(" --Date published: {0}", v.Published.ToShortDateString()); } if (!string.IsNullOrEmpty(v.Id)) { VulnText.AppendFormat(" --Id: {0}", v.Id); } if (v.References != null && v.References.Count() > 0) { if (v.References.Count() == 1) { VulnText.AppendFormat(" --Reference: {0}", v.References[0]); } else { VulnText.AppendFormat(" --References:"); for (int i = 0; i < v.References.Count(); i++) { VulnText.AppendFormat(" - {0}", v.References[i]); } } } if (!string.IsNullOrEmpty(v.DataSource.Name)) { VulnText.AppendFormat(" --Provided by: {0}", v.DataSource.Name); } f.Text = VulnText.ToString().Split(Environment.NewLine.ToCharArray()); tc.failure[c++] = f; VulnText.Clear(); } } testSuite.testcase[tcount++] = tc; } testSuites.testsuite = new testsuite[] { testSuite }; XmlSerializer xs = new XmlSerializer(typeof(testsuites)); xs.Serialize(File.CreateText(outputFile), testSuites); }
/// <summary> /// converts all data from the test results in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public void CreateXmlFromRunResults(TestSuiteRunResults results) { _testSuites = new testsuites(); testsuite uftts = new testsuite { errors = results.NumErrors.ToString(), tests = results.NumTests.ToString(), failures = results.NumFailures.ToString(), name = results.SuiteName, package = ClassName }; foreach (TestRunResults testRes in results.TestRuns) { if (testRes.TestType == TestType.LoadRunner.ToString()) { testsuite lrts = CreateXmlFromLRRunResults(testRes); _testSuites.AddTestsuite(lrts); } else { //Console.WriteLine("CreateXmlFromRunResults, UFT test"); testcase ufttc = CreateXmlFromUFTRunResults(testRes); uftts.AddTestCase(ufttc); } } if (uftts.testcase.Length > 0) { //Console.WriteLine("CreateXmlFromRunResults, add test case to test suite"); _testSuites.AddTestsuite(uftts); } else { //Console.WriteLine("CreateXmlFromRunResults, no uft test case to write"); } if (File.Exists(XmlName)) { //Console.WriteLine("CreateXmlFromRunResults, file exist - delete file"); File.Delete(XmlName); } // else //{ //Console.WriteLine("CreateXmlFromRunResults, file does not exist"); // } using (Stream s = File.OpenWrite(XmlName)) { //Console.WriteLine("CreateXmlFromRunResults, write test results to xml file"); //Console.WriteLine("_testSuites: " + _testSuites.name + " tests: " + _testSuites.tests); //Console.WriteLine("_testSuites: " + _testSuites.ToString()); _serializer.Serialize(s, _testSuites); } //Console.WriteLine("CreateXmlFromRunResults, XmlName: " + XmlName); /*if (File.Exists(XmlName)) * { * Console.WriteLine("CreateXmlFromRunResults, results file was created"); * } else * { * Console.WriteLine("CreateXmlFromRunResults, results file was not created"); * }*/ }