public void ReportProcessor_NoUrlsFound()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider() { UrlsToReturn = new string[] { } };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter converter = new MockReportConverter() { CanConvert = true };
            AnalysisConfig context = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger logger = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool initResult = processor.Initialise(context, settings, logger);
            Assert.IsTrue(initResult, "Expecting true: processor should have been initialised successfully");
            bool result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // no urls returned, so should go any further
            converter.AssertConvertNotCalled();
            Assert.IsTrue(result, "Expecting true: no coverage reports is a valid scenario");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
Esempio n. 2
0
        public void ReportProcessor_MultipleUrlsFound()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1, ValidUrl2 }
            };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter  converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            AnalysisConfig    context  = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger        logger   = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool result = processor.ProcessCoverageReports(context, settings, logger);

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // Multiple urls so should early out
            converter.AssertConvertNotCalled();
            Assert.IsFalse(result, "Expecting false: can't process multiple coverage reports");

            logger.AssertErrorsLogged(1);
            logger.AssertWarningsLogged(0);
        }
Esempio n. 3
0
        public void ReportProcessor_CannotConvertFiles()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1 }
            };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter  converter  = new MockReportConverter()
            {
                CanConvert = false
            };
            AnalysisConfig    context  = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger        logger   = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool result = processor.ProcessCoverageReports(context, settings, logger);

            // Assert
            urlProvider.AssertGetUrlsNotCalled();
            downloader.AssertDownloadNotCalled();
            converter.AssertConvertNotCalled();
            Assert.IsFalse(result, "Expecting result to be false as files could not be converted");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
Esempio n. 4
0
        public void ReportProcessor_SingleUrlFound_DownloadedOk()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl2 }
            };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter  converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            AnalysisConfig    context  = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger        logger   = new TestLogger();

            downloader.CreateFileOnDownloadRequest = true;

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool result = processor.ProcessCoverageReports(context, settings, logger);

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(1);
            converter.AssertExpectedNumberOfConversions(1);

            downloader.AssertExpectedUrlsRequested(ValidUrl2);
            downloader.AssertExpectedTargetFileNamesSupplied(Path.Combine(context.SonarOutputDir, TfsLegacyCoverageReportProcessor.DownloadFileName));
            Assert.IsTrue(result, "Expecting true: happy path");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
Esempio n. 5
0
        public void ReportProcessor_NoUrlsFound()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { }
            };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter  converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            AnalysisConfig    context  = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger        logger   = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool result = processor.ProcessCoverageReports(context, settings, logger);

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // no urls returned, so should go any further
            converter.AssertConvertNotCalled();
            Assert.IsTrue(result, "Expecting true: no coverage reports is a valid scenario");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
        public void ReportProcessor_CannotConvertFiles()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider() { UrlsToReturn = new string[] { ValidUrl1 } };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter converter = new MockReportConverter() { CanConvert = false };
            AnalysisConfig context = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger logger = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool initResult = processor.Initialise(context, settings, logger);

            // Assert
            Assert.IsFalse(initResult, "Expecting false: processor should not have been initialised successfully");

            urlProvider.AssertGetUrlsNotCalled();
            downloader.AssertDownloadNotCalled();
            converter.AssertConvertNotCalled();

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
        public void ReportProcessor_NoUrlsFound()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();
            var testDir  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter, logger);

            // Act
            var initResult = processor.Initialise(context, settings, testDir + "\\sonar-project.properties");

            initResult.Should().BeTrue("Expecting true: processor should have been initialized successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // no urls returned, so should go any further
            converter.AssertConvertNotCalled();
            result.Should().BeTrue("Expecting true: no coverage reports is a valid scenario");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
        public void ReportProcessor_MultipleUrlsFound()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1, ValidUrl2 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            var initResult = processor.Initialise(context, settings, logger);

            Assert.IsTrue(initResult, "Expecting true: processor should have been initialised successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // Multiple urls so should early out
            converter.AssertConvertNotCalled();
            Assert.IsFalse(result, "Expecting false: can't process multiple coverage reports");

            logger.AssertErrorsLogged(1);
            logger.AssertWarningsLogged(0);
        }
        public void ReportProcessor_CannotConvertFiles()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = false
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            var initResult = processor.Initialise(context, settings, logger);

            // Assert
            Assert.IsFalse(initResult, "Expecting false: processor should not have been initialised successfully");

            urlProvider.AssertGetUrlsNotCalled();
            downloader.AssertDownloadNotCalled();
            converter.AssertConvertNotCalled();

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
Esempio n. 10
0
        public void ReportProcessor_SingleUrlFound_NotDownloaded()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1 }
            };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter  converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            AnalysisConfig    context  = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger        logger   = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool result = processor.ProcessCoverageReports(context, settings, logger);

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(1);
            converter.AssertConvertNotCalled();

            downloader.AssertExpectedUrlsRequested(ValidUrl1);

            Assert.IsFalse(result, "Expecting false: report could not be downloaded");
            logger.AssertErrorsLogged(1);
            logger.AssertWarningsLogged(0);
        }
        public void ReportProcessor_NoUrlsFound()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            var initResult = processor.Initialise(context, settings, logger);

            Assert.IsTrue(initResult, "Expecting true: processor should have been initialised successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // no urls returned, so should go any further
            converter.AssertConvertNotCalled();
            Assert.IsTrue(result, "Expecting true: no coverage reports is a valid scenario");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
Esempio n. 12
0
        /// <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 ReportProcessor_SingleUrlFound_DownloadedOk()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl2 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();
            var testDir  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(testDir);

            TestUtils.CreateTextFile(testDir, "sonar-project.properties", String.Empty);

            downloader.CreateFileOnDownloadRequest = true;

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter, logger);

            // Act
            var initResult = processor.Initialise(context, settings, testDir + "\\sonar-project.properties");

            initResult.Should().BeTrue("Expecting true: processor should have been initialized successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(1);
            converter.AssertExpectedNumberOfConversions(1);

            downloader.AssertExpectedUrlsRequested(ValidUrl2);
            downloader.AssertExpectedTargetFileNamesSupplied(Path.Combine(context.SonarOutputDir, TfsLegacyCoverageReportProcessor.DownloadFileName));
            result.Should().BeTrue("Expecting true: happy path");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);

            var linesWritten = File.ReadAllLines(testDir + "\\sonar-project.properties");

            linesWritten[0].Should().Contain(SonarProperties.VsCoverageXmlReportsPaths);
        }
        public void ReportProcessor_MultipleUrlsFound()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1, ValidUrl2 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();
            var testDir  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(testDir);

            TestUtils.CreateTextFile(testDir, "sonar-project.properties", String.Empty);

            downloader.CreateFileOnDownloadRequest = true;

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter, logger);

            // Act
            var initResult = processor.Initialise(context, settings, testDir + "\\sonar-project.properties");

            initResult.Should().BeTrue("Expecting true: processor should have been initialized successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(2);
            converter.AssertExpectedNumberOfConversions(2);
            downloader.AssertExpectedUrlsRequested(ValidUrl1, ValidUrl2);
            result.Should().BeTrue();

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
Esempio n. 15
0
        public void ReportProcessor_SingleUrlFound_DownloadedOk()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl2 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();

            downloader.CreateFileOnDownloadRequest = true;

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter, logger);

            // Act
            var initResult = processor.Initialise(context, settings);

            initResult.Should().BeTrue("Expecting true: processor should have been initialized successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(1);
            converter.AssertExpectedNumberOfConversions(1);

            downloader.AssertExpectedUrlsRequested(ValidUrl2);
            downloader.AssertExpectedTargetFileNamesSupplied(Path.Combine(context.SonarOutputDir, TfsLegacyCoverageReportProcessor.DownloadFileName));
            result.Should().BeTrue("Expecting true: happy path");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);

            context.LocalSettings.Should().Contain(x => x.Id == SonarProperties.VsCoverageXmlReportsPaths);
        }
        public void ReportProcessor_SingleUrlFound_NotDownloaded()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            var initResult = processor.Initialise(context, settings, logger);

            Assert.IsTrue(initResult, "Expecting true: processor should have been initialised successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(1);
            converter.AssertConvertNotCalled();

            downloader.AssertExpectedUrlsRequested(ValidUrl1);

            Assert.IsFalse(result, "Expecting false: report could not be downloaded");

            logger.AssertErrorsLogged(1);
            logger.AssertWarningsLogged(0);
        }
Esempio n. 17
0
        public void ReportProcessor_MultipleUrlsFound()
        {
            // Arrange
            var urlProvider = new MockReportUrlProvider()
            {
                UrlsToReturn = new string[] { ValidUrl1, ValidUrl2 }
            };
            var downloader = new MockReportDownloader();
            var converter  = new MockReportConverter()
            {
                CanConvert = true
            };
            var context  = CreateValidContext();
            var settings = CreateValidSettings();
            var logger   = new TestLogger();

            downloader.CreateFileOnDownloadRequest = true;

            var processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter, logger);

            // Act
            var initResult = processor.Initialise(context, settings);

            initResult.Should().BeTrue("Expecting true: processor should have been initialized successfully");
            var result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(2);
            converter.AssertExpectedNumberOfConversions(2);
            downloader.AssertExpectedUrlsRequested(ValidUrl1, ValidUrl2);
            result.Should().BeTrue();

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
        public void ReportProcessor_SingleUrlFound_DownloadedOk()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider() { UrlsToReturn = new string[] { ValidUrl2 } };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter converter = new MockReportConverter() { CanConvert = true };
            AnalysisConfig context = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger logger = new TestLogger();

            downloader.CreateFileOnDownloadRequest = true;

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool initResult = processor.Initialise(context, settings, logger);
            Assert.IsTrue(initResult, "Expecting true: processor should have been initialised successfully");
            bool result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertExpectedDownloads(1);
            converter.AssertExpectedNumberOfConversions(1);

            downloader.AssertExpectedUrlsRequested(ValidUrl2);
            downloader.AssertExpectedTargetFileNamesSupplied(Path.Combine(context.SonarOutputDir, TfsLegacyCoverageReportProcessor.DownloadFileName));
            Assert.IsTrue(result, "Expecting true: happy path");

            logger.AssertWarningsLogged(0);
            logger.AssertErrorsLogged(0);
        }
        public void ReportProcessor_MultipleUrlsFound()
        {
            // Arrange
            MockReportUrlProvider urlProvider = new MockReportUrlProvider() { UrlsToReturn = new string[] { ValidUrl1, ValidUrl2 } };
            MockReportDownloader downloader = new MockReportDownloader();
            MockReportConverter converter = new MockReportConverter() { CanConvert = true };
            AnalysisConfig context = this.CreateValidContext();
            TeamBuildSettings settings = this.CreateValidSettings();
            TestLogger logger = new TestLogger();

            TfsLegacyCoverageReportProcessor processor = new TfsLegacyCoverageReportProcessor(urlProvider, downloader, converter);

            // Act
            bool initResult = processor.Initialise(context, settings, logger);
            Assert.IsTrue(initResult, "Expecting true: processor should have been initialised successfully");
            bool result = processor.ProcessCoverageReports();

            // Assert
            urlProvider.AssertGetUrlsCalled();
            downloader.AssertDownloadNotCalled(); // Multiple urls so should early out
            converter.AssertConvertNotCalled();
            Assert.IsFalse(result, "Expecting false: can't process multiple coverage reports");

            logger.AssertErrorsLogged(1);
            logger.AssertWarningsLogged(0);
        }