Esempio n. 1
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly.
        /// </summary>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(string assemblyFileName, string configFileName = null)
        {
            if (configFileName == null)
            {
                configFileName = assemblyFileName + ".config";
            }

            var result = new TestAssemblyConfiguration();

            try
            {
                var map = new ExeConfigurationFileMap {
                    ExeConfigFilename = configFileName
                };
                var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
                if (config != null && config.AppSettings != null)
                {
                    var settings = config.AppSettings.Settings;

                    result.DiagnosticMessages         = GetBoolean(settings, TestOptionsNames.Configuration.DiagnosticMessages, result.DiagnosticMessages);
                    result.MaxParallelThreads         = GetInt(settings, TestOptionsNames.Configuration.MaxParallelThreads, result.MaxParallelThreads);
                    result.MethodDisplay              = GetEnum(settings, TestOptionsNames.Configuration.MethodDisplay, result.MethodDisplay);
                    result.ParallelizeAssembly        = GetBoolean(settings, TestOptionsNames.Configuration.ParallelizeAssembly, result.ParallelizeAssembly);
                    result.ParallelizeTestCollections = GetBoolean(settings, TestOptionsNames.Configuration.ParallelizeTestCollections, result.ParallelizeTestCollections);
                    result.PreEnumerateTheories       = GetBoolean(settings, TestOptionsNames.Configuration.PreEnumerateTheories, result.PreEnumerateTheories);
                }
            }
            catch (ConfigurationErrorsException) { }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly.
        /// </summary>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(string assemblyFileName, string configFileName = null)
        {
            if (configFileName == null)
            {
                configFileName = assemblyFileName + ".config";
            }

            var result = new TestAssemblyConfiguration();

            try
            {
                using (var stream = File.OpenRead(configFileName))
                {
                    var document    = XDocument.Load(stream);
                    var appSettings = document.Root.Element("appSettings");

                    if (appSettings != null)
                    {
                        foreach (var add in appSettings.Elements("add"))
                        {
                            var key   = add.Attribute("key");
                            var value = add.Attribute("value");

                            if (key != null && value != null)
                            {
                                if (key.Value.Equals(TestOptionsNames.Configuration.DiagnosticMessages, StringComparison.OrdinalIgnoreCase))
                                {
                                    result.DiagnosticMessages = GetBoolean(value.Value, result.DiagnosticMessages);
                                }
                                else if (key.Value.Equals(TestOptionsNames.Configuration.MaxParallelThreads, StringComparison.OrdinalIgnoreCase))
                                {
                                    result.MaxParallelThreads = GetInt(value.Value, result.MaxParallelThreads);
                                }
                                else if (key.Value.Equals(TestOptionsNames.Configuration.MethodDisplay, StringComparison.OrdinalIgnoreCase))
                                {
                                    result.MethodDisplay = GetEnum(value.Value, result.MethodDisplay);
                                }
                                else if (key.Value.Equals(TestOptionsNames.Configuration.ParallelizeAssembly, StringComparison.OrdinalIgnoreCase))
                                {
                                    result.ParallelizeAssembly = GetBoolean(value.Value, result.ParallelizeAssembly);
                                }
                                else if (key.Value.Equals(TestOptionsNames.Configuration.ParallelizeTestCollections, StringComparison.OrdinalIgnoreCase))
                                {
                                    result.ParallelizeTestCollections = GetBoolean(value.Value, result.ParallelizeTestCollections);
                                }
                                else if (key.Value.Equals(TestOptionsNames.Configuration.PreEnumerateTheories, StringComparison.OrdinalIgnoreCase))
                                {
                                    result.PreEnumerateTheories = GetBoolean(value.Value, result.PreEnumerateTheories);
                                }
                            }
                        }
                    }
                }
            }
            catch { }

            return(result);
        }
Esempio n. 3
0
 AssemblyRunner(bool useAppDomain,
                string assemblyFileName,
                string configFileName   = null,
                bool shadowCopy         = true,
                string shadowCopyFolder = null)
 {
     controller    = new XunitFrontController(useAppDomain, assemblyFileName, configFileName, shadowCopy, shadowCopyFolder, diagnosticMessageSink: this);
     configuration = ConfigReader.Load(assemblyFileName, configFileName);
 }
Esempio n. 4
0
        public static ITestFrameworkExecutionOptions ForExecution(TestAssemblyConfiguration configuration = null)
        {
            ITestFrameworkExecutionOptions result = new TestFrameworkOptions();

            if (configuration != null)
            {
                result.SetDiagnosticMessages(configuration.DiagnosticMessages);
                result.SetDisableParallelization(!configuration.ParallelizeTestCollections);
                result.SetMaxParallelThreads(configuration.MaxParallelThreads);
            }

            return(result);
        }
Esempio n. 5
0
        public static ITestFrameworkDiscoveryOptions ForDiscovery(TestAssemblyConfiguration configuration = null)
        {
            ITestFrameworkDiscoveryOptions result = new TestFrameworkOptions();

            if (configuration != null)
            {
                result.SetDiagnosticMessages(configuration.DiagnosticMessages);
                result.SetMethodDisplay(configuration.MethodDisplay);
                result.SetPreEnumerateTheories(configuration.PreEnumerateTheories);
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly.
        /// </summary>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(string assemblyFileName, string configFileName = null)
        {
            if (configFileName == null)
            {
                configFileName = assemblyFileName + ".config";
            }

            if (configFileName.EndsWith(".config", StringComparison.Ordinal))
            {
                try
                {
                    var map = new ExeConfigurationFileMap {
                        ExeConfigFilename = configFileName
                    };
                    var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
                    if (config != null && config.AppSettings != null)
                    {
                        var result   = new TestAssemblyConfiguration();
                        var settings = config.AppSettings.Settings;

                        result.AppDomain                  = GetEnum <AppDomainSupport>(settings, Configuration.AppDomain) ?? result.AppDomain;
                        result.DiagnosticMessages         = GetBoolean(settings, Configuration.DiagnosticMessages) ?? result.DiagnosticMessages;
                        result.InternalDiagnosticMessages = GetBoolean(settings, Configuration.InternalDiagnosticMessages) ?? result.InternalDiagnosticMessages;
                        result.MaxParallelThreads         = GetInt(settings, Configuration.MaxParallelThreads) ?? result.MaxParallelThreads;
                        result.MethodDisplay              = GetEnum <TestMethodDisplay>(settings, Configuration.MethodDisplay) ?? result.MethodDisplay;
                        result.MethodDisplayOptions       = GetEnum <TestMethodDisplayOptions>(settings, Configuration.MethodDisplayOptions) ?? result.MethodDisplayOptions;
                        result.ParallelizeAssembly        = GetBoolean(settings, Configuration.ParallelizeAssembly) ?? result.ParallelizeAssembly;
                        result.ParallelizeTestCollections = GetBoolean(settings, Configuration.ParallelizeTestCollections) ?? result.ParallelizeTestCollections;
                        result.PreEnumerateTheories       = GetBoolean(settings, Configuration.PreEnumerateTheories) ?? result.PreEnumerateTheories;
                        result.ShadowCopy                 = GetBoolean(settings, Configuration.ShadowCopy) ?? result.ShadowCopy;
                        result.StopOnFail                 = GetBoolean(settings, Configuration.StopOnFail) ?? result.StopOnFail;
                        result.LongRunningTestSeconds     = GetInt(settings, Configuration.LongRunningTestSeconds) ?? result.LongRunningTestSeconds;

                        return(result);
                    }
                }
                catch { }
            }

            return(null);
        }
Esempio n. 7
0
        protected override async Task <ITestResult> RunInternalAsync(ITestFilter filter)
        {
            _tcsRun = new TaskCompletionSource <ITestResult>();

            var config = new xu.TestAssemblyConfiguration();

            _cancel = false;
            _testsToRun.Clear();
            _testSuiteStarted = new HashSet <TestSuiteWrapper>();
            _testSuiteStatus  = new Dictionary <TestSuiteWrapper, TestStatus>();
            messageHandler    = FilterTestCases;
            _filter           = filter;
            _tcsFilter        = new TaskCompletionSource <int>();
            controller.Find(false, this, xu.TestFrameworkOptions.ForDiscovery(config));
            await _tcsFilter.Task;

            messageHandler = RunMessageHandler;
            controller.RunTests(_testsToRun, this, xu.TestFrameworkOptions.ForExecution(config));

            return(await _tcsRun.Task);
        }
Esempio n. 8
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly.
        /// </summary>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(string assemblyFileName, string configFileName = null)
        {
            if (FileOpenRead == null)
                throw new InvalidOperationException("Runner authors in .NET Core must set ConfigReader_Json.FileOpenRead.");

            if (configFileName == null)
                configFileName = Path.Combine(Path.GetDirectoryName(assemblyFileName), "xunit.runner.json");

            if (configFileName.EndsWith(".json", StringComparison.Ordinal))
            {
                try
                {
                    var result = new TestAssemblyConfiguration();

                    using (var stream = FileOpenRead(configFileName))
                    using (var reader = new StreamReader(stream))
                    {
                        var config = JsonDeserializer.Deserialize(reader) as JsonObject;

                        foreach (var propertyName in config.Keys)
                        {
                            var propertyValue = config.Value(propertyName);
                            var booleanValue = propertyValue as JsonBoolean;

                            if (booleanValue != null)
                            {
                                if (string.Equals(propertyName, Configuration.DiagnosticMessages, StringComparison.OrdinalIgnoreCase))
                                    result.DiagnosticMessages = booleanValue;
                                if (string.Equals(propertyName, Configuration.ParallelizeAssembly, StringComparison.OrdinalIgnoreCase))
                                    result.ParallelizeAssembly = booleanValue;
                                if (string.Equals(propertyName, Configuration.ParallelizeTestCollections, StringComparison.OrdinalIgnoreCase))
                                    result.ParallelizeTestCollections = booleanValue;
                                if (string.Equals(propertyName, Configuration.PreEnumerateTheories, StringComparison.OrdinalIgnoreCase))
                                    result.PreEnumerateTheories = booleanValue;
                                if (string.Equals(propertyName, Configuration.UseAppDomain, StringComparison.OrdinalIgnoreCase))
                                    result.UseAppDomain = booleanValue;
                            }
                            else if (string.Equals(propertyName, Configuration.MaxParallelThreads, StringComparison.OrdinalIgnoreCase))
                            {
                                var numberValue = propertyValue as JsonNumber;
                                if (numberValue != null)
                                {
                                    int maxParallelThreads;
                                    if (int.TryParse(numberValue.Raw, out maxParallelThreads) && maxParallelThreads > 0)
                                        result.MaxParallelThreads = maxParallelThreads;
                                }
                            }
                            else if (string.Equals(propertyName, Configuration.MethodDisplay, StringComparison.OrdinalIgnoreCase))
                            {
                                var stringValue = propertyValue as JsonString;
                                if (stringValue != null)
                                {
                                    try
                                    {
                                        var methodDisplay = Enum.Parse(typeof(TestMethodDisplay), stringValue, true);
                                        result.MethodDisplay = (TestMethodDisplay)methodDisplay;
                                    }
                                    catch { }
                                }
                            }
                        }
                    }

                    return result;
                }
                catch { }
            }

            return null;
        }
Esempio n. 9
0
        protected override XElement ExecuteAssembly(string assemblyFilename, string configFileName, TestAssemblyConfiguration configuration)
        {
            ExecuteAssembly_Calls.Add(string.Format("{0}, {1}", assemblyFilename ?? "(null)", configFileName ?? "(null)"));

            return base.ExecuteAssembly(assemblyFilename, configFileName, configuration);
        }
Esempio n. 10
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly from a JSON stream. Caller is responsible for opening the stream.
        /// </summary>
        /// <param name="configStream">Stream containing config for an assembly</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(Stream configStream)
        {
            var result = new TestAssemblyConfiguration();

            try
            {
                using (var reader = new StreamReader(configStream))
                {
                    var config = JsonDeserializer.Deserialize(reader) as JsonObject;

                    foreach (var propertyName in config.Keys)
                    {
                        var propertyValue = config.Value(propertyName);
                        var booleanValue  = propertyValue as JsonBoolean;

                        if (booleanValue != null)
                        {
                            if (string.Equals(propertyName, Configuration.DiagnosticMessages, StringComparison.OrdinalIgnoreCase))
                            {
                                result.DiagnosticMessages = booleanValue;
                            }
                            if (string.Equals(propertyName, Configuration.InternalDiagnosticMessages, StringComparison.OrdinalIgnoreCase))
                            {
                                result.InternalDiagnosticMessages = booleanValue;
                            }
                            if (string.Equals(propertyName, Configuration.ParallelizeAssembly, StringComparison.OrdinalIgnoreCase))
                            {
                                result.ParallelizeAssembly = booleanValue;
                            }
                            if (string.Equals(propertyName, Configuration.ParallelizeTestCollections, StringComparison.OrdinalIgnoreCase))
                            {
                                result.ParallelizeTestCollections = booleanValue;
                            }
                            if (string.Equals(propertyName, Configuration.PreEnumerateTheories, StringComparison.OrdinalIgnoreCase))
                            {
                                result.PreEnumerateTheories = booleanValue;
                            }
                            if (string.Equals(propertyName, Configuration.ShadowCopy, StringComparison.OrdinalIgnoreCase))
                            {
                                result.ShadowCopy = booleanValue;
                            }
                            if (string.Equals(propertyName, Configuration.StopOnFail, StringComparison.OrdinalIgnoreCase))
                            {
                                result.StopOnFail = booleanValue;
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.MaxParallelThreads, StringComparison.OrdinalIgnoreCase))
                        {
                            var numberValue = propertyValue as JsonNumber;
                            if (numberValue != null)
                            {
                                int maxParallelThreads;
                                if (int.TryParse(numberValue.Raw, out maxParallelThreads) && maxParallelThreads >= -1)
                                {
                                    result.MaxParallelThreads = maxParallelThreads;
                                }
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.LongRunningTestSeconds, StringComparison.OrdinalIgnoreCase))
                        {
                            var numberValue = propertyValue as JsonNumber;
                            if (numberValue != null)
                            {
                                int seconds;
                                if (int.TryParse(numberValue.Raw, out seconds) && seconds > 0)
                                {
                                    result.LongRunningTestSeconds = seconds;
                                }
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.MethodDisplay, StringComparison.OrdinalIgnoreCase))
                        {
                            var stringValue = propertyValue as JsonString;
                            if (stringValue != null)
                            {
                                try
                                {
                                    var methodDisplay = Enum.Parse(typeof(TestMethodDisplay), stringValue, true);
                                    result.MethodDisplay = (TestMethodDisplay)methodDisplay;
                                }
                                catch { }
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.MethodDisplayOptions, StringComparison.OrdinalIgnoreCase))
                        {
                            var stringValue = propertyValue as JsonString;
                            if (stringValue != null)
                            {
                                try
                                {
                                    var methodDisplayOptions = Enum.Parse(typeof(TestMethodDisplayOptions), stringValue, true);
                                    result.MethodDisplayOptions = (TestMethodDisplayOptions)methodDisplayOptions;
                                }
                                catch { }
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.AppDomain, StringComparison.OrdinalIgnoreCase))
                        {
                            var stringValue = propertyValue as JsonString;
                            if (stringValue != null)
                            {
                                try
                                {
                                    var appDomain = Enum.Parse(typeof(AppDomainSupport), stringValue, true);
                                    result.AppDomain = (AppDomainSupport)appDomain;
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
            catch { }

            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly from a JSON stream. Caller is responsible for opening the stream.
        /// </summary>
        /// <param name="configStream">Stream containing config for an assembly</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(Stream configStream)
        {
            var result = new TestAssemblyConfiguration();

            try
            {
                using (var reader = new StreamReader(configStream))
                {
                    var config = JsonDeserializer.Deserialize(reader) as JsonObject;

                    foreach (var propertyName in config.Keys)
                    {
                        var propertyValue = config.Value(propertyName);
                        var booleanValue = propertyValue as JsonBoolean;

                        if (booleanValue != null)
                        {
                            if (string.Equals(propertyName, Configuration.DiagnosticMessages, StringComparison.OrdinalIgnoreCase))
                                result.DiagnosticMessages = booleanValue;
                            if (string.Equals(propertyName, Configuration.ParallelizeAssembly, StringComparison.OrdinalIgnoreCase))
                                result.ParallelizeAssembly = booleanValue;
                            if (string.Equals(propertyName, Configuration.ParallelizeTestCollections, StringComparison.OrdinalIgnoreCase))
                                result.ParallelizeTestCollections = booleanValue;
                            if (string.Equals(propertyName, Configuration.PreEnumerateTheories, StringComparison.OrdinalIgnoreCase))
                                result.PreEnumerateTheories = booleanValue;
                            if (string.Equals(propertyName, Configuration.ShadowCopy, StringComparison.OrdinalIgnoreCase))
                                result.ShadowCopy = booleanValue;
                        }
                        else if (string.Equals(propertyName, Configuration.MaxParallelThreads, StringComparison.OrdinalIgnoreCase))
                        {
                            var numberValue = propertyValue as JsonNumber;
                            if (numberValue != null)
                            {
                                int maxParallelThreads;
                                if (int.TryParse(numberValue.Raw, out maxParallelThreads) && maxParallelThreads > 0)
                                    result.MaxParallelThreads = maxParallelThreads;
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.LongRunningTestSeconds, StringComparison.OrdinalIgnoreCase))
                        {
                            var numberValue = propertyValue as JsonNumber;
                            if (numberValue != null)
                            {
                                int seconds;
                                if (int.TryParse(numberValue.Raw, out seconds) && seconds > 0)
                                    result.LongRunningTestSeconds = seconds;
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.MethodDisplay, StringComparison.OrdinalIgnoreCase))
                        {
                            var stringValue = propertyValue as JsonString;
                            if (stringValue != null)
                            {
                                try
                                {
                                    var methodDisplay = Enum.Parse(typeof(TestMethodDisplay), stringValue, true);
                                    result.MethodDisplay = (TestMethodDisplay)methodDisplay;
                                }
                                catch { }
                            }
                        }
                        else if (string.Equals(propertyName, Configuration.AppDomain, StringComparison.OrdinalIgnoreCase))
                        {
                            var stringValue = propertyValue as JsonString;
                            if (stringValue != null)
                            {
                                try
                                {
                                    var appDomain = Enum.Parse(typeof(AppDomainSupport), stringValue, true);
                                    result.AppDomain = (AppDomainSupport)appDomain;
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
            catch { }

            return result;
        }
Esempio n. 12
0
        /// <summary>
        /// Loads the test assembly configuration for the given test assembly.
        /// </summary>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <returns>The test assembly configuration.</returns>
        public static TestAssemblyConfiguration Load(string assemblyFileName, string configFileName = null)
        {
            if (configFileName == null)
            {
                configFileName = Path.Combine(Path.GetDirectoryName(assemblyFileName), "xunit.runner.json");
            }

            if (configFileName.EndsWith(".json", StringComparison.Ordinal))
            {
                try
                {
                    var result = new TestAssemblyConfiguration();

                    using (var stream = File_OpenRead(configFileName))
                        using (var reader = new StreamReader(stream))
                        {
                            var config = JsonDeserializer.Deserialize(reader) as JsonObject;

                            foreach (var propertyName in config.Keys)
                            {
                                var propertyValue = config.Value(propertyName);
                                var booleanValue  = propertyValue as JsonBoolean;

                                if (booleanValue != null)
                                {
                                    if (string.Equals(propertyName, Configuration.DiagnosticMessages, StringComparison.OrdinalIgnoreCase))
                                    {
                                        result.DiagnosticMessages = booleanValue;
                                    }
                                    if (string.Equals(propertyName, Configuration.ParallelizeAssembly, StringComparison.OrdinalIgnoreCase))
                                    {
                                        result.ParallelizeAssembly = booleanValue;
                                    }
                                    if (string.Equals(propertyName, Configuration.ParallelizeTestCollections, StringComparison.OrdinalIgnoreCase))
                                    {
                                        result.ParallelizeTestCollections = booleanValue;
                                    }
                                    if (string.Equals(propertyName, Configuration.PreEnumerateTheories, StringComparison.OrdinalIgnoreCase))
                                    {
                                        result.PreEnumerateTheories = booleanValue;
                                    }
                                }
                                else if (string.Equals(propertyName, Configuration.MaxParallelThreads, StringComparison.OrdinalIgnoreCase))
                                {
                                    var numberValue = propertyValue as JsonNumber;
                                    if (numberValue != null)
                                    {
                                        int maxParallelThreads;
                                        if (int.TryParse(numberValue.Raw, out maxParallelThreads) && maxParallelThreads > 0)
                                        {
                                            result.MaxParallelThreads = maxParallelThreads;
                                        }
                                    }
                                }
                                else if (string.Equals(propertyName, Configuration.MethodDisplay, StringComparison.OrdinalIgnoreCase))
                                {
                                    var stringValue = propertyValue as JsonString;
                                    if (stringValue != null)
                                    {
                                        try
                                        {
                                            var methodDisplay = Enum.Parse(typeof(TestMethodDisplay), stringValue, true);
                                            result.MethodDisplay = (TestMethodDisplay)methodDisplay;
                                        }
                                        catch { }
                                    }
                                }
                                else if (string.Equals(propertyName, Configuration.AppDomain, StringComparison.OrdinalIgnoreCase))
                                {
                                    var stringValue = propertyValue as JsonString;
                                    if (stringValue != null)
                                    {
                                        try
                                        {
                                            var appDomain = Enum.Parse(typeof(AppDomainSupport), stringValue, true);
                                            result.AppDomain = (AppDomainSupport)appDomain;
                                        }
                                        catch { }
                                    }
                                }
                            }
                        }

                    return(result);
                }
                catch { }
            }

            return(null);
        }