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); }
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_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); }
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); }
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); }