예제 #1
0
        /// <summary>
        /// Attempts to return the file location for the specified type of analysis result.
        /// Returns null if there is not a result for the specified type.
        /// Note that callers must check if the file exists before attempting to read.
        /// </summary>
        public static string TryGetAnalysisFileLocation(this ProjectInfo projectInfo, AnalysisType analysisType)
        {
            if (projectInfo.TryGetAnalyzerResult(analysisType, out AnalysisResult result))
            {
                return(result.Location);
            }

            return(null);
        }
        /// <summary>
        /// Attempts to return the file location for the specified type of analysis result.
        /// Returns null if there is not a result for the specified type, or if the
        /// file does not exist.
        /// </summary>
        public static string TryGetAnalysisFileLocation(this ProjectInfo projectInfo, AnalysisType analysisType)
        {
            string location = null;

            AnalysisResult result = null;

            if (projectInfo.TryGetAnalyzerResult(analysisType, out result))
            {
                if (File.Exists(result.Location))
                {
                    location = result.Location;
                }
            }
            return(location);
        }
        private void AssertResultFileExists(ProjectInfo projectInfo, AnalysisType resultType, params string[] expected)
        {
            AnalysisResult result;
            bool found = projectInfo.TryGetAnalyzerResult(resultType, out result);

            Assert.IsTrue(found, "Analysis result not found: {0}", resultType);
            Assert.IsTrue(File.Exists(result.Location), "Analysis result file not found");

            this.TestContext.AddResultFile(result.Location);

            string[] actualFiles = File.ReadAllLines(result.Location);

            try
            {
                CollectionAssert.AreEquivalent(expected, actualFiles, "The analysis result file does not contain the expected entries");
            }
            catch (AssertFailedException)
            {
                this.TestContext.WriteLine("Expected files: {1}{0}", Environment.NewLine, string.Join("\t" + Environment.NewLine, expected));
                this.TestContext.WriteLine("Actual files: {1}{0}", Environment.NewLine, string.Join("\t" + Environment.NewLine, actualFiles));
                throw;
            }
        }
        private void AssertResultFileDoesNotExist(ProjectInfo projectInfo, AnalysisType resultType)
        {
            AnalysisResult result;
            bool found = projectInfo.TryGetAnalyzerResult(resultType, out result);

            if (found)
            {
                this.TestContext.AddResultFile(result.Location);
            }

            Assert.IsFalse(found, "Analysis result found unexpectedly. Result type: {0}", resultType);
        }