public void SaveObjectShouldReplaceOnlyInvalidCharacter() { XmlPersistence xmlPersistence = new XmlPersistence(); var node = xmlPersistence.CreateRootElement("TestRun"); string strWithInvalidCharForXml = "This string has these \0 \v invalid characters"; xmlPersistence.SaveObject(strWithInvalidCharForXml, node, null, "dummy"); string expectedResult = "This string has these \\u0000 \\u000b invalid characters"; Assert.AreEqual(0, string.Compare(expectedResult, node.InnerXml)); }
public void SaveObjectShouldReplaceInvalidCharacter() { XmlPersistence xmlPersistence = new XmlPersistence(); var node = xmlPersistence.CreateRootElement("TestRun"); // we are handling only #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] char[] invalidXmlCharacterArray = new char[7]; invalidXmlCharacterArray[0] = (char)0x5; invalidXmlCharacterArray[1] = (char)0xb; invalidXmlCharacterArray[2] = (char)0xf; invalidXmlCharacterArray[3] = (char)0xd800; invalidXmlCharacterArray[4] = (char)0xdc00; invalidXmlCharacterArray[5] = (char)0xfffe; invalidXmlCharacterArray[6] = (char)0x0; string strWithInvalidCharForXml = new string(invalidXmlCharacterArray); xmlPersistence.SaveObject(strWithInvalidCharForXml, node, null, "dummy"); string expectedResult = "\\u0005\\u000b\\u000f\\ud800\\udc00\\ufffe\\u0000"; Assert.AreEqual(0, string.Compare(expectedResult, node.InnerXml)); }
public void SaveObjectShouldNotReplaceValidCharacter() { XmlPersistence xmlPersistence = new XmlPersistence(); var node = xmlPersistence.CreateRootElement("TestRun"); // we are handling only #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] char[] validXmlCharacterArray = new char[8]; validXmlCharacterArray[0] = (char)0x9; validXmlCharacterArray[1] = (char)0xa; validXmlCharacterArray[2] = (char)0xd; validXmlCharacterArray[3] = (char)0x20; validXmlCharacterArray[4] = (char)0xc123; validXmlCharacterArray[5] = (char)0xe000; validXmlCharacterArray[6] = (char)0xea12; validXmlCharacterArray[7] = (char)0xfffd; string strWithValidCharForXml = new string(validXmlCharacterArray); xmlPersistence.SaveObject(strWithValidCharForXml, node, null, "dummy"); string expectedResult = "\t\n\r 섣�"; Assert.AreEqual(0, string.Compare(expectedResult, node.InnerXml)); }
/// <summary> /// Called when a test run is completed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// Test run complete events arguments. /// </param> internal void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) { // Create test run // If abort occurs there is no call to TestResultHandler which results in testRun not created. // This happens when some test aborts in the first batch of execution. if (this.testRun == null) { CreateTestRun(); } XmlPersistence helper = new XmlPersistence(); XmlTestStoreParameters parameters = XmlTestStoreParameters.GetParameters(); XmlElement rootElement = helper.CreateRootElement("TestRun"); // Save runId/username/creation time etc. this.testRun.Finished = DateTime.UtcNow; helper.SaveSingleFields(rootElement, this.testRun, parameters); // Save test settings helper.SaveObject(this.testRun.RunConfiguration, rootElement, "TestSettings", parameters); // Save test results helper.SaveIEnumerable(this.results.Values, rootElement, "Results", ".", null, parameters); // Save test definitions helper.SaveIEnumerable(this.testElements.Values, rootElement, "TestDefinitions", ".", null, parameters); // Save test entries helper.SaveIEnumerable(this.entries.Values, rootElement, "TestEntries", ".", "TestEntry", parameters); // Save default categories List <TestListCategory> categories = new List <TestListCategory>(); categories.Add(TestListCategory.UncategorizedResults); categories.Add(TestListCategory.AllResults); helper.SaveList(categories, rootElement, "TestLists", ".", "TestList", parameters); // Save summary if (this.testRunOutcome == TrxLoggerObjectModel.TestOutcome.Passed) { this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Completed; } testRunOutcome = changeTestOutcomeIfNecessary(testRunOutcome); List <string> errorMessages = new List <string>(); List <CollectorDataEntry> collectorEntries = this.converter.ToCollectionEntries(e.AttachmentSets, this.testRun, this.testResultsDirPath); IList <string> resultFiles = this.converter.ToResultFiles(e.AttachmentSets, this.testRun, this.testResultsDirPath, errorMessages); if (errorMessages.Count > 0) { // Got some errors while attaching files, report them and set the outcome of testrun to be Error... this.testRunOutcome = TrxLoggerObjectModel.TestOutcome.Error; foreach (string msg in errorMessages) { RunInfo runMessage = new RunInfo(msg, null, Environment.MachineName, TrxLoggerObjectModel.TestOutcome.Error); this.runLevelErrorsAndWarnings.Add(runMessage); } } TestRunSummary runSummary = new TestRunSummary( this.totalTests, this.passTests + this.failTests, this.passTests, this.failTests, this.testRunOutcome, this.runLevelErrorsAndWarnings, this.runLevelStdOut.ToString(), resultFiles, collectorEntries); helper.SaveObject(runSummary, rootElement, "ResultSummary", parameters); this.ReserveTrxFilePath(); this.PopulateTrxFile(this.trxFilePath, rootElement); }