Ejemplo n.º 1
0
        /// <summary>
        /// Log the parameter warnings on the parameter logger
        /// </summary>
        /// <param name="testExecutionRecorder">Handle to record test start/end/results/messages.</param>
        /// <param name="result">Result of the run operation.</param>
        private void LogCleanupResult(ITestExecutionRecorder testExecutionRecorder, RunCleanupResult result)
        {
            Debug.Assert(testExecutionRecorder != null, "Logger should not be null");

            if (!string.IsNullOrEmpty(result.StandardOut))
            {
                testExecutionRecorder.SendMessage(TestMessageLevel.Informational, result.StandardOut);
            }

            if (!string.IsNullOrEmpty(result.DebugTrace))
            {
                testExecutionRecorder.SendMessage(TestMessageLevel.Informational, result.DebugTrace);
            }

            if (!string.IsNullOrEmpty(result.StandardError))
            {
                testExecutionRecorder.SendMessage(
                    MSTestSettings.CurrentSettings.TreatClassAndAssemblyCleanupWarningsAsErrors ? TestMessageLevel.Error : TestMessageLevel.Warning,
                    result.StandardError);
            }

            if (result.Warnings != null)
            {
                foreach (string warning in result.Warnings)
                {
                    testExecutionRecorder.SendMessage(
                        MSTestSettings.CurrentSettings.TreatClassAndAssemblyCleanupWarningsAsErrors ? TestMessageLevel.Error : TestMessageLevel.Warning,
                        warning);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the class cleanup method.
        /// It returns any error information during the execution of the cleanup method
        /// </summary>
        /// <returns> The <see cref="RunCleanupResult"/>. </returns>
        internal RunCleanupResult RunCleanup()
        {
            // No cleanup methods to execute, then return.
            var assemblyInfoCache = this.typeCache.AssemblyInfoListWithExecutableCleanupMethods;
            var classInfoCache    = this.typeCache.ClassInfoListWithExecutableCleanupMethods;

            if (!assemblyInfoCache.Any() && !classInfoCache.Any())
            {
                return(null);
            }

            var result = new RunCleanupResult {
                Warnings = new List <string>()
            };

            using (var redirector = new LogMessageListener(MSTestSettings.CurrentSettings.CaptureDebugTraces))
            {
                try
                {
                    this.RunClassCleanupMethods(classInfoCache, result.Warnings);
                    this.RunAssemblyCleanup(assemblyInfoCache, result.Warnings);
                }
                finally
                {
                    // Replacing the null character with a string.replace should work.
                    // If this does not work for a specific dotnet version a custom function doing the same needs to be put in place.
                    result.StandardOut   = redirector.GetAndClearStandardOutput()?.Replace("\0", "\\0");
                    result.StandardError = redirector.GetAndClearStandardError()?.Replace("\0", "\\0");
                    result.DebugTrace    = redirector.GetAndClearDebugTrace()?.Replace("\0", "\\0");
                }
            }

            return(result);
        }