Example #1
0
        public OutputSpecification ResolveOutputSpecification(string value, IList <OutputSpecification> outputSpecifications, IFileSystem fileSystem, string currentDir)
        {
            if (value == null)
            {
                return(null);
            }

            OutputSpecification spec;

            try
            {
                spec = new OutputSpecification(value, currentDir);
            }
            catch (ArgumentException e)
            {
                _logError(e.Message);
                return(null);
            }

            if (spec.Transform != null)
            {
                if (!fileSystem.FileExists(spec.Transform))
                {
                    _logError($"Transform {spec.Transform} could not be found.");
                    return(null);
                }
            }

            return(spec);
        }
Example #2
0
        /// <summary>
        /// Write out the result of exploring the tests
        /// </summary>
        /// <param name="test">The top-level test</param>
        /// <param name="spec">An OutputSpecification</param>
        public void WriteTestFile(ITest test, OutputSpecification spec)
        {
            string       outputPath   = Path.Combine(_workDirectory, spec.OutputPath);
            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
            case "nunit3":
                outputWriter = new NUnit3XmlOutputWriter();
                break;

            case "cases":
                outputWriter = new TestCaseOutputWriter();
                break;

            //case "user":
            //    Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            //    string dir = Path.GetDirectoryName(uri.LocalPath);
            //    outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform));
            //    break;

            default:
                throw new ArgumentException(
                          string.Format("Invalid XML output format '{0}'", spec.Format),
                          "spec");
            }

            outputWriter.WriteTestFile(test, outputPath);
            Console.WriteLine("Tests ({0}) saved as {1}", spec.Format, outputPath);
        }
 public void UserFormatMayBeIndicatedExplicitlyAfterTransform()
 {
     var spec = new OutputSpecification("MyFile.xml;transform=transform.xslt;format=user");
     Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
     Assert.That(spec.Format, Is.EqualTo("user"));
     Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
 }
 public void FileNamePlusFormat()
 {
     var spec = new OutputSpecification("MyFile.xml;format=nunit2");
     Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
     Assert.That(spec.Format, Is.EqualTo("nunit2"));
     Assert.Null(spec.Transform);
 }
Example #5
0
        public void FileNamePlusFormat()
        {
            var spec = new OutputSpecification("MyFile.xml;format=nunit2");

            Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
            Assert.That(spec.Format, Is.EqualTo("nunit2"));
        }
Example #6
0
        /// <summary>
        /// Write the result of a test run according to a spec.
        /// </summary>
        /// <param name="result">The test result</param>
        /// <param name="spec">An output specification</param>
        public void WriteResultFile(ITestResult result, OutputSpecification spec)
        {
            string outputPath = Path.Combine(_workDirectory, spec.OutputPath);
            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
                case "nunit3":
                    outputWriter = new NUnit3XmlOutputWriter();
                    break;

                case "nunit2":
                    outputWriter = new NUnit2XmlOutputWriter();
                    break;

                //case "user":
                //    Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
                //    string dir = Path.GetDirectoryName(uri.LocalPath);
                //    outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform));
                //    break;

                default:
                    throw new ArgumentException(
                        string.Format("Invalid XML output format '{0}'", spec.Format),
                        "spec");
            }

            outputWriter.WriteResultFile(result, outputPath);
            Console.WriteLine("Results ({0}) saved as {1}", spec.Format, outputPath);
        }
 public void FileNamePlusTransform()
 {
     var spec = new OutputSpecification("MyFile.xml;transform=transform.xslt");
     Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
     Assert.That(spec.Format, Is.EqualTo("user"));
     Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
 }
Example #8
0
        public void FileNameOnly()
        {
            var spec = new OutputSpecification("MyFile.xml");

            Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
            Assert.That(spec.Format, Is.EqualTo("nunit3"));
            Assert.Null(spec.Transform);
        }
        public void TransformFolderIsUsedToSpecifyTransform(string transformFolder)
        {
            const string fileName          = "transform.xslt";
            var          spec              = new OutputSpecification($"MyFile.xml;transform=transform.xslt", transformFolder);
            var          expectedTransform = Path.Combine(transformFolder ?? "", fileName);

            Assert.That(spec.Transform, Is.EqualTo(expectedTransform));
        }
Example #10
0
        public void UserFormatMayBeIndicatedExplicitlyBeforeTransform()
        {
            var spec = new OutputSpecification("MyFile.xml;format=user;transform=transform.xslt");

            Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
            Assert.That(spec.Format, Is.EqualTo("user"));
            Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
        }
Example #11
0
        public void FileNamePlusTransform()
        {
            var spec = new OutputSpecification("MyFile.xml;transform=transform.xslt");

            Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
            Assert.That(spec.Format, Is.EqualTo("user"));
            Assert.That(spec.Transform, Is.EqualTo("transform.xslt"));
        }
        public void FileNamePlusTransform()
        {
            const string fileName = "transform.xslt";
            var          spec     = new OutputSpecification($"MyFile.xml;transform={fileName}", null);

            Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
            Assert.That(spec.Format, Is.EqualTo("user"));
            Assert.That(spec.Transform, Is.EqualTo(fileName));
        }
        public void UserFormatMayBeIndicatedExplicitlyBeforeTransform()
        {
            const string fileName = "transform.xslt";
            var          spec     = new OutputSpecification($"MyFile.xml;format=user;transform={fileName}", null);

            Assert.That(spec.OutputPath, Is.EqualTo("MyFile.xml"));
            Assert.That(spec.Format, Is.EqualTo("user"));
            Assert.That(spec.Transform, Is.EqualTo(fileName));
        }
Example #14
0
        public FormDataValidationResult Validate()
        {
            var result = new FormDataValidationResult();


            if (Title.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Title is required");
            }
            if (Description.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Description is required");
            }
            if (Constraints.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Constraints is required");
            }
            if (InputSpecification.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("InputSpecification is required");
            }
            if (OutputSpecification.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("OutputSpecification is required");
            }
            if (SampleInput.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("SampleInput is required");
            }
            if (SampleOutput.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("SampleOutput is required");
            }
            if (Notes.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Notes is required");
            }
            if (TimeLimit == 0 || TimeLimit > 20)
            {
                result.AddErrorMessage("TimeLimit is invalid");
            }
            if (MemoryLimit == 0 || MemoryLimit > 512)
            {
                result.AddErrorMessage("MemoryLimit is invalid");
            }
            if (string.IsNullOrEmpty(TestCaseInput))
            {
                result.AddErrorMessage("TestCaseInput is required");
            }
            if (string.IsNullOrEmpty(TestCaseOutput))
            {
                result.AddErrorMessage("TestCaseOutput is required");
            }

            return(result);
        }
        public void ResultOptionWithFilePathAndFormat()
        {
            var options = new NUnitLiteOptions("-result:results.xml;format=nunit2");

            Assert.True(options.Validate());

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("nunit2", spec.Format);
        }
        public void ExploreOptionWithFilePathAndFormat()
        {
            var options = new NUnitLiteOptions("-explore:results.xml;format=cases");

            Assert.True(options.Validate());
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("cases", spec.Format);
        }
Example #17
0
        public void ResultOptionWithFilePathAndTransform()
        {
            var options = new NUnitLiteOptions("-result:results.xml;transform=transform.xslt");

            Assert.True(options.Validate());

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            Assert.AreEqual("transform.xslt", spec.Transform);
        }
Example #18
0
        public void ResultOptionWithFilePathAndTransform()
        {
            ConsoleOptions options = new ConsoleOptions("tests.dll", "-result:results.xml;transform=transform.xslt");
            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);

            OutputSpecification spec = options.ResultOutputSpecifications[0];
            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            Assert.AreEqual("transform.xslt", spec.Transform);
        }
        public void ResultOptionWithFilePathAndFormat()
        {
            var options = new CommandLineOptions("-result:results.xml;format=nunit2");

            Assert.That(options.ErrorMessages, Is.Empty);

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("nunit2", spec.Format);
            Assert.Null(spec.Transform);
        }
        public void ResultOptionWithFilePathAndTransform()
        {
            var options = new CommandLineOptions("-result:results.xml;transform=transform.xslt");

            Assert.That(options.ErrorMessages, Is.Empty);

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            Assert.AreEqual("transform.xslt", spec.Transform);
        }
        public void ExploreOptionWithFilePathAndFormat()
        {
            var options = new CommandLineOptions("-explore:results.xml;format=cases");

            Assert.That(options.ErrorMessages, Is.Empty);
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.That(spec.OutputPath, Is.EqualTo("results.xml"));
            Assert.That(spec.Format, Is.EqualTo("cases"));
            Assert.Null(spec.Transform);
        }
        public void ExploreOptionWithFilePathAndTransform()
        {
            var options = new CommandLineOptions("-explore:results.xml;transform=myreport.xslt");

            Assert.That(options.ErrorMessages, Is.Empty);
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.That(spec.OutputPath, Is.EqualTo("results.xml"));
            Assert.That(spec.Format, Is.EqualTo("user"));
            Assert.That(spec.Transform, Is.EqualTo("myreport.xslt"));
        }
Example #23
0
        public void ExploreOptionWithFilePathAndTransform()
        {
            var options = new NUnitLiteOptions("-explore:results.xml;transform=myreport.xslt");

            Assert.True(options.Validate());
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            Assert.AreEqual("myreport.xslt", spec.Transform);
        }
Example #24
0
        public void ExploreOptionWithFilePath()
        {
            var options = new NUnitLiteOptions("-explore:results.xml");

            Assert.True(options.Validate());
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("nunit3", spec.Format);
            Assert.Null(spec.Transform);
        }
Example #25
0
        public void ExploreOptionWithFilePathAndFormat()
        {
            ConsoleOptions options = new ConsoleOptions("tests.dll", "-explore:results.xml;format=cases");
            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];
            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("cases", spec.Format);
            Assert.Null(spec.Transform);
        }
Example #26
0
        public void ResultOptionWithFilePathAndFormat()
        {
            ConsoleOptions options = ConsoleMocks.Options("tests.dll", "-result:results.xml;format=nunit2");

            Assert.That(options.Validate(), Is.True);
            Assert.That(options.InputFiles.Count, Is.EqualTo(1), "assembly should be set");
            Assert.That(options.InputFiles[0], Is.EqualTo("tests.dll"));

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.That(spec.OutputPath, Is.EqualTo("results.xml"));
            Assert.That(spec.Format, Is.EqualTo("nunit2"));
            Assert.Null(spec.Transform);
        }
Example #27
0
        public void ResultOptionWithFilePathAndFormat()
        {
            var options = new NUnitLiteOptions("tests.dll", "-result:results.xml;format=nunit2");

            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("nunit2", spec.Format);
            Assert.Null(spec.Transform);
        }
Example #28
0
        public void ExploreOptionWithFilePathAndTransform()
        {
            var options = new NUnitLiteOptions("tests.dll", "-explore:results.xml;transform=myreport.xslt");

            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            Assert.AreEqual("myreport.xslt", spec.Transform);
        }
Example #29
0
        public void ExploreOptionWithFilePath()
        {
            ConsoleOptions options = new ConsoleOptions("tests.dll", "-explore:results.xml");

            Assert.That(options.Validate(), Is.True);
            Assert.That(options.InputFiles.Count, Is.EqualTo(1), "assembly should be set");
            Assert.That(options.InputFiles[0], Is.EqualTo("tests.dll"));
            Assert.That(options.Explore, Is.True);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.That(spec.OutputPath, Is.EqualTo("results.xml"));
            Assert.That(spec.Format, Is.EqualTo("nunit3"));
            Assert.Null(spec.Transform);
        }
Example #30
0
        public void ExploreOptionWithFilePathAndTransform()
        {
            string         transformFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "TextSummary.xslt");
            IFileSystem    fileSystem    = GetFileSystemContainingFile(transformFile);
            ConsoleOptions options       = new ConsoleOptions(
                new DefaultOptionsProviderStub(false),
                fileSystem,
                "tests.dll", $"-explore:results.xml;transform={transformFile}");

            Assert.That(options.Validate(), Is.True);
            Assert.That(options.InputFiles.Count, Is.EqualTo(1), "assembly should be set");
            Assert.That(options.InputFiles[0], Is.EqualTo("tests.dll"));
            Assert.That(options.Explore, Is.True);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];

            Assert.That(spec.OutputPath, Is.EqualTo("results.xml"));
            Assert.That(spec.Format, Is.EqualTo("user"));
            var fullFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, transformFile);

            Assert.That(spec.Transform, Is.EqualTo(fullFilePath));
        }
Example #31
0
        public void ResultOptionWithFilePathAndTransform()
        {
            const string transformFile = "TextSummary.xslt";
            IFileSystem  fileSystem    = GetFileSystemContainingFile(transformFile);

            ConsoleOptions options = new ConsoleOptions(
                new DefaultOptionsProviderStub(false),
                fileSystem,
                "tests.dll", $"-result:results.xml;transform={transformFile}");

            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);

            OutputSpecification spec = options.ResultOutputSpecifications[0];

            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            var fullFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, transformFile);

            Assert.AreEqual(fullFilePath, spec.Transform);
        }
        /// <summary>
        /// Write the result of a test run according to a spec.
        /// </summary>
        /// <param name="result">The test result</param>
        /// <param name="spec">An output specification</param>
        /// <param name="runSettings">Settings</param>
        /// <param name="filter">Filter</param>
        public void WriteResultFile(ITestResult result, OutputSpecification spec, IDictionary <string, object> runSettings, TestFilter filter)
        {
            string       outputPath   = Path.Combine(_workDirectory, spec.OutputPath);
            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
            case "nunit3":
                outputWriter = new NUnit3XmlOutputWriter();
                break;

            case "nunit2":
                outputWriter = new NUnit2XmlOutputWriter();
                break;

            default:
                throw new ArgumentException(
                          string.Format("Invalid XML output format '{0}'", spec.Format),
                          nameof(spec));
            }

            outputWriter.WriteResultFile(result, outputPath, runSettings, filter);
            Console.WriteLine("Results ({0}) saved as {1}", spec.Format, outputPath);
        }
        /// <summary>
        /// Write out the result of exploring the tests
        /// </summary>
        /// <param name="test">The top-level test</param>
        /// <param name="spec">An OutputSpecification</param>
        public void WriteTestFile(ITest test, OutputSpecification spec)
        {
            string       outputPath   = Path.Combine(_workDirectory, spec.OutputPath);
            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
            case "nunit3":
                outputWriter = new NUnit3XmlOutputWriter();
                break;

            case "cases":
                outputWriter = new TestCaseOutputWriter();
                break;

            default:
                throw new ArgumentException(
                          string.Format("Invalid output format '{0}'", spec.Format),
                          nameof(spec));
            }

            outputWriter.WriteTestFile(test, outputPath);
            Console.WriteLine("Tests ({0}) saved as {1}", spec.Format, outputPath);
        }
Example #34
0
 private IResultWriter GetResultWriter(OutputSpecification spec)
 {
     return _resultService.GetResultWriter(spec.Format, new object[] {spec.Transform});
 }
Example #35
0
        /// <summary>
        /// Write the result of a test run according to a spec.
        /// </summary>
        /// <param name="result">The test result</param>
        /// <param name="spec">An output specification</param>
        /// <param name="runSettings">Settings</param>
        /// <param name="filter">Filter</param>
        public void WriteResultFile(ITestResult result, OutputSpecification spec, IDictionary <string, object> runSettings, TestFilter filter)
        {
            //string outputPath = Path.Combine(_workDirectory, spec.OutputPath);
            // [DuongNT][BEGIN]: Get configured file path output
            // Write results log
            ResultSummary summary   = new ResultSummary(result);
            int           totalTCT  = summary.TestCount;
            int           passedTCT = summary.PassCount;
            int           failedTCT = summary.FailedCount;
            int           blockTCT  = totalTCT - passedTCT - failedTCT;

            TLogger.Write("");
            TLogger.Write("#####Summary#####");
            TLogger.Write("##### Total #####");
            TLogger.Write("#####   " + totalTCT + "   #####");
            TLogger.Write("##### PASS #####");
            TLogger.Write("#####   " + passedTCT + "   #####");
            TLogger.Write("##### FAIL #####");
            TLogger.Write("#####   " + failedTCT + "   #####");
            TLogger.Write("##### BLOCK #####");
            TLogger.Write("#####   " + blockTCT + "   #####");
            TLogger.Write("##### Details #####");
            TLogger.Write("");

            string outputPath = TSettings.GetInstance().GetOutputFilePathName();

            if (outputPath == "")
            {
                outputPath = Path.Combine(_workDirectory, spec.OutputPath);
            }
            TLogger.Write("Completed test-suite's execution!");
            TLogger.Write("Writing results to: " + outputPath + "...");
            // [DuongNT][END]: Get configured file path output

            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
            case "nunit3":
                outputWriter = new NUnit3XmlOutputWriter();
                break;

            case "nunit2":
                outputWriter = new NUnit2XmlOutputWriter();
                break;

            //case "user":
            //    Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            //    string dir = Path.GetDirectoryName(uri.LocalPath);
            //    outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform));
            //    break;

            default:
                throw new ArgumentException(
                          string.Format("Invalid XML output format '{0}'", spec.Format),
                          "spec");
            }

            outputWriter.WriteResultFile(result, outputPath, runSettings, filter);
            TLogger.Write("Results saved to: " + outputPath);
        }