public void SarifFixer_ShouldNotChange_SpansMultipleLines() { // Arrange string testSarif = @"{ ""version"": ""0.1"", ""toolInfo"": { ""toolName"": ""Microsoft (R) Visual C# Compiler"", ""productVersion"": ""1.0.0"", ""fileVersion"": ""1.0.0"" }, ""issues"": [ { ""ruleId"": ""DD001"", ""shortMessage"": ""Test shortMessage. It features ""quoted text""."", ""properties"": { ""severity"": ""Info"", ""helpLink"": ""https://github.com/SonarSource/sonar-msbuild-runner"", } } ] }"; // Act string fixedSarif; bool returnStringIsValid = RoslynV1SarifFixer.FixRoslynV1Sarif(testSarif, out fixedSarif); // Assert Assert.IsFalse(returnStringIsValid); Assert.AreEqual(testSarif, fixedSarif); }
public void SarifFixer_ShouldChange_EscapeBackslashes() { // Arrange string testSarif = @"{ ""version"": ""0.1"", ""toolInfo"": { ""toolName"": ""Microsoft (R) Visual C# Compiler"", ""productVersion"": ""1.0.0"", ""fileVersion"": ""1.0.0"" }, ""issues"": [ { ""ruleId"": ""DD001"", ""locations"": [ { ""analysisTarget"": [ { ""uri"": ""C:\agent\_work\2\s\MyTestProj\Program.cs"", } ] } ], } ] }"; // Act string fixedSarif; bool returnStringIsValid = RoslynV1SarifFixer.FixRoslynV1Sarif(testSarif, out fixedSarif); // Assert Assert.IsTrue(returnStringIsValid); Assert.AreEqual(@"{ ""version"": ""0.1"", ""toolInfo"": { ""toolName"": ""Microsoft (R) Visual C# Compiler"", ""productVersion"": ""1.0.0"", ""fileVersion"": ""1.0.0"" }, ""issues"": [ { ""ruleId"": ""DD001"", ""locations"": [ { ""analysisTarget"": [ { ""uri"": ""C:\\agent\\_work\\2\\s\\MyTestProj\\Program.cs"", } ] } ], } ] }", fixedSarif); }
public void SarifFixer_ShouldNotChange_Unfixable() { // Arrange string testSarif = @"{ ""version"": ""0.1"", ""toolInfo"": { ""toolName"": ""Microsoft (R) Visual C# Compiler"", ""productVersion"": ""1.0.0"", ""fileVersion"": ""1.0.0"" }, ""issues"": [ { }}}}}}}}}}}}}}}}}}}}}}}}} ""ruleId"": ""DD001"", ""locations"": [ { ""analysisTarget"": [ { ""uri"": ""C:\\agent\\_work\\2\\s\\MyTestProj\\Program.cs"", } ] } ], ""shortMessage"": ""Test shortMessage. It features \""quoted text\""."", ""properties"": { ""severity"": ""Info"", ""helpLink"": ""https://github.com/SonarSource/sonar-msbuild-runner"", } } ] }"; // Act string fixedSarif; bool returnStringIsValid = RoslynV1SarifFixer.FixRoslynV1Sarif(testSarif, out fixedSarif); // Assert Assert.IsFalse(returnStringIsValid); Assert.AreEqual(testSarif, fixedSarif); }
public void SarifFixer_ShouldChange_EscapeCharsInAllAffectedFields() { // Arrange string testSarif = @"{ ""version"": ""0.1"", ""toolInfo"": { ""toolName"": ""Microsoft (R) Visual C# Compiler"", ""productVersion"": ""1.0.0"", ""fileVersion"": ""1.0.0"" }, ""issues"": [ { ""ruleId"": ""DD001"", ""locations"": [ { ""analysisTarget"": [ { ""uri"": ""C:\agent\_work\2\s\MyTestProj\Program.cs"", } ] } ], ""shortMessage"": ""Test shortMessage. It features ""quoted text"" and has \slashes."", ""fullMessage"": ""Test fullMessage. It features ""quoted text"" and has \slashes."", ""properties"": { ""severity"": ""Info"", ""title"": ""Test title. It features ""quoted text"" and has \slashes."", ""helpLink"": ""https://github.com/SonarSource/sonar-msbuild-runner"", } } ] }"; // Act string fixedSarif; bool changeApplied = RoslynV1SarifFixer.FixRoslynV1Sarif(testSarif, out fixedSarif); // Assert Assert.IsTrue(changeApplied); Assert.AreEqual(@"{ ""version"": ""0.1"", ""toolInfo"": { ""toolName"": ""Microsoft (R) Visual C# Compiler"", ""productVersion"": ""1.0.0"", ""fileVersion"": ""1.0.0"" }, ""issues"": [ { ""ruleId"": ""DD001"", ""locations"": [ { ""analysisTarget"": [ { ""uri"": ""C:\\agent\\_work\\2\\s\\MyTestProj\\Program.cs"", } ] } ], ""shortMessage"": ""Test shortMessage. It features \""quoted text\"" and has \\slashes."", ""fullMessage"": ""Test fullMessage. It features \""quoted text\"" and has \\slashes."", ""properties"": { ""severity"": ""Info"", ""title"": ""Test title. It features \""quoted text\"" and has \\slashes."", ""helpLink"": ""https://github.com/SonarSource/sonar-msbuild-runner"", } } ] }", fixedSarif); }