public void FileGen_ValidFiles_WithFixableSarif() { // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); // SARIF file path string testSarifPath = Path.Combine(testDir, "testSarif.json"); // Create SARIF report path property and add it to the project info AnalysisProperties projectSettings = new AnalysisProperties { new Property() { Id = PropertiesFileGenerator.ReportFileCsharpPropertyKey, Value = testSarifPath } }; Guid projectGuid = Guid.NewGuid(); CreateProjectWithFiles("withFiles1", testDir, projectGuid, true, projectSettings); TestLogger logger = new TestLogger(); AnalysisConfig config = CreateValidConfig(testDir); // Mock SARIF fixer simulates fixable SARIF with fixed name string returnPathDir = Path.GetDirectoryName(testSarifPath); string returnPathFileName = Path.GetFileNameWithoutExtension(testSarifPath) + RoslynV1SarifFixer.FixedFileSuffix + Path.GetExtension(testSarifPath); MockRoslynV1SarifFixer mockSarifFixer = new MockRoslynV1SarifFixer(returnPathFileName); string escapedMockReturnPath = mockSarifFixer.ReturnVal.Replace(@"\", @"\\"); // Act ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger, mockSarifFixer); // Assert Assert.AreEqual(1, mockSarifFixer.CallCount); Assert.AreEqual(RoslynV1SarifFixer.CSharpLanguage, mockSarifFixer.LastLanguage); // Fixable SARIF -> new file saved -> changed property SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingExists(projectGuid.ToString().ToUpper() + "." + PropertiesFileGenerator.ReportFileCsharpPropertyKey, escapedMockReturnPath); }
public void FileGen_ValidFiles_WithUnfixableSarif() { // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); // SARIF file path string testSarifPath = Path.Combine(testDir, "testSarif.json"); string escapedSarifPath = testSarifPath.Replace(@"\", @"\\"); // Create SARIF report path property and add it to the project info AnalysisProperties projectSettings = new AnalysisProperties { new Property() { Id = PropertiesFileGenerator.ReportFileCsharpPropertyKey, Value = testSarifPath } }; Guid projectGuid = Guid.NewGuid(); CreateProjectWithFiles("withFiles1", testDir, projectGuid, true, projectSettings); TestLogger logger = new TestLogger(); AnalysisConfig config = CreateValidConfig(testDir); // Mock SARIF fixer simulated unfixable/absent file MockRoslynV1SarifFixer mockSarifFixer = new MockRoslynV1SarifFixer(null); // Act ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger, mockSarifFixer); // Assert Assert.AreEqual(1, mockSarifFixer.CallCount); // One valid project info file -> file created AssertPropertiesFilesCreated(result, logger); // Unfixable SARIF -> cannot fix -> report file property removed SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingDoesNotExist(projectGuid.ToString().ToUpper() + "." + PropertiesFileGenerator.ReportFileCsharpPropertyKey); }
public void FileGen_ValidFiles_WithAlreadyValidSarif() { // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); // SARIF file path string testSarifPath = Path.Combine(testDir, "testSarif.json"); // Create SARIF report path property and add it to the project info AnalysisProperties projectSettings = new AnalysisProperties { new Property() { Id = PropertiesFileGenerator.ReportFileCsharpPropertyKey, Value = testSarifPath } }; Guid projectGuid = Guid.NewGuid(); CreateProjectWithFiles("withFiles1", testDir, projectGuid, true, projectSettings); TestLogger logger = new TestLogger(); AnalysisConfig config = CreateValidConfig(testDir); // Mock SARIF fixer simulates already valid sarif MockRoslynV1SarifFixer mockSarifFixer = new MockRoslynV1SarifFixer(testSarifPath); string mockReturnPath = mockSarifFixer.ReturnVal; // Act ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger, mockSarifFixer); // Assert Assert.AreEqual(1, mockSarifFixer.CallCount); // Already valid SARIF -> no change in file -> unchanged property SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingExists(projectGuid.ToString().ToUpper() + "." + PropertiesFileGenerator.ReportFileCsharpPropertyKey, mockReturnPath); }