Esempio n. 1
0
 public void TestCloseWithFileName()
 {
     strategy = new XmlResultWriter(testResultFileName, folderModel);
     strategy.Close();
     Assert.IsTrue(folderModel.Exists(testResultFileName));
     Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?>" + Environment.NewLine + "<testResults />", folderModel.GetPageContent(testResultFileName));
 }
Esempio n. 2
0
    public void RunFinished(TestResult result)
    {
        // Reset console output
        consoleStringWriter.Dispose();
        var consoleOut = Console.Out;

        Console.SetOut(consoleOut);

        // Write the TestResult.xml
        if (testresultpath != null)
        {
            var testResultBuilder = new StringBuilder();
            using (var writer = new StringWriter(testResultBuilder))
            {
                var xmlWriter = new XmlResultWriter(writer);
                xmlWriter.SaveTestResult(result);
            }

            var xmlOutput = testResultBuilder.ToString();
            using (var writer = new StreamWriter(testresultpath))
            {
                writer.Write(xmlOutput);
            }
        }
    }
 public void TestCloseWithFileName()
 {
     _strategy = new XmlResultWriter(TEST_RESULT_FILE_NAME, _folderModel);
     _strategy.Close();
     Assert.IsTrue(_folderModel.Exists(TEST_RESULT_FILE_NAME));
     Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<testResults />", _folderModel.GetPageContent(TEST_RESULT_FILE_NAME));
 }
Esempio n. 4
0
 /// <summary>
 /// Saves the TestResult as xml to the specified path.
 /// </summary>
 /// <param name="result">The test result to be saved.</param>
 /// <param name="outputXmlPath">The output xml path.</param>
 private static void SaveXmlOutput(TestResult result, string outputXmlPath)
 {
     if (!string.IsNullOrEmpty(outputXmlPath))
     {
         var writer = new XmlResultWriter(outputXmlPath);
         writer.SaveTestResult(result);
     }
 }
Esempio n. 5
0
 public void TestWriteFinalCounts()
 {
     strategy = new XmlResultWriter(testResultFileName, folderModel);
     strategy.WriteFinalCount(MakeTestCounts());
     strategy.Close();
     Assert.AreEqual(BuildFinalCountsString(1, 2, 3, 4),
                     folderModel.GetPageContent(testResultFileName));
 }
 public void TestWriteFinalCounts()
 {
     _strategy = new XmlResultWriter(TEST_RESULT_FILE_NAME, _folderModel);
     _strategy.WriteFinalCount(MakeTestCounts());
     _strategy.Close();
     Assert.AreEqual(BuildFinalCountsString(1, 2, 3, 4),
                     _folderModel.GetPageContent(TEST_RESULT_FILE_NAME));
 }
Esempio n. 7
0
        public TestRunner(String path)
        {
            this.path = path;
            TestResult      tempTr = runTest();
            XmlResultWriter xmlw   = new XmlResultWriter(Directory.GetCurrentDirectory() + @"\BackupResults\testResult_" + this.nextFileName());

            xmlw.SaveTestResult(tempTr);
            //call class to xml parsing
        }
Esempio n. 8
0
        /// <summary>
        ///     Writes API outputs using JSON or XML depending on the Accept header, the "format" query parameter, then the
        ///     Content-Type header, defaulting to JSON.
        /// </summary>
        /// <param name="options">Options for the JSON serializer</param>
        /// <returns>This <see cref="RestModelOptionsBuilder{TModel, TUser}" /> object, for chaining</returns>
        public RestModelOptionsBuilder <TModel, TUser> WriteJsonOrXml(JsonSerializerOptions options = null)
        {
            string[] MimeTypes             = { "application/json", "application/xml" };
            JsonResultWriter <TModel> Json = new JsonResultWriter <TModel>(options);
            XmlResultWriter <TModel>  Xml  = new XmlResultWriter <TModel>();

            HeaderDependentResultWriter <TModel, TUser> ContentTypeWriter           = new HeaderDependentResultWriter <TModel, TUser>(HeaderNames.ContentType, MimeTypes, new IResultWriter <TModel, TUser>[] { Json, Xml }, 0);
            QueryDependentResultWriter <TModel, TUser>  QueryDependentResultWriter  = new QueryDependentResultWriter <TModel, TUser>("format", new[] { "json", "xml" }, new IResultWriter <TModel, TUser>[] { Json, Xml, ContentTypeWriter }, 2);
            AcceptDependentResultWriter <TModel, TUser> AcceptDependentResultWriter = new AcceptDependentResultWriter <TModel, TUser>(MimeTypes, new IResultWriter <TModel, TUser>[] { Json, Xml, QueryDependentResultWriter }, 2);

            return(this.UseResultWriter(AcceptDependentResultWriter));
        }
        public void TestWriteIllegalCharacters()
        {
            const string pageName   = "Test Page";
            var          pageResult = new PageResult(pageName, "<table><tr><td>Text</td></tr>\x02</table>", MakeTestCounts());

            _strategy = new XmlResultWriter(TEST_RESULT_FILE_NAME, _folderModel);
            _strategy.WritePageResult(pageResult);
            _strategy.Close();
            Assert.AreEqual(
                BuildPageResultString(pageName, "<![CDATA[<table><tr><td>Text</td></tr>&#2;</table>]]>", 1, 2, 3, 4),
                _folderModel.GetPageContent(TEST_RESULT_FILE_NAME));
        }
Esempio n. 10
0
        public void TestWriteResults()
        {
            const string pageName   = "Test Page";
            var          pageResult = new PageResult(pageName, "<table border=\"1\" cellspacing=\"0\">\r\n<tr><td>Text</td>\r\n</tr>\r\n</table>", MakeTestCounts());

            _strategy = new XmlResultWriter(TEST_RESULT_FILE_NAME, _folderModel);
            _strategy.WritePageResult(pageResult);
            _strategy.Close();
            Assert.AreEqual(
                BuildPageResultString(pageName, "<![CDATA[<table border=\"1\" cellspacing=\"0\">\r\n<tr><td>Text</td>\r\n</tr>\r\n</table>]]>", 1, 2, 3, 4),
                _folderModel.GetPageContent(TEST_RESULT_FILE_NAME));
        }
Esempio n. 11
0
        private TestResult runTest()
        {
            CoreExtensions.Host.InitializeService();
            TestPackage      testPackage = new TestPackage(this.path);
            RemoteTestRunner rtr         = new RemoteTestRunner();

            rtr.Load(testPackage);
            TestResult      tr   = rtr.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Error);
            XmlResultWriter xmlw = new XmlResultWriter(Directory.GetCurrentDirectory() + @"\TempResults\testResult.xml");

            xmlw.SaveTestResult(tr);
            return(tr);
        }
        protected void OutputXml(TestResult result)
        {
            var builder      = new StringBuilder();
            var writer       = new StringWriter(builder);
            var resultWriter = new XmlResultWriter(writer);

            resultWriter.SaveTestResult(result);

            Response.ContentType = "text/xml";
            Response.Write(builder.ToString());
            Response.Flush();
            Response.End();
        }
Esempio n. 13
0
 public void RunFinished(TestResult result)
 {
     try
     {
         var cleanedName = OutputName.Replace("?", "");
         var writer      = new XmlResultWriter(Path.Combine(_outputPath, string.Format("{0}.xml", cleanedName)));
         writer.SaveTestResult(result);
     }
     finally
     {
         //Finished
         MarkAsFinished();
     }
 }
Esempio n. 14
0
 public void RunFinished()
 {
     var resultDestiantion = Application.dataPath;
     if (!string.IsNullOrEmpty (resultFilePath))
         resultDestiantion = resultFilePath;
     var fileName = Path.GetFileName (resultDestiantion);
     if (!string.IsNullOrEmpty (fileName))
         resultDestiantion = resultDestiantion.Substring (0, resultDestiantion.Length - fileName.Length);
     else
         fileName = "UnitTestResults.xml";
     #if !UNITY_METRO
     var resultWriter = new XmlResultWriter ("Unit Tests", results.ToArray ());
     resultWriter.WriteToFile (resultDestiantion, fileName);
     #endif
 }
Esempio n. 15
0
        private void OnRunAllTests()
        {
            LinkedWindow.Close();

            List <string> copiedAssemblies = new List <string>();

            foreach (TestableDll dll in DLLs)
            {
                // Shadow copy to temp folder
                string tempFile = Path.GetTempFileName();
                tempFile = tempFile.Replace(Path.GetExtension(tempFile), Path.GetExtension(dll.FullPath));
                File.Copy(dll.FullPath, tempFile, true);

                //Copy the PDB to get stack trace
                string destPdbFile = tempFile.Replace(Path.GetExtension(tempFile), ".pdb");
                string srcPdb      = dll.FullPath.Replace(Path.GetExtension(dll.FullPath), ".pdb");
                File.Copy(srcPdb, destPdbFile, true);

                copiedAssemblies.Add(tempFile);
            }

            // Copy Moq.dll and dependencies to temp folder
            CopyRequiredLibsToTemp(DLLs.First().FullPath);

            TestResult testResult = RunTestsInAssemblies(copiedAssemblies, TestFilter.Empty);

            // Save the result to xml file:
            string          resultFile   = Path.GetDirectoryName(DLLs.First().FullPath) + @"\TestResult.xml";
            XmlResultWriter resultWriter = new XmlResultWriter(resultFile);

            resultWriter.SaveTestResult(testResult);

            // show results dialog
            string extraMsg = "Result file can be found at " + resultFile;
            TestResultViewerViewModel vm     = new TestResultViewerViewModel(testResult, extraMsg);
            TestResultViewer          viewer = new TestResultViewer(vm);

            //viewer.Owner = LinkedWindow;
            GeneralHelper.SetRevitAsWindowOwner(viewer);
            viewer.ShowDialog();

            // cleanup
            foreach (string dll in copiedAssemblies)
            {
                File.Delete(dll);
                File.Delete(Path.ChangeExtension(dll, ".pdb"));
            }
        }
Esempio n. 16
0
        private void OnRunTest(string testDll)
        {
            string originalDllName = testDll;

            LinkedWindow.Close();
            // Shadow copy to temp folder
            string tempFile = Path.GetTempFileName();

            tempFile = tempFile.Replace(Path.GetExtension(tempFile), Path.GetExtension(testDll));
            File.Copy(testDll, tempFile, true);

            //Copy the PDB to get stack trace
            string destPdbFile = tempFile.Replace(Path.GetExtension(tempFile), ".pdb");
            string srcPdb      = testDll.Replace(Path.GetExtension(testDll), ".pdb");

            File.Copy(srcPdb, destPdbFile, true);

            testDll = tempFile;

            // Copy Moq.dll and dependencies to temp folder
            CopyRequiredLibsToTemp(tempFile);

            SimpleTestFilter filter     = new SimpleTestFilter(DLLs.FirstOrDefault(d => d.FullPath == originalDllName).Tests);
            TestResult       testResult = RunTestsInAssemblies(new List <string>()
            {
                testDll
            }, filter);

            // Save the result to xml file:
            string          resultFile   = Path.GetDirectoryName(testDll) + @"\TestResult.xml";
            XmlResultWriter resultWriter = new XmlResultWriter(resultFile);

            resultWriter.SaveTestResult(testResult);

            // show results dialog
            string extraMsg = "Result file can be found at " + resultFile;
            TestResultViewerViewModel vm     = new TestResultViewerViewModel(testResult, extraMsg);
            TestResultViewer          viewer = new TestResultViewer(vm);

            //viewer.Owner = LinkedWindow;
            GeneralHelper.SetRevitAsWindowOwner(viewer);
            viewer.ShowDialog();

            // cleanup
            File.Delete(tempFile);
            File.Delete(destPdbFile);
        }
Esempio n. 17
0
        public void TestWriteResults()
        {
            const string pageName   = "Test Page";
            var          pageResult = new PageResult(pageName, "<table border=\"1\" cellspacing=\"0\">" + Environment.NewLine
                                                     + "<tr><td>Text</td>" + Environment.NewLine
                                                     + "</tr>" + Environment.NewLine + "</table>", MakeTestCounts());

            strategy = new XmlResultWriter(testResultFileName, folderModel);
            strategy.WritePageResult(pageResult);
            strategy.Close();
            Assert.AreEqual(
                BuildPageResultString(pageName, "<![CDATA[<table border=\"1\" cellspacing=\"0\">" + Environment.NewLine
                                      + "<tr><td>Text</td>" + Environment.NewLine
                                      + "</tr>" + Environment.NewLine
                                      + "</table>]]>", 1, 2, 3, 4),
                folderModel.GetPageContent(testResultFileName));
        }
Esempio n. 18
0
            public override void RunFinished(TestResult result)
            {
                base.RunFinished(result);

                var resultWriter = new XmlResultWriter(_runOptions.XmlResultsPath);

                resultWriter.SaveTestResult(result);

                if (_runOptions.PerformXslTransform)
                {
                    var transform = new XslCompiledTransform();
                    transform.Load(_runOptions.XslTransformPath);
                    transform.Transform(_runOptions.XmlResultsPath, _runOptions.TransformedResultsPath);
                }

                File.WriteAllText(_runOptions.StdoutPath, StdoutStandin.ToString());

                if (_runOptions.PerformXslTransform && _runOptions.ShouldLaunchResults)
                {
                    System.Diagnostics.Process.Start(_runOptions.TransformedResultsPath);
                }
            }
Esempio n. 19
0
File: Program.cs Progetto: zparr/ATF
        /// <summary>
        /// Runs all tests.
        /// </summary>
        /// <param name="testAssemblyName">Name of the test assembly.</param>
        /// <returns>0 if tests ran successfully, -1 otherwise</returns>
        public static int RunAllTests(string testAssemblyName)
        {
            TestRunner runner   = MakeTestRunner(testAssemblyName);
            string     category = ParseTestCategory();

            runner.Run(new UnitTestListener(), new TestFilter(category));
            XmlResultWriter writer = new XmlResultWriter("TestResult.xml");

            writer.SaveTestResult(runner.TestResult);

            XslCompiledTransform xsl = new XslCompiledTransform();

            xsl.Load("Resources/NUnitToJUnit.xslt");
            xsl.Transform("TestResult.xml", "TestResult.JUnit.xml");

            if (runner.TestResult.IsFailure)
            {
                return(-1);
            }

            return(0);
        }
Esempio n. 20
0
			public void RunFinished ()
			{
				var resultWriter = new XmlResultWriter("UnitTestResults.xml");
				resultWriter.SaveTestResult ("Unit Tests", unitTestView.testList.ToArray ());
				EditorUtility.ClearProgressBar();
			}
Esempio n. 21
0
			public void RunFinished ()
			{
				var resultWriter = new XmlResultWriter(EditorApplication.currentScene,
															"UnitTestResults.xml");
				resultWriter.SaveTestResult(unitTestView.testList.ToArray());
				EditorUtility.ClearProgressBar();
			}
Esempio n. 22
0
		private void WriteResultsToFile()
		{
			var path = System.IO.Path.Combine (Application.dataPath,
												Application.loadedLevelName + "-TestResults.xml");
			var resultWriter = new XmlResultWriter(Application.loadedLevelName, path);
			resultWriter.SaveTestResult(testToRun.ToArray());
		}
		private void SaveResults ()
		{
			if (!IsFileSavingSupported ()) return;
			var resultDestiantion = GetResultDestiantion ();
			var resultFileName = Application.loadedLevelName;
			if (resultFileName != "")
				resultFileName += "-";
			resultFileName += defaultResulFilePostfix;

			var resultWriter = new XmlResultWriter (Application.loadedLevelName, testToRun.ToArray ());

#if !UNITY_METRO 
			Uri uri;
			if ( Uri.TryCreate (resultDestiantion, UriKind.Absolute, out uri) && uri.Scheme == Uri.UriSchemeFile)
			{
				resultWriter.WriteToFile (resultDestiantion, resultFileName);
			}
			else
			{
				Debug.LogError ("Provided path is invalid");
			}
#endif
		}
Esempio n. 24
0
            public void RunFinished()
            {
                var resultDestiantion = Application.dataPath;
                if (!string.IsNullOrEmpty(m_ResultFilePath))
                    resultDestiantion = m_ResultFilePath;
                var fileName = Path.GetFileName(resultDestiantion);
                if (!string.IsNullOrEmpty(fileName))
                    resultDestiantion = resultDestiantion.Substring(0, resultDestiantion.Length - fileName.Length);
                else
                    fileName = "UnitTestResults.xml";
#if !UNITY_METRO
                var resultWriter = new XmlResultWriter("Unit Tests", "Editor", m_Results.ToArray());
                resultWriter.WriteToFile(resultDestiantion, fileName);
#endif
                var executed = m_Results.Where(result => result.Executed);
                if (!executed.Any())
                {
                    EditorApplication.Exit(returnCodeRunError);
                    return;
                }
                var failed = executed.Where(result => !result.IsSuccess);
                EditorApplication.Exit(failed.Any() ? returnCodeTestsFailed : returnCodeTestsOk);
            }
Esempio n. 25
0
        private void FormatResult(NUnit2Test testElement, TestResult result)
        {
            // temp file for storing test results
            string xmlResultFile = Path.GetTempFileName();

            try {
                XmlResultWriter resultWriter = new XmlResultWriter(xmlResultFile);
                resultWriter.SaveTestResult(result);

                foreach (FormatterElement formatter in FormatterElements)
                {
                    // permanent file for storing test results
                    string outputFile = result.Name + "-results" + formatter.Extension;

                    if (formatter.Type == FormatterType.Xml)
                    {
                        if (formatter.UseFile)
                        {
                            if (formatter.OutputDirectory != null)
                            {
                                // ensure output directory exists
                                if (!formatter.OutputDirectory.Exists)
                                {
                                    formatter.OutputDirectory.Create();
                                }

                                // combine output directory and result filename
                                outputFile = Path.Combine(formatter.OutputDirectory.FullName,
                                                          Path.GetFileName(outputFile));
                            }

                            // copy the temp result file to permanent location
                            File.Copy(xmlResultFile, outputFile, true);
                        }
                        else
                        {
                            using (StreamReader reader = new StreamReader(xmlResultFile)) {
                                // strip off the xml header
                                reader.ReadLine();
                                StringBuilder builder = new StringBuilder();
                                while (reader.Peek() > -1)
                                {
                                    builder.Append(reader.ReadLine().Trim()).Append(
                                        Environment.NewLine);
                                }
                                Log(Level.Info, builder.ToString());
                            }
                        }
                    }
                    else if (formatter.Type == FormatterType.Plain)
                    {
                        TextWriter writer;
                        if (formatter.UseFile)
                        {
                            if (formatter.OutputDirectory != null)
                            {
                                // ensure output directory exists
                                if (!formatter.OutputDirectory.Exists)
                                {
                                    formatter.OutputDirectory.Create();
                                }

                                // combine output directory and result filename
                                outputFile = Path.Combine(formatter.OutputDirectory.FullName,
                                                          Path.GetFileName(outputFile));
                            }

                            writer = new StreamWriter(outputFile);
                        }
                        else
                        {
                            writer = new LogWriter(this, Level.Info, CultureInfo.InvariantCulture);
                        }
                        CreateSummaryDocument(xmlResultFile, writer, testElement);
                        writer.Close();
                    }
                }
            } catch (Exception ex) {
                throw new BuildException("Test results could not be formatted.",
                                         Location, ex);
            } finally {
                // make sure temp file with test results is removed
                File.Delete(xmlResultFile);
            }
        }
Esempio n. 26
0
		public void WriteReport()
		{
			if (Defects.Count == 0)
			{
				Log.LogMessage(MessageImportance.Normal, "No errors detected");
				if (!string.IsNullOrEmpty(LogFile) && File.Exists(LogFile))
					File.Delete(LogFile);
			}
			else
			{
				ResultWriter resultWriter = null;
				
				switch (LogType)
				{
				case LogTypeEnum.None:
					PrintInScreen();
					break;
				case LogTypeEnum.Plain:
					resultWriter = new TextResultWriter(this, LogFile);
					break;
				case LogTypeEnum.Xml:
					resultWriter = new XmlResultWriter(this, LogFile);
					break;
				case LogTypeEnum.Html:
					resultWriter = new HtmlResultWriter(this, LogFile);
					break;
				default:
					break;
				}
				
				if (resultWriter != null)
				{
					resultWriter.Report();
					resultWriter.Dispose();
				}
			}
		}
Esempio n. 27
0
			public void RunFinished ()
			{
				var resultDestiantion = Application.dataPath;
				if (!string.IsNullOrEmpty (resultFilePath))
					resultDestiantion = resultFilePath;
				var fileName = Path.GetFileName (resultDestiantion);
				if (!string.IsNullOrEmpty (fileName))
					resultDestiantion = resultDestiantion.Substring (0, resultDestiantion.Length - fileName.Length);
				else
					fileName = "UnitTestResults.xml";
#if !UNITY_METRO
				var resultWriter = new XmlResultWriter ("Unit Tests", results.ToArray ());
				resultWriter.WriteToFile (resultDestiantion, fileName);
#endif
				var executed = results.Where( result => result.Executed );
				if (!executed.Any ())
				{
					EditorApplication.Exit(RETURN_CODE_RUN_ERROR);
					return;
				}
				var failed = executed.Where (result => !result.IsSuccess);
				EditorApplication.Exit(failed.Any() ? RETURN_CODE_TESTS_FAILED : RETURN_CODE_TESTS_OK);
			}
Esempio n. 28
0
 public void TestCloseWithStandardOut()
 {
     strategy = new XmlResultWriter("stdout", folderModel);
     strategy.Close();
     Assert.IsFalse(folderModel.Exists(testResultFileName));
 }
Esempio n. 29
0
 public void TestCloseWithStandardOut()
 {
     _strategy = new XmlResultWriter("stdout", _folderModel);
     _strategy.Close();
     Assert.IsFalse(_folderModel.Exists(TEST_RESULT_FILE_NAME));
 }
Esempio n. 30
0
 private void WriteResultsToFile()
 {
     string path = Path.Combine(Application.dataPath, Application.loadedLevelName + "-TestResults.xml");
     Debug.Log("Saving results in " + path);
     var resultWriter = new XmlResultWriter(path);
     resultWriter.SaveTestResult(Application.loadedLevelName, testToRun.ToArray());
 }