public void SearchFallbackShouldBeCalled_IfNoTrxFilesFound() { var mockSearchFallback = new MockSearchFallback(); mockSearchFallback.SetReturnedFiles("file1.txt", "file2.txt"); var testDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(testDir); var testSubject = new BuildVNextCoverageReportProcessor(new MockReportConverter(), new TestLogger(), mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; IEnumerable <string> trxFilePaths = null; bool result = testSubject.TryGetTrxFilesAccessor(new Common.AnalysisConfig(), settings, out trxFilePaths); // Assert result.Should().BeTrue(); // expecting true i.e. carry on even if nothing found testSubject.TrxFilesLocated.Should().BeFalse(); IEnumerable <string> binaryFilePaths = null; result = testSubject.TryGetVsCoverageFilesAccessor(new Common.AnalysisConfig(), settings, out binaryFilePaths); result.Should().BeTrue(); binaryFilePaths.Should().BeEquivalentTo("file1.txt", "file2.txt"); mockSearchFallback.FallbackCalled.Should().BeTrue(); }
public void SearchFallbackNotShouldBeCalled_IfTrxFilesFound() { var mockSearchFallback = new MockSearchFallback(); var testDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())).FullName; var testResultsDir = Path.Combine(testDir, "TestResults"); Directory.CreateDirectory(testResultsDir); TestUtils.CreateTextFile(testResultsDir, "dummy.trx", TRX_PAYLOAD); var testSubject = new BuildVNextCoverageReportProcessor(new MockReportConverter(), new TestLogger(), mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; IEnumerable <string> trxFilePaths = null; bool result = testSubject.TryGetTrxFilesAccessor(new Common.AnalysisConfig(), settings, out trxFilePaths); // 1) Search for TRX files -> results found result.Should().BeTrue(); testSubject.TrxFilesLocated.Should().BeTrue(); // 2) Now search for .coverage files IEnumerable <string> binaryFilePaths = null; result = testSubject.TryGetVsCoverageFilesAccessor(new Common.AnalysisConfig(), settings, out binaryFilePaths); result.Should().BeTrue(); binaryFilePaths.Should().BeEmpty(); mockSearchFallback.FallbackCalled.Should().BeFalse(); }
public void ProcessCoverageReports_VsTestReportsPathsProvided_ShouldSkipSearching() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())).FullName; var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); var converter = new MockReportConverter(); converter.CanConvert = true; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; analysisConfig.LocalSettings.Add(new Property { Id = SonarProperties.VsTestReportsPaths, Value = String.Empty }); testSubject.Initialise(analysisConfig, settings, testDir + "\\sonar-project.properties"); // Act var result = testSubject.ProcessCoverageReports(); // Assert // 1) Property vstestreportPaths provided, we skip the search for trx files. result.Should().BeTrue(); testSubject.TrxFilesLocated.Should().BeFalse(); }
public void ProcessCoverageReports_VsTestReportsPathsProvided_ShouldSkipSearching() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); var converter = new MockReportConverter(); converter.CanConvert = true; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; analysisConfig.LocalSettings.Add(new Property { Id = SonarProperties.VsTestReportsPaths, Value = String.Empty }); testSubject.Initialise(analysisConfig, settings); // Act var result = testSubject.ProcessCoverageReports(); // Assert // 1) Property vstestreportPaths provided, we skip the search for trx files. result.Should().BeTrue(); testSubject.TrxFilesLocated.Should().BeFalse(); }
public void ProcessCoverageReports_VsCoverageXmlPathProvided_CoverageXmlFileAlreadyPresent_NotShouldTryConverting() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); var testResultsDir = Path.Combine(testDir, "TestResults"); var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); Directory.CreateDirectory(testResultsDir); var coverageDir = Path.Combine(testResultsDir, "dummy", "In"); Directory.CreateDirectory(coverageDir); TestUtils.CreateTextFile(testResultsDir, "dummy.trx", TRX_PAYLOAD); TestUtils.CreateTextFile(coverageDir, "dummy.coverage", ""); TestUtils.CreateTextFile(coverageDir, "dummy.coveragexml", ""); var converter = new MockReportConverter(); converter.CanConvert = true; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; analysisConfig.LocalSettings.Add(new Property { Id = SonarProperties.VsCoverageXmlReportsPaths, Value = String.Empty }); testSubject.Initialise(analysisConfig, settings); try { // Act var result = testSubject.ProcessCoverageReports(); // Assert result.Should().BeTrue(); converter.AssertConvertNotCalled(); testLogger.AssertWarningsLogged(0); } finally { TestUtils.DeleteTextFile(coverageDir, "dummy.coveragexml"); } }
public void ProcessCoverageReports_NotVsCoverageXmlPathProvided_CoverageXmlFileAlreadyPresent_NotShouldTryConverting() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var testResultsDir = Path.Combine(testDir, "TestResults"); var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); Directory.CreateDirectory(testResultsDir); var coverageDir = Path.Combine(testResultsDir, "dummy", "In"); Directory.CreateDirectory(coverageDir); TestUtils.CreateTextFile(testResultsDir, "dummy.trx", TRX_PAYLOAD); TestUtils.CreateTextFile(coverageDir, "dummy.coverage", ""); TestUtils.CreateTextFile(coverageDir, "dummy.coveragexml", ""); var converter = new MockReportConverter(); converter.CanConvert = true; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; testSubject.Initialise(analysisConfig, settings, testDir + "\\sonar-project.properties"); // Act try { using (new AssertIgnoreScope()) { var result = testSubject.ProcessCoverageReports(); // Assert result.Should().BeTrue(); } converter.AssertConvertNotCalled(); } finally { TestUtils.DeleteTextFile(coverageDir, "dummy.coveragexml"); } }
/// <summary> /// Factory method to create a coverage report processor for the current build environment. /// TODO: replace with a general purpose pre- and post- processing extension mechanism. /// </summary> private static ICoverageReportProcessor TryCreateCoverageReportProcessor(TeamBuildSettings settings) { ICoverageReportProcessor processor = null; if (settings.BuildEnvironment == BuildEnvironment.TeamBuild) { processor = new BuildVNextCoverageReportProcessor(); } else if (settings.BuildEnvironment == BuildEnvironment.LegacyTeamBuild && !TeamBuildSettings.SkipLegacyCodeCoverageProcessing) { processor = new TfsLegacyCoverageReportProcessor(); } return(processor); }
public void ProcessCoverageReports_VsCoverageXmlPathProvided_NotCoverageXmlFileAlreadyPresent_ShouldTryConverting() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var testResultsDir = Path.Combine(testDir, "TestResults"); var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); Directory.CreateDirectory(testResultsDir); var coverageDir = Path.Combine(testResultsDir, "dummy", "In"); Directory.CreateDirectory(coverageDir); TestUtils.CreateTextFile(testResultsDir, "dummy.trx", TRX_PAYLOAD); TestUtils.CreateTextFile(coverageDir, "dummy.coverage", ""); var converter = new MockReportConverter(); converter.CanConvert = true; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; var coveragePathValue = "ThisIsADummyPath"; analysisConfig.LocalSettings.Add(new Property { Id = SonarProperties.VsCoverageXmlReportsPaths, Value = coveragePathValue }); testSubject.Initialise(analysisConfig, settings, testDir + "\\sonar-project.properties"); // Act var result = testSubject.ProcessCoverageReports(); // Assert result.Should().BeTrue(); converter.AssertExpectedNumberOfConversions(1); Assert.AreEqual(analysisConfig.GetSettingOrDefault(SonarProperties.VsCoverageXmlReportsPaths, true, null), coveragePathValue); }
public void ProcessCoverageReports_NotVsCoverageXmlPathProvided_NotCoverageXmlFileAlreadyPresent_ShouldTryConverting_ConversionFailed() { // Arrange var mockSearchFallback = new MockSearchFallback(); var testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); var testResultsDir = Path.Combine(testDir, "TestResults"); var analysisConfig = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; var testLogger = new TestLogger(); Directory.CreateDirectory(testResultsDir); var coverageDir = Path.Combine(testResultsDir, "dummy", "In"); Directory.CreateDirectory(coverageDir); TestUtils.CreateTextFile(testResultsDir, "dummy.trx", TRX_PAYLOAD); TestUtils.CreateTextFile(coverageDir, "dummy.coverage", ""); var converter = new MockReportConverter(); converter.CanConvert = true; converter.ShouldNotFailConversion = false; var testSubject = new BuildVNextCoverageReportProcessor(converter, testLogger, mockSearchFallback); var settings = new MockBuildSettings { BuildDirectory = testDir }; testSubject.Initialise(analysisConfig, settings); // Act var result = testSubject.ProcessCoverageReports(); // Assert result.Should().BeTrue(); converter.AssertExpectedNumberOfConversions(1); }