/// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyDiscoveryStarting"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="discoveryOptions">The discovery options</param>
 /// <param name="executionOptions">The execution options</param>
 public TestAssemblyDiscoveryStarting(XunitProjectAssembly assembly,
                                      ITestFrameworkDiscoveryOptions discoveryOptions,
                                      ITestFrameworkExecutionOptions executionOptions)
 {
     Assembly = assembly;
     DiscoveryOptions = discoveryOptions;
     ExecutionOptions = executionOptions;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyExecutionFinished"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="executionOptions">The execution options</param>
 /// <param name="executionSummary">The execution summary</param>
 public TestAssemblyExecutionFinished(XunitProjectAssembly assembly,
                                      ITestFrameworkExecutionOptions executionOptions,
                                      ExecutionSummary executionSummary)
 {
     Assembly = assembly;
     ExecutionOptions = executionOptions;
     ExecutionSummary = executionSummary;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyDiscoveryStarting"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="appDomain">Indicates whether the tests will be discovered and run in a separate app domain</param>
 /// <param name="discoveryOptions">The discovery options</param>
 public TestAssemblyDiscoveryStarting(XunitProjectAssembly assembly,
                                      bool appDomain,
                                      ITestFrameworkDiscoveryOptions discoveryOptions)
 {
     Assembly = assembly;
     AppDomain = appDomain;
     DiscoveryOptions = discoveryOptions;
 }
Example #4
0
        public void ProjectIsDirtyWhenAddingAssembly()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();

            project.AddAssembly(assembly);

            Assert.True(project.IsDirty);
        }
Example #5
0
        public void AddedAssemblyIsPartOfAssemblyList()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();

            project.AddAssembly(assembly);

            Assert.Contains(assembly, project.Assemblies);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyDiscoveryFinished"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="discoveryOptions">The discovery options</param>
 /// <param name="testCasesDiscovered">The number of test cases discovered</param>
 /// <param name="testCasesToRun">The number of test cases to be run</param>
 public TestAssemblyDiscoveryFinished(XunitProjectAssembly assembly,
                                      ITestFrameworkDiscoveryOptions discoveryOptions,
                                      int testCasesDiscovered,
                                      int testCasesToRun)
 {
     Assembly = assembly;
     DiscoveryOptions = discoveryOptions;
     TestCasesDiscovered = testCasesDiscovered;
     TestCasesToRun = testCasesToRun;
 }
    public void UnknownTransform()
    {
        var assembly = new XunitProjectAssembly();
        assembly.Output["unknown"] = "foo.xml";
        var factory = new TestableTransformFactory();

        Exception ex = Record.Exception(() => factory.GetTransforms(assembly));

        Assert.IsType<ArgumentException>(ex);
        Assert.Equal("unknown output transform: unknown", ex.Message);
    }
Example #8
0
        public void ProjectIsDirtyWhenRemovingAssembly()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();
            project.AddAssembly(assembly);
            project.IsDirty = false;

            project.RemoveAssembly(assembly);

            Assert.True(project.IsDirty);
        }
Example #9
0
        public void ProjectIsMarkedCleanWhenSaved()
        {
            using (var tempFile = new TempFile())
            {
                var project = new XunitProject();
                var assembly = new XunitProjectAssembly { AssemblyFilename = @"C:\FooBar" };
                project.AddAssembly(assembly);

                project.SaveAs(tempFile.Filename);

                Assert.False(project.IsDirty);
            }
        }
    public void KnownTransformWithValidXslFile()
    {
        var config = new XunitConsoleConfigurationSection();
        config.Transforms = new TestableTransformConfigItem("known", "xslFile.xsl");
        var assembly = new XunitProjectAssembly();
        assembly.Output["known"] = "foo.xml";
        var factory = new TestableTransformFactory(config);

        List<IResultXmlTransform> transforms = factory.GetTransforms(assembly);

        IResultXmlTransform transform = Assert.Single(transforms);
        var xslTransform = Assert.IsType<XslStreamTransformer>(transform);
        Assert.Equal("foo.xml", xslTransform.OutputFilename);
        Assert.Equal("xslFile.xsl", Path.GetFileName(xslTransform.XslFilename));
    }
    public void KnownTransformWithMissingXslFile()
    {
        var config = new XunitConsoleConfigurationSection();
        config.Transforms = new TestableTransformConfigItem("known", "xslFile.xsl");
        var assembly = new XunitProjectAssembly();
        assembly.Output["known"] = "foo.xml";
        var factory = new TestableTransformFactory(config);
        factory.FileExistsResult = false;

        Exception ex = Record.Exception(() => factory.GetTransforms(assembly));

        Assert.IsType<ArgumentException>(ex);
        Assert.Contains("cannot find transform XSL file", ex.Message);
        Assert.Contains("xslFile.xsl", ex.Message);
        Assert.Contains("for transform 'known'", ex.Message);
    }
Example #12
0
        public void SaveAcceptanceTest()
        {
            string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <xunit>
              <assemblies>
            <assembly filename=""C:\AssemblyFilename"" config-filename=""C:\ConfigFilename"" shadow-copy=""true"">
              <output type=""xml"" filename=""C:\XmlFilename"" />
              <output type=""html"" filename=""C:\HtmlFilename"" />
            </assembly>
            <assembly filename=""C:\AssemblyFilename2"" config-filename=""C:\ConfigFilename2"" shadow-copy=""false"">
              <output type=""xml"" filename=""C:\XmlFilename2"" />
              <output type=""html"" filename=""C:\HtmlFilename2"" />
            </assembly>
              </assemblies>
            </xunit>";

            using (TempFile tempFile = new TempFile())
            {
                XunitProject project = new XunitProject { Filename = tempFile.Filename };
                XunitProjectAssembly assembly1 = new XunitProjectAssembly();
                assembly1.AssemblyFilename = @"C:\AssemblyFilename";
                assembly1.ConfigFilename = @"C:\ConfigFilename";
                assembly1.ShadowCopy = true;
                assembly1.Output.Add("xml", @"C:\XmlFilename");
                assembly1.Output.Add("html", @"C:\HtmlFilename");
                project.AddAssembly(assembly1);
                XunitProjectAssembly assembly2 = new XunitProjectAssembly();
                assembly2.AssemblyFilename = @"C:\AssemblyFilename2";
                assembly2.ConfigFilename = @"C:\ConfigFilename2";
                assembly2.ShadowCopy = false;
                assembly2.Output.Add("xml", @"C:\XmlFilename2");
                assembly2.Output.Add("html", @"C:\HtmlFilename2");
                project.AddAssembly(assembly2);

                project.Save();

                Assert.Equal(expectedXml, File.ReadAllText(tempFile.Filename));
            }
        }
Example #13
0
        public void UnknownAssemblyDoesNotThrow()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();

            Assert.DoesNotThrow(() => project.RemoveAssembly(assembly));
        }
Example #14
0
        public void RemovesAssemblyFromAssembliesList()
        {
            XunitProject project = new XunitProject();
            XunitProjectAssembly assembly = new XunitProjectAssembly();
            project.AddAssembly(assembly);

            project.RemoveAssembly(assembly);

            Assert.DoesNotContain(assembly, project.Assemblies);
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyDiscoveryStarting"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="discoveryOptions">The discovery options</param>
 public TestAssemblyDiscoveryStarting(XunitProjectAssembly assembly,
                                      ITestFrameworkDiscoveryOptions discoveryOptions)
 {
     Assembly         = assembly;
     DiscoveryOptions = discoveryOptions;
 }
Example #16
0
        /// <summary>
        /// Loads an xUnit.net Test Project file from disk.
        /// </summary>
        /// <param name="filename">The test project filename</param>
        public static XunitProject Load(string filename)
        {
            filename = Path.GetFullPath(filename);
            string directory = Path.GetDirectoryName(filename);
            XmlDocument doc = new XmlDocument();
            XunitProject result = new XunitProject { Filename = filename };

            try
            {
                doc.Load(filename);
            }
            catch (XmlException)
            {
                throw new ArgumentException("The xUnit.net project file appears to be malformed.", "filename");
            }

            foreach (XmlNode assemblyNode in doc.SelectNodes("xunit/assemblies/assembly"))
            {
                XunitProjectAssembly assembly = new XunitProjectAssembly
                {
                    AssemblyFilename = Path.GetFullPath(Path.Combine(directory, assemblyNode.Attributes["filename"].Value))
                };

                if (assemblyNode.Attributes["config-filename"] != null)
                    assembly.ConfigFilename = Path.GetFullPath(Path.Combine(directory, assemblyNode.Attributes["config-filename"].Value));
                if (assemblyNode.Attributes["shadow-copy"] != null)
                    assembly.ShadowCopy = Boolean.Parse(assemblyNode.Attributes["shadow-copy"].Value);

                foreach (XmlNode outputNode in assemblyNode.SelectNodes("output"))
                    assembly.Output.Add(outputNode.Attributes["type"].Value,
                                        Path.GetFullPath(Path.Combine(directory, outputNode.Attributes["filename"].Value)));

                result.assemblies.Add(assembly);
            }

            if (result.assemblies.Count == 0)
                throw new ArgumentException("The xUnit.net project file has no assemblies.", "filename");

            return result;
        }
Example #17
0
        /// <summary>
        /// Removes assembly from the assembly list
        /// </summary>
        /// <param name="assembly">The assembly to be removed</param>
        public void RemoveAssembly(XunitProjectAssembly assembly)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            assemblies.Remove(assembly);
            IsDirty = true;
        }
 /// <summary>
 /// Gets the display name of a test assembly from a test assembly message.
 /// </summary>
 /// <param name="assembly">The test assembly</param>
 /// <returns>The assembly display name</returns>
 protected virtual string GetAssemblyDisplayName(XunitProjectAssembly assembly)
 {
     return(Path.GetFileNameWithoutExtension(assembly.AssemblyFilename));
 }
Example #19
0
        public void FilenameIsUpdated()
        {
            using (TempFile tempFile = new TempFile())
            {
                XunitProject project = new XunitProject();
                XunitProjectAssembly assembly = new XunitProjectAssembly { AssemblyFilename = @"C:\FooBar" };
                project.AddAssembly(assembly);

                project.SaveAs(tempFile.Filename);

                Assert.Equal(tempFile.Filename, project.Filename);
            }
        }
 /// <summary>
 /// Gets the display name of a test assembly from a test assembly message.
 /// </summary>
 /// <param name="assembly">The test assembly</param>
 /// <returns>The assembly display name</returns>
 protected virtual string GetAssemblyDisplayName(XunitProjectAssembly assembly)
     => Path.GetFileNameWithoutExtension(assembly.AssemblyFilename);
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyExecutionStarting"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="executionOptions">The execution options</param>
 public TestAssemblyExecutionStarting(XunitProjectAssembly assembly,
                                      ITestFrameworkExecutionOptions executionOptions)
 {
     Assembly = assembly;
     ExecutionOptions = executionOptions;
 }
Example #22
0
        public IEnumerable<AutoTest.TestRunners.Shared.Results.TestResult> Run(RunSettings settings)
        {
            var logger = new XUnitLogger();
            XunitProject project = new XunitProject();

            var runner = settings.Assembly;
            // Set assembly externally as XUnit screws up the casing
            logger.SetCurrentAssembly(runner.Assembly);

            XunitProjectAssembly assembly = new XunitProjectAssembly
            {
                AssemblyFilename = runner.Assembly,
                ConfigFilename = null,
                ShadowCopy = false
            };
            project.AddAssembly(assembly);

            foreach (XunitProjectAssembly asm in project.Assemblies)
            {
                using (ExecutorWrapper wrapper = new ExecutorWrapper(asm.AssemblyFilename, asm.ConfigFilename, asm.ShadowCopy))
                {
                    try
                    {
                        var xunitRunner = new TestRunner(wrapper, logger);
                        //Run all tests
                        if (runner.Tests.Count() == 0 && runner.Members.Count() == 0 && runner.Namespaces.Count() == 0)
                            xunitRunner.RunAssembly();
                        //Run tests
                        if (runner.Tests.Count() > 0)
                        {
                            foreach (var test in runner.Tests)
                                xunitRunner.RunTest(test.Substring(0, test.LastIndexOf(".")), test.Substring(test.LastIndexOf(".") + 1, test.Length - (test.LastIndexOf(".") + 1)));
                        }
                        //Run members
                        if (runner.Members.Count() > 0)
                        {
                            foreach (var member in runner.Members)
                                xunitRunner.RunClass(member);
                        }
                        //Run namespaces
                        if (runner.Namespaces.Count() > 0)
                        {
                            var loadedAssembly = Assembly.LoadFrom(runner.Assembly);
                            var types = loadedAssembly.GetExportedTypes();
                            loadedAssembly = null;
                            foreach (var ns in runner.Namespaces)
                            {
                                foreach (Type type in types)
                                    if (ns == null || type.Namespace == ns)
                                        xunitRunner.RunClass(type.FullName);
                            }
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            return logger.Results;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyExecutionStarting"/> class.
 /// </summary>
 /// <param name="assembly">Information about the assembly that is being discovered</param>
 /// <param name="executionOptions">The execution options</param>
 public TestAssemblyExecutionStarting(XunitProjectAssembly assembly,
                                      ITestFrameworkExecutionOptions executionOptions)
 {
     Assembly         = assembly;
     ExecutionOptions = executionOptions;
 }