示例#1
0
        public void SaveLastResult()
        {
            //TODO: Save all results
            TestResult result = loader.Results[0];

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Title            = "Save Test Results as XML";
            dlg.Filter           = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
            dlg.FileName         = "TestResult.xml";
            dlg.InitialDirectory = Path.GetDirectoryName(loader.TestFileName);
            dlg.DefaultExt       = "xml";
            dlg.ValidateNames    = true;
            dlg.OverwritePrompt  = true;

            if (dlg.ShowDialog(owner) == DialogResult.OK)
            {
                try
                {
                    string fileName = dlg.FileName;

                    XmlResultVisitor resultVisitor
                        = new XmlResultVisitor(fileName, result);
                    result.Accept(resultVisitor);
                    resultVisitor.Write();

                    string msg = String.Format("Results saved as {0}", fileName);
                    UserMessage.DisplayInfo(msg, "Save Results as XML");
                }
                catch (Exception exception)
                {
                    UserMessage.DisplayFailure(exception, "Unable to Save Results");
                }
            }
        }
示例#2
0
        private void runSchemaValidatorTest(TextWriter writer, CultureInfo testCulture)
        {
            // Preserve current culture
            CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;

            // Enable test culture
            Thread.CurrentThread.CurrentCulture = testCulture;

            try
            {
                string           testsDll = "mock-assembly.dll";
                TestSuiteBuilder builder  = new TestSuiteBuilder();
                Test             suite    = builder.Build(new TestPackage(testsDll));

                TestResult result = suite.Run(NullListener.NULL);

                XmlResultVisitor visitor = new XmlResultVisitor(writer, result);
                result.Accept(visitor);
                visitor.Write();
            }
            finally
            {
                // Restore previous culture
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
示例#3
0
    public int Execute()
    {
        EventCollector collector = new EventCollector();

        Console.WriteLine();

        ConsoleWriter outStream   = new ConsoleWriter(Console.Out);
        ConsoleWriter errorStream = new ConsoleWriter(Console.Error);

        if (!options.noSummary)
        {
            TestResult result = testDomain.Run(collector, outStream, errorStream);
            Console.WriteLine("\n");
            XmlResultVisitor resultVisitor = new XmlResultVisitor(outputFile, result);
            result.Accept(resultVisitor);
            resultVisitor.Write();
            CreateSummaryDocument();
            return(result.IsFailure ? 1 : 0);
        }
        else
        {
            testDomain.Run(collector, outStream, errorStream);
            return(0);
        }
    }
示例#4
0
        private void runSchemaValidatorTest(string reportFileName, CultureInfo testCulture)
        {
            // Preserve current culture
            CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;

            // Enable test culture
            Thread.CurrentThread.CurrentCulture = testCulture;

            try
            {
                string           testsDll = "mock-assembly.dll";
                TestSuiteBuilder builder  = new TestSuiteBuilder();
                Test             suite    = builder.Build(new TestPackage(testsDll));

                TestResult result = suite.Run(NullListener.NULL);

                XmlResultVisitor visitor = new XmlResultVisitor(reportFileName, result);
                result.Accept(visitor);
                visitor.Write();

                SchemaValidator validator = new SchemaValidator(reportFileName, schemaFile.Path);
                Assert.IsTrue(validator.Validate(), "validate failed");
            }
            finally
            {
                // Restore previous culture
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
示例#5
0
        public static void CreateXmlOutput(TestResult result, TextWriter w)
        {
            XmlResultVisitor visitor = new XmlResultVisitor(w, result);

            result.Accept(visitor);
            visitor.Write();
        }
示例#6
0
        private string CreateXmlOutput(TestResult result)
        {
            StringBuilder    builder       = new StringBuilder();
            XmlResultVisitor resultVisitor = new XmlResultVisitor(new StringWriter(builder), result);

            result.Accept(resultVisitor);
            resultVisitor.Write();

            return(builder.ToString());
        }
示例#7
0
        private void runSchemaValidatorTest(TextWriter writer)
        {
            string           testsDll = "mock-assembly.dll";
            TestSuiteBuilder builder  = new TestSuiteBuilder();
            Test             suite    = builder.Build(new TestPackage(testsDll));

            TestResult result = suite.Run(NullListener.NULL);

            XmlResultVisitor visitor = new XmlResultVisitor(writer, result);

            result.Accept(visitor);
            visitor.Write();
        }
示例#8
0
        private void runSchemaValidatorTest(string reportFileName)
        {
            string           testsDll = "mock-assembly.dll";
            TestSuiteBuilder builder  = new TestSuiteBuilder();
            Test             suite    = builder.Build(new TestPackage(testsDll));

            TestResult result = suite.Run(NullListener.NULL);

            XmlResultVisitor visitor = new XmlResultVisitor(reportFileName, result);

            result.Accept(visitor);
            visitor.Write();

            SchemaValidator validator = new SchemaValidator(reportFileName, schemaFile.Path);

            Assert.IsTrue(validator.Validate(), "validate failed");
        }
示例#9
0
        public void RunMockTests()
        {
            string           testsDll     = "D:\\Courses\\2 - 2008 Fall\\CSC 712\\TermProject\\NUnit-2.4.8-src\\src\\ClientUtilities\\tests\\bin\\Debug2005\\mock-assembly.dll";
            TestSuiteBuilder suiteBuilder = new TestSuiteBuilder();
            Test             suite        = suiteBuilder.Build(new TestPackage(testsDll));

            TestResult       result  = suite.Run(NullListener.NULL);
            StringBuilder    builder = new StringBuilder();
            StringWriter     writer  = new StringWriter(builder);
            XmlResultVisitor visitor = new XmlResultVisitor(writer, result);

            result.Accept(visitor);
            visitor.Write();

            string resultXml = builder.ToString();

            resultDoc = new XmlDocument();
            resultDoc.LoadXml(resultXml);
        }
示例#10
0
        public void RunMockTests()
        {
            string           testsDll     = "mock-assembly.dll";
            TestSuiteBuilder suiteBuilder = new TestSuiteBuilder();
            Test             suite        = suiteBuilder.Build(new TestPackage(testsDll));

            TestResult       result  = suite.Run(NullListener.NULL);
            StringBuilder    builder = new StringBuilder();
            StringWriter     writer  = new StringWriter(builder);
            XmlResultVisitor visitor = new XmlResultVisitor(writer, result);

            result.Accept(visitor);
            visitor.Write();

            string resultXml = builder.ToString();

            resultDoc = new XmlDocument();
            resultDoc.LoadXml(resultXml);
        }
示例#11
0
        private void FormatResult(NUnit2Test testElement, TestResult result)
        {
            // temp file for storing test results
            string xmlResultFile = Path.GetTempFileName();

            // permanent file for storing test results
            string outputFile = null;

            try {
                XmlResultVisitor resultVisitor = new XmlResultVisitor(xmlResultFile, result);
                result.Accept(resultVisitor);
                resultVisitor.Write();

                foreach (FormatterElement formatter in FormatterElements)
                {
                    if (formatter.Type == FormatterType.Xml)
                    {
                        if (formatter.UseFile)
                        {
                            // determine file name for output file
                            outputFile = result.Name + "-results" + formatter.Extension;

                            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)
                        {
                            // determine file name for output file
                            outputFile = result.Name + "-results" + formatter.Extension;

                            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);
            }
        }
示例#12
0
		public int Execute()
		{
			EventCollector collector = new EventCollector();
			Console.WriteLine ();

			ConsoleWriter outStream = new ConsoleWriter(Console.Out);
			ConsoleWriter errorStream = new ConsoleWriter(Console.Error);

			if (!options.noSummary) {
				TestResult result = testDomain.Run(collector, outStream, errorStream);
				Console.WriteLine("\n");
				XmlResultVisitor resultVisitor = new XmlResultVisitor(outputFile, result);
				result.Accept(resultVisitor);
				resultVisitor.Write();
				CreateSummaryDocument();
				return result.IsFailure ? 1 : 0;
			}
			else {
				testDomain.Run (collector, outStream, errorStream);
				return 0;
			}
		}
示例#13
0
        public void RunMockTests()
        {
            string testsDll = "mock-assembly.dll";
            TestSuiteBuilder suiteBuilder = new TestSuiteBuilder();
            Test suite = suiteBuilder.Build( new TestPackage( testsDll ) );

            TestResult result = suite.Run(NullListener.NULL);
            StringBuilder builder = new StringBuilder();
            StringWriter writer = new StringWriter(builder);
            XmlResultVisitor visitor = new XmlResultVisitor(writer, result);
            result.Accept(visitor);
            visitor.Write();

            string resultXml = builder.ToString();
            Console.WriteLine(resultXml);

            resultDoc = new XmlDocument();
            resultDoc.LoadXml(resultXml);
        }
示例#14
0
        public void RunMockTests()
        {
            string testsDll = "D:\\Courses\\2 - 2008 Fall\\CSC 712\\TermProject\\NUnit-2.4.8-src\\src\\ClientUtilities\\tests\\bin\\Debug2005\\mock-assembly.dll";
            TestSuiteBuilder suiteBuilder = new TestSuiteBuilder();
            Test suite = suiteBuilder.Build( new TestPackage( testsDll ) );

            TestResult result = suite.Run(NullListener.NULL);
            StringBuilder builder = new StringBuilder();
            StringWriter writer = new StringWriter(builder);
            XmlResultVisitor visitor = new XmlResultVisitor(writer, result);
            result.Accept(visitor);
            visitor.Write();

            string resultXml = builder.ToString();

            resultDoc = new XmlDocument();
            resultDoc.LoadXml(resultXml);
        }