Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionInfo"/> class.
        /// </summary>
        /// <param name="commandLineArguments">The command line arguments.</param>
        /// <param name="configuration">The configuration.</param>
        public SessionInfo(CommandLineArguments commandLineArguments, CodeCoverageUtilConfiguration configuration)
        {
            assembliesDirectory = Path.Combine(configuration.TempPath, "Assemblies");

            resultsDirectory = Path.Combine(configuration.ResultsPath, "Latest");

            assemblyBackupDirectory = Path.Combine(configuration.TempPath, "Backup");

            coverageReportDirectory = Path.Combine(resultsDirectory, "CoverageReport");

            CoverageResultsFile = Path.Combine(ResultsDirectory, CoverageResultsFileName);

            CommandLineArguments = commandLineArguments;
            Configuration        = configuration;

            NoResults = configuration.NoResults;
            if (commandLineArguments.NoResults.HasValue)
            {
                NoResults = commandLineArguments.NoResults.Value;
            }

            details.AddRange(configuration.Details);
            details.AddRange(commandLineArguments.Details);
            details = details.Distinct().ToList <string>();

            if (!string.IsNullOrEmpty(commandLineArguments.TestSourceFilePath) &&
                !string.IsNullOrEmpty(commandLineArguments.TestAssemblyFilePath) &&
                commandLineArguments.LineNumber > 0)
            {
                TestCodeContext = new TestCodeContext(
                    commandLineArguments.TestSourceFilePath,
                    commandLineArguments.LineNumber,
                    commandLineArguments.TestAssemblyFilePath);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether [is test context valid] [the specified test context].
        /// </summary>
        /// <param name="testContext">The test context.</param>
        /// <param name="assemblyPath">The assembly path.</param>
        /// <returns>
        ///   <c>true</c> if the test context is valid; otherwise, <c>false</c>.
        /// </returns>
        public bool IsTestContextValid(TestCodeContext testContext, string assemblyPath)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException("assemblyPath");
            }

            if (testContext == null)
            {
                return(false);
            }

            bool isTestContextValid = true;

            try
            {
                Assembly.LoadFrom(Settings.Default.NunitExeFrameworkPath);
                Assembly assembly = Assembly.LoadFrom(assemblyPath);

                if (!string.IsNullOrEmpty(testContext.ClassNameQualified) ||
                    !string.IsNullOrEmpty(testContext.MethodNameQualified))
                {
                    bool isTestClassValid  = true;
                    bool isTestMethodValid = true;

                    if (!string.IsNullOrEmpty(testContext.ClassNameQualified))
                    {
                        isTestClassValid = false;
                    }
                    if (!string.IsNullOrEmpty(testContext.MethodNameQualified))
                    {
                        isTestMethodValid = false;
                    }

                    Type classType = assembly.GetType(testContext.ClassNameQualified, false);
                    if (classType != null)
                    {
                        isTestClassValid = true;

                        if (!string.IsNullOrEmpty(testContext.MethodNameQualified))
                        {
                            MethodInfo methodInfo = classType.GetMethod(testContext.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                            if (methodInfo != null)
                            {
                                isTestMethodValid = true;
                            }
                        }
                    }

                    isTestContextValid = isTestClassValid && isTestMethodValid;
                }
            }
            catch
            {
                isTestContextValid = false;
            }

            return(isTestContextValid);
        }
 /// <summary>
 /// Determines whether [is test context valid] [the specified test context].
 /// </summary>
 /// <param name="testContext">The test context.</param>
 /// <param name="assemblyPath">The assembly path.</param>
 /// <returns>
 ///   <c>true</c> if the test context is valid; otherwise, <c>false</c>.
 /// </returns>
 public bool IsTestContextValid(TestCodeContext testContext, string assemblyPath)
 {
     return(appDomainWorker.IsTestContextValid(testContext, assemblyPath));
 }