public void SarifLogger_ScrapesFilesFromResult()
{
var sb = new StringBuilder();
using (var textWriter = new StringWriter(sb))
{
using (var sarifLogger = new SarifLogger(
textWriter,
analysisTargets: null,
verbose: false,
computeTargetsHash: true,
logEnvironment: false,
prereleaseInfo: null,
invocationTokensToRedact: null))
{
string ruleId = "RuleId";
var rule = new Rule() { Id = ruleId };
var result = new Result()
{
RuleId = ruleId,
Locations = new[]
{
new Location
{
AnalysisTarget = new PhysicalLocation { Uri = new Uri(@"file:///file0.cpp")},
ResultFile = new PhysicalLocation { Uri = new Uri(@"file:///file1.cpp")}
},
},
Fixes = new[]
{
new Fix
{
FileChanges = new[]
{
new FileChange
{
Uri = new Uri(@"file:///file2.cpp")
}
}
}
},
RelatedLocations = new[]
{
new AnnotatedCodeLocation
{
PhysicalLocation = new PhysicalLocation { Uri = new Uri(@"file:///file3.cpp")}
}
},
Stacks = new[]
{
new Stack
{
Frames = new[]
{
new StackFrame
{
Uri = new Uri(@"file:///file4.cpp")
}
}
}
},
CodeFlows = new[]
{
new CodeFlow
{
Locations = new[]
{
new AnnotatedCodeLocation
{
PhysicalLocation = new PhysicalLocation { Uri = new Uri(@"file:///file5.cpp")}
}
}
}
}
};
sarifLogger.Log(rule, result);
}
}
string logText = sb.ToString();
var sarifLog = JsonConvert.DeserializeObject<SarifLog>(logText);
int fileCount = 6;
for (int i = 0; i < fileCount; ++i)
{
string fileName = @"file" + i + ".cpp";
string fileDataKey = "file:///" + fileName;
sarifLog.Runs[0].Files.Should().ContainKey(fileDataKey, "file data for " + fileName + " should exist in files collection");
}
sarifLog.Runs[0].Files.Count.Should().Be(fileCount);
}