private void VerifyProjectBaseDir(string expectedValue, string teamBuildValue, string userValue, string[] projectPaths) { AnalysisConfig config = new AnalysisConfig(); PropertiesWriter writer = new PropertiesWriter(config); config.SonarOutputDir = TestSonarqubeOutputDir; config.SourcesDirectory = teamBuildValue; config.SetConfigValue(SonarProperties.ProjectBaseDir, userValue); using (new AssertIgnoreScope()) { foreach (string projectPath in projectPaths) { var projectInfo = new ProjectInfo { FullPath = projectPath, ProjectLanguage = ProjectLanguages.CSharp }; writer.WriteSettingsForProject(projectInfo, Enumerable.Empty <string>(), "", ""); } var actual = writer.Flush(); var expected = "\r\nsonar.projectBaseDir=" + PropertiesWriter.Escape(expectedValue); Assert.IsTrue(actual.Contains(expected)); } }
public void PropertiesWriterEscape() { PropertiesWriter.Escape("foo").Should().Be("foo"); PropertiesWriter.Escape(@"C:\File.cs").Should().Be(@"C:\\File.cs"); PropertiesWriter.Escape("你好").Should().Be(@"\u4F60\u597D"); PropertiesWriter.Escape("\n").Should().Be(@"\u000A"); }
public void PropertiesWriterEscape() { Assert.AreEqual("foo", PropertiesWriter.Escape("foo")); Assert.AreEqual(@"C:\\File.cs", PropertiesWriter.Escape(@"C:\File.cs")); Assert.AreEqual(@"\u4F60\u597D", PropertiesWriter.Escape("你好")); Assert.AreEqual(@"\u000A", PropertiesWriter.Escape("\n")); }
public void PropertiesWriter_FxCopRerportForUnrecognisedLanguage() { var productBaseDir = TestUtils.CreateTestSpecificFolder(TestContext); string productProject = CreateEmptyFile(productBaseDir, "MyProduct.proj"); string productFile = CreateEmptyFile(productBaseDir, "File.txt"); string productFxCopFilePath = CreateEmptyFile(productBaseDir, "productFxCopReport.txt"); string productFileListFilePath = Path.Combine(productBaseDir, "productFileList.txt"); List <string> productFiles = new List <string>(); productFiles.Add(productFile); ProjectInfo product = CreateProjectInfo("myproduct", "9507E2E6-7342-4A04-9CB9-B0C47C937019", productProject, false, productFiles, productFileListFilePath, productFxCopFilePath, null, "my.language"); AnalysisConfig config = new AnalysisConfig() { SonarProjectKey = "my_project_key", SonarProjectName = "my_project_name", SonarProjectVersion = "1.0", SonarOutputDir = @"C:\my_folder", SourcesDirectory = @"D:\sources" }; string actual = null; using (new AssertIgnoreScope()) // expecting the property writer to complain about having an FxCop report for an unknown language { PropertiesWriter writer = new PropertiesWriter(config); writer.WriteSettingsForProject(product, new string[] { productFile, }, productFxCopFilePath, null); actual = writer.Flush(); } string expected = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"9507E2E6-7342-4A04-9CB9-B0C47C937019.sonar.projectKey=my_project_key:9507E2E6-7342-4A04-9CB9-B0C47C937019 9507E2E6-7342-4A04-9CB9-B0C47C937019.sonar.projectName=myproduct 9507E2E6-7342-4A04-9CB9-B0C47C937019.sonar.projectBaseDir={0} 9507E2E6-7342-4A04-9CB9-B0C47C937019.sonar.sources=\ {0}\\File.txt sonar.projectKey=my_project_key sonar.projectName=my_project_name sonar.projectVersion=1.0 sonar.working.directory=C:\\my_folder\\.sonar sonar.projectBaseDir={1} # FIXME: Encoding is hardcoded sonar.sourceEncoding=UTF-8 sonar.modules=9507E2E6-7342-4A04-9CB9-B0C47C937019 ", PropertiesWriter.Escape(productBaseDir), PropertiesWriter.Escape(config.SourcesDirectory)); SaveToResultFile(productBaseDir, "Expected.txt", expected.ToString()); SaveToResultFile(productBaseDir, "Actual.txt", actual); Assert.AreEqual(expected, actual); }
private static void AssertFileIsReferenced(string fullFilePath, string content, int times = 1) { var formattedPath = PropertiesWriter.Escape(fullFilePath); var index = content.IndexOf(formattedPath); if (times == 0) { index.Should().Be(-1, $"File should not be referenced: {formattedPath}"); } else { index.Should().NotBe(-1, $"File should be referenced: {formattedPath}"); for (var i = 0; i < times - 1; i++) { index = content.IndexOf(formattedPath, index + 1); index.Should().NotBe(-1, $"File should be referenced exactly {times} times: {formattedPath}"); } index = content.IndexOf(formattedPath, index + 1); index.Should().Be(-1, $"File should be referenced exactly {times} times: {formattedPath}"); } }
private void AssertHasProjectBaseDir(string expectedProjectDir, string fallback, params string[] projectPaths) { var config = new AnalysisConfig(); config.SonarOutputDir = fallback; var writer = new PropertiesWriter(config); using (new AssertIgnoreScope()) { foreach (string projectPath in projectPaths) { var projectInfo = new ProjectInfo { FullPath = projectPath, ProjectLanguage = ProjectLanguages.VisualBasic }; writer.WriteSettingsForProject(projectInfo, Enumerable.Empty <string>(), "", ""); } var actual = writer.Flush(); var expected = "\r\nsonar.projectBaseDir=" + PropertiesWriter.Escape(expectedProjectDir); Console.WriteLine(actual); Assert.IsTrue(actual.Contains(expected)); } }
public void PropertiesWriterToString() { var productBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_ProductBaseDir"); var productProject = CreateEmptyFile(productBaseDir, "MyProduct.csproj"); var productFile = CreateEmptyFile(productBaseDir, "File.cs"); var productChineseFile = CreateEmptyFile(productBaseDir, "你好.cs"); var productCoverageFilePath = CreateEmptyFile(productBaseDir, "productCoverageReport.txt").FullName; CreateEmptyFile(productBaseDir, "productTrx.trx"); var productFileListFilePath = Path.Combine(productBaseDir, "productManagedFiles.txt"); var otherDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_OtherDir"); var missingFileOutsideProjectDir = new FileInfo(Path.Combine(otherDir, "missing.cs")); var productFiles = new List <FileInfo> { productFile, productChineseFile, missingFileOutsideProjectDir }; var productCS = new ProjectData(CreateProjectInfo("你好", "DB2E5521-3172-47B9-BA50-864F12E6DFFF", productProject, false, productFiles, productFileListFilePath, productCoverageFilePath, ProjectLanguages.CSharp, "UTF-8")); productCS.SonarQubeModuleFiles.Add(productFile); productCS.SonarQubeModuleFiles.Add(productChineseFile); productCS.SonarQubeModuleFiles.Add(missingFileOutsideProjectDir); var productVB = new ProjectData(CreateProjectInfo("vbProject", "B51622CF-82F4-48C9-9F38-FB981FAFAF3A", productProject, false, productFiles, productFileListFilePath, productCoverageFilePath, ProjectLanguages.VisualBasic, "UTF-8")); productVB.SonarQubeModuleFiles.Add(productFile); var testBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_TestBaseDir"); var testProject = CreateEmptyFile(testBaseDir, "MyTest.csproj"); var testFile = CreateEmptyFile(testBaseDir, "File.cs"); var testFileListFilePath = Path.Combine(testBaseDir, "testManagedFiles.txt"); var testFiles = new List <FileInfo> { testFile }; var test = new ProjectData(CreateProjectInfo("my_test_project", "DA0FCD82-9C5C-4666-9370-C7388281D49B", testProject, true, testFiles, testFileListFilePath, null, ProjectLanguages.VisualBasic, "UTF-8")); test.SonarQubeModuleFiles.Add(testFile); var config = new AnalysisConfig() { SonarProjectKey = "my_project_key", SonarProjectName = "my_project_name", SonarProjectVersion = "1.0", SonarOutputDir = @"C:\my_folder", SourcesDirectory = @"d:\source_files\" }; string actual = null; using (new AssertIgnoreScope()) // expecting the property writer to complain about the missing file { var writer = new PropertiesWriter(config, new TestLogger()); writer.WriteSettingsForProject(productCS); writer.WriteSettingsForProject(productVB); writer.WriteSettingsForProject(test); actual = writer.Flush(); } var expected = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.projectKey=my_project_key:DB2E5521-3172-47B9-BA50-864F12E6DFFF DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.projectName=\u4F60\u597D DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.projectBaseDir={0} DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.sourceEncoding=utf-8 DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.sources=\ {0}\\File.cs,\ {0}\\\u4F60\u597D.cs,\ {2} DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.working.directory=C:\\my_folder\\.sonar\\mod0 B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.projectKey=my_project_key:B51622CF-82F4-48C9-9F38-FB981FAFAF3A B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.projectName=vbProject B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.projectBaseDir={0} B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.sourceEncoding=utf-8 B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.sources=\ {0}\\File.cs B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.working.directory=C:\\my_folder\\.sonar\\mod1 DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.projectKey=my_project_key:DA0FCD82-9C5C-4666-9370-C7388281D49B DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.projectName=my_test_project DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.projectBaseDir={1} DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.sourceEncoding=utf-8 DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.sources= DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.tests=\ {1}\\File.cs DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.working.directory=C:\\my_folder\\.sonar\\mod2 sonar.modules=DB2E5521-3172-47B9-BA50-864F12E6DFFF,B51622CF-82F4-48C9-9F38-FB981FAFAF3A,DA0FCD82-9C5C-4666-9370-C7388281D49B ", PropertiesWriter.Escape(productBaseDir), PropertiesWriter.Escape(testBaseDir), PropertiesWriter.Escape(missingFileOutsideProjectDir)); SaveToResultFile(productBaseDir, "Expected.txt", expected.ToString()); SaveToResultFile(productBaseDir, "Actual.txt", actual); actual.Should().Be(expected); }
private static void AssertFileIsNotReferenced(string fullFilePath, string content) { string formattedPath = PropertiesWriter.Escape(fullFilePath); Assert.IsFalse(content.Contains(formattedPath), "File should not be referenced: {0}", formattedPath); }
public void PropertiesWriterToString() { var productBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_ProductBaseDir"); string productProject = CreateEmptyFile(productBaseDir, "MyProduct.csproj"); string productFile = CreateEmptyFile(productBaseDir, "File.cs"); string productChineseFile = CreateEmptyFile(productBaseDir, "你好.cs"); string productFxCopFilePath = CreateEmptyFile(productBaseDir, "productFxCopReport.txt"); string productCoverageFilePath = CreateEmptyFile(productBaseDir, "productCoverageReport.txt"); string productFileListFilePath = Path.Combine(productBaseDir, "productManagedFiles.txt"); string otherDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_OtherDir"); string missingFileOutsideProjectDir = Path.Combine(otherDir, "missing.cs"); List <string> productFiles = new List <string>(); productFiles.Add(productFile); productFiles.Add(productChineseFile); productFiles.Add(missingFileOutsideProjectDir); ProjectInfo productCS = CreateProjectInfo("你好", "DB2E5521-3172-47B9-BA50-864F12E6DFFF", productProject, false, productFiles, productFileListFilePath, productFxCopFilePath, productCoverageFilePath, ProjectLanguages.CSharp); ProjectInfo productVB = CreateProjectInfo("vbProject", "B51622CF-82F4-48C9-9F38-FB981FAFAF3A", productProject, false, productFiles, productFileListFilePath, productFxCopFilePath, productCoverageFilePath, ProjectLanguages.VisualBasic); string testBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_TestBaseDir"); string testProject = CreateEmptyFile(testBaseDir, "MyTest.csproj"); string testFile = CreateEmptyFile(testBaseDir, "File.cs"); string testFileListFilePath = Path.Combine(testBaseDir, "testManagedFiles.txt"); List <string> testFiles = new List <string>(); testFiles.Add(testFile); ProjectInfo test = CreateProjectInfo("my_test_project", "DA0FCD82-9C5C-4666-9370-C7388281D49B", testProject, true, testFiles, testFileListFilePath, null, null, ProjectLanguages.VisualBasic); AnalysisConfig config = new AnalysisConfig() { SonarProjectKey = "my_project_key", SonarProjectName = "my_project_name", SonarProjectVersion = "1.0", SonarOutputDir = @"C:\my_folder", SourcesDirectory = @"d:\source_files\" }; string actual = null; using (new AssertIgnoreScope()) // expecting the property writer to complain about the missing file { PropertiesWriter writer = new PropertiesWriter(config); writer.WriteSettingsForProject(productCS, new string[] { productFile, productChineseFile, missingFileOutsideProjectDir }, productFxCopFilePath, productCoverageFilePath); writer.WriteSettingsForProject(productVB, new string[] { productFile }, productFxCopFilePath, null); writer.WriteSettingsForProject(test, new string[] { testFile }, null, null); actual = writer.Flush(); } string expected = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.projectKey=my_project_key:DB2E5521-3172-47B9-BA50-864F12E6DFFF DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.projectName=\u4F60\u597D DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.projectBaseDir={0} DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.cs.fxcop.reportPath={1} DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.cs.vscoveragexml.reportsPaths={2} DB2E5521-3172-47B9-BA50-864F12E6DFFF.sonar.sources=\ {0}\\File.cs,\ {0}\\\u4F60\u597D.cs,\ {4} B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.projectKey=my_project_key:B51622CF-82F4-48C9-9F38-FB981FAFAF3A B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.projectName=vbProject B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.projectBaseDir={0} B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.vbnet.fxcop.reportPath={1} B51622CF-82F4-48C9-9F38-FB981FAFAF3A.sonar.sources=\ {0}\\File.cs DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.projectKey=my_project_key:DA0FCD82-9C5C-4666-9370-C7388281D49B DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.projectName=my_test_project DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.projectBaseDir={3} DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.sources= DA0FCD82-9C5C-4666-9370-C7388281D49B.sonar.tests=\ {3}\\File.cs sonar.modules=DB2E5521-3172-47B9-BA50-864F12E6DFFF,B51622CF-82F4-48C9-9F38-FB981FAFAF3A,DA0FCD82-9C5C-4666-9370-C7388281D49B ", PropertiesWriter.Escape(productBaseDir), PropertiesWriter.Escape(productFxCopFilePath), PropertiesWriter.Escape(productCoverageFilePath), PropertiesWriter.Escape(testBaseDir), PropertiesWriter.Escape(missingFileOutsideProjectDir), PropertiesWriter.Escape(config.SourcesDirectory)); SaveToResultFile(productBaseDir, "Expected.txt", expected.ToString()); SaveToResultFile(productBaseDir, "Actual.txt", actual); Assert.AreEqual(expected, actual); }
private static void AssertFileIsReferenced(string fullFilePath, string content) { var formattedPath = PropertiesWriter.Escape(fullFilePath); Assert.IsTrue(content.Contains(formattedPath), "Files should be referenced: {0}", formattedPath); }