public void SarifErrorListItem_WhenResultRefersToRuleWithNoMessageStrings_ContainsBlankMessage() { var result = new Result { Message = new Message { Id = "nonExistentMessageId", }, RuleId = "TST0001", }; var run = new Run { Tool = new Tool { Driver = new ToolComponent { Rules = new List <ReportingDescriptor> { new ReportingDescriptor { Id = "TST0001", }, }, }, }, }; SarifErrorListItem item = MakeErrorListItem(run, result); item.Message.Should().Be(string.Empty); }
public void CodeAnalysisResultManager_VerifyFileWithArtifactHash_HasNoEmbeddedFile() { // Arrange. const string PathInLogFile = @"C:\Code\sarif-sdk\src\Sarif\Notes.cs"; const string ResolvedPath = @"D:\Users\John\source\sarif-sdk\src\Sarif\Notes.cs"; const string EmbeddedFilePath = null; const int RunId = 1; var target = new CodeAnalysisResultManager( null, // This test never touches the file system. this.FakePromptForResolvedPath, this.FakePromptForEmbeddedFile); var dataCache = new RunDataCache(); target.RunIndexToRunDataCache.Add(RunId, dataCache); this.embeddedFileDialogResult = ResolveEmbeddedFileDialogResult.None; var sarifErrorListItem = new SarifErrorListItem { LogFilePath = @"C:\Code\sarif-sdk\src\.sarif\Result.sarif" }; // Act. bool result = target.VerifyFileWithArtifactHash(sarifErrorListItem, PathInLogFile, dataCache, ResolvedPath, EmbeddedFilePath, out string actualResolvedPath); // Assert. result.Should().BeTrue(); actualResolvedPath.Should().Be(ResolvedPath); // no dialog pop up this.numEmbeddedFilePrompts.Should().Be(0); }
private void ErrorListInlineLink_Click(object sender, RoutedEventArgs e) { Hyperlink hyperLink = sender as Hyperlink; if (hyperLink != null) { Tuple <int, int> data = hyperLink.Tag as Tuple <int, int>; // data.Item1 = index of SarifErrorListItem // data.Item2 = id of related location to link SarifErrorListItem sarifResult = _errors[Convert.ToInt32(data.Item1)]; CodeFlowLocationModel location = sarifResult.RelatedLocations.Where(l => l.Id == data.Item2).FirstOrDefault(); if (location != null) { // Set the current sarif error in the manager so we track code locations. CodeAnalysisResultManager.Instance.CurrentSarifResult = sarifResult; SarifViewerPackage.SarifToolWindow.Control.DataContext = null; if (sarifResult.HasDetails) { // Setting the DataContext to null (above) forces the TabControl to select the appropriate tab. SarifViewerPackage.SarifToolWindow.Control.DataContext = sarifResult; } location.NavigateTo(false); location.ApplyDefaultSourceFileHighlighting(); } } }
/// <summary> /// Initializes a new instance of the <see cref="DisposableDifferenceViewerControl"/> class. /// </summary> /// <param name="errorListItem">Corresponding SarifErrorListItem object.</param> /// <param name="differenceViewer"><see cref="IWpfDifferenceViewer"/> instance.</param> /// <param name="description">Description of the changes. Optional.</param> /// <param name="additionalContent">Additional content to display at the bottom. Optional.</param> internal DisposableDifferenceViewerControl( SarifErrorListItem errorListItem, IWpfDifferenceViewer differenceViewer, string description = null, FrameworkElement additionalContent = null) { this.InitializeComponent(); this.sarifErrorListItem = errorListItem; this.differenceViewer = Requires.NotNull(differenceViewer, nameof(differenceViewer)); if (!string.IsNullOrWhiteSpace(description)) { var descriptionBlock = new TextBlock { TextWrapping = TextWrapping.Wrap, Padding = new Thickness(5), }; descriptionBlock.Inlines.Add(new Run() { Text = description, }); this.StackPanelContent.Children.Add(descriptionBlock); } this.StackPanelContent.Children.Add(this.differenceViewer.VisualElement); if (additionalContent != null) { this.StackPanelContent.Children.Add(additionalContent); } }
public void SarifErrorListItem_WhenMessageAndFormattedRuleMessageAreAbsentButRuleMetadataIsPresent_ContainsBlankMessage() { // This test prevents regression of #647, // "Viewer NRE when result lacks message/formattedRuleMessage but rule metadata is present" var result = new Result { RuleId = "TST0001", }; var run = new Run { Tool = new Tool { Driver = new ToolComponent { Rules = new List <ReportingDescriptor> { new ReportingDescriptor { Id = "TST0001", }, }, }, }, }; SarifErrorListItem item = MakeErrorListItem(run, result); item.Message.Should().Be(string.Empty); }
/// <summary> /// Remove the specified error from the Error List. /// </summary> /// <param name="errorToRemove"> /// The error to remove from the Error List. /// </param> public void RemoveError(SarifErrorListItem errorToRemove) { using (this.tableEntriesLock.EnterWriteLock()) { // Find the dictionary entry for the one log file that contains the error to be // removed. Any given error object can appear in at most one log file, even if // multiple log files report the "same" error. List <SarifResultTableEntry> tableEntryListWithSpecifiedError = this.logFileToTableEntries.Values .SingleOrDefault(tableEntryList => tableEntryList.Select(tableEntry => tableEntry.Error).Contains(errorToRemove)); if (tableEntryListWithSpecifiedError != null) { // Any give error object can appear at most once in any log file, even if the // log file reports the "same" error multiple times. And we've already seen // that this error object does appear in this log file, so calling Single is // just fine. SarifResultTableEntry entryToRemove = tableEntryListWithSpecifiedError.Single(tableEntry => tableEntry.Error == errorToRemove); this.CallSinks(sink => sink.RemoveEntries(new[] { entryToRemove })); tableEntryListWithSpecifiedError.Remove(entryToRemove); entryToRemove.Dispose(); } } }
public void SarifErrorListItem_HasEmbeddedLinks_MultipleSentencesWithEmbeddedLinks() { const string s1 = "The quick [brown](1) fox."; const string s2 = "Jumps over the [lazy](2) dog."; var result = new Result { Message = new Message() { Text = $"{s1} {s2}", }, }; SarifErrorListItem item = TestUtilities.MakeErrorListItem(result); item.HasEmbeddedLinks.Should().BeTrue(); // "The quick ", "brown", " fox.", "Jumps over the ", "lazy", " dog." item.MessageInlines.Count.Should().Be(5); item.MessageInlines[0].ContentStart.GetTextInRun(XamlDoc.LogicalDirection.Forward).Should().BeEquivalentTo("The quick "); var hyperlink = item.MessageInlines[1] as XamlDoc.Hyperlink; hyperlink.Inlines.First().ContentStart.GetTextInRun(XamlDoc.LogicalDirection.Forward).Should().BeEquivalentTo("brown"); item.MessageInlines[2].ContentStart.GetTextInRun(XamlDoc.LogicalDirection.Forward).Should().BeEquivalentTo(" fox. Jumps over the "); hyperlink = item.MessageInlines[3] as XamlDoc.Hyperlink; hyperlink.Inlines.First().ContentStart.GetTextInRun(XamlDoc.LogicalDirection.Forward).Should().BeEquivalentTo("lazy"); item.MessageInlines[4].ContentStart.GetTextInRun(XamlDoc.LogicalDirection.Forward).Should().BeEquivalentTo(" dog."); item.ShortMessage.Should().Be("The quick [brown](1) fox."); item.Message.Should().Be("The quick [brown](1) fox. Jumps over the [lazy](2) dog."); }
public void SarifErrorListItem_WhenRuleMetadataIsAbsent_SynthesizesRuleModelFromResultRuleId() { var result = new Result { RuleId = "TST0001", }; var run = new Run { Tool = new Tool { Driver = new ToolComponent { Rules = new List <ReportingDescriptor> { // No metadata for rule TST0001. }, }, }, }; SarifErrorListItem item = MakeErrorListItem(run, result); item.Rule.Id.Should().Be("TST0001"); }
public void SarifErrorListItem_WithPropertyBags_HasProperties() { var result = new Result(); result.SetProperty("text", "test strings"); result.SetProperty <bool>("validated", true); result.SetProperty <double>("totalAmount", 344.235d); result.SetProperty <int[]>("params", new int[] { -1, 2, 3 }); result.SetProperty <object>("nullObj", null); result.SetProperty <dynamic>("object", new { foo = "bar" }); SarifErrorListItem item = TestUtilities.MakeErrorListItem(result); item.Properties.Should().BeEmpty(); item.PopulateAdditionalPropertiesIfNot(); item.Properties.Should().NotBeNull(); item.Properties.Count.Should().Be(6); item.Properties.First(kv => kv.Key == "text").Value.Should().BeEquivalentTo("\"test strings\""); item.Properties.First(kv => kv.Key == "validated").Value.Should().BeEquivalentTo("true"); item.Properties.First(kv => kv.Key == "totalAmount").Value.Should().BeEquivalentTo("344.235"); item.Properties.First(kv => kv.Key == "params").Value.Should().BeEquivalentTo("[-1,2,3]"); item.Properties.First(kv => kv.Key == "nullObj").Value.Should().BeNull(); item.Properties.First(kv => kv.Key == "object").Value.Should().BeEquivalentTo("{\"foo\":\"bar\"}"); }
private static void VerifyErrorListItemEntry(SarifErrorListItem error, SarifResultTableEntry entry, dynamic test) { error.ShortMessage.Should().Be(test.ShortMessage); error.Message.Should().Be(test.FullMessage); error.RawMessage.Should().Be(test.RawMessage.Trim()); error.HasEmbeddedLinks.Should().Be(test.ContainsHyperlink); entry.TryGetValue(StandardTableKeyNames.Text, out object textColumn).Should().BeTrue(); entry.TryGetValue(StandardTableKeyNames.FullText, out object fullTextColumn).Should().BeTrue(); entry.TryGetValue(StandardTableKeyNames2.TextInlines, out object textInlinesColumn).Should().BeTrue(); entry.TryGetValue(SarifResultTableEntry.FullTextInlinesColumnName, out object fullTextInlinesColumn).Should().BeTrue(); ((string)textColumn).Should().Be(test.ShortMessage); ((string)fullTextColumn).Should().Be(error.HasDetailsContent ? test.FullMessage : null); if (test.ContainsHyperlink) { var textInlines = textInlinesColumn as List <Inline>; textInlines.Should().NotBeNull(); SdkUIUtilities.GetPlainText(textInlines).Should().Be(test.ShortPlainText); var fullTextInlines = fullTextInlinesColumn as List <Inline>; fullTextInlines.Should().NotBeNull(); SdkUIUtilities.GetPlainText(fullTextInlines).Should().Be(test.FullPlainText); } else { textInlinesColumn.Should().BeNull(); fullTextInlinesColumn.Should().BeNull(); } }
public void SarifResultEntry_TryGetValue_TextWithMarkdownHyperlinks() { string messageText = "Sample [text](0) with hyperlink to [example web site](https://example.com)."; var errorItem = new SarifErrorListItem { RawMessage = messageText, Message = messageText, ShortMessage = messageText }; var tableEntry = new SarifResultTableEntry(errorItem); tableEntry.TryGetValue("textinlines", out object inlines).Should().Be(true); List <Inline> inlineList = inlines as List <Inline>; inlineList.Should().NotBeNull(); inlineList.Count.Should().Be(5); inlineList[1].GetType().Should().Be(typeof(Hyperlink)); inlineList[3].GetType().Should().Be(typeof(Hyperlink)); tableEntry.TryGetValue("text", out object text).Should().Be(true); ((string)text).Should().BeEquivalentTo(messageText); tableEntry.TryGetValue("fullText", out object fullText).Should().Be(true); ((string)fullText).Should().BeNull(); }
private void ErrorListInlineLink_Click(object sender, RoutedEventArgs e) { Hyperlink hyperLink = sender as Hyperlink; if (hyperLink != null) { Tuple <int, int> indices = hyperLink.Tag as Tuple <int, int>; SarifErrorListItem sarifResult = _errors[indices.Item1]; // Set the current sarif error in the manager so we track code locations. CodeAnalysisResultManager.Instance.CurrentSarifError = sarifResult; if (sarifResult.HasDetails) { // Setting the DataContext to be null first forces the TabControl to select the appropriate tab. SarifViewerPackage.SarifToolWindow.Control.DataContext = null; SarifViewerPackage.SarifToolWindow.Control.DataContext = sarifResult; } else { SarifViewerPackage.SarifToolWindow.Control.DataContext = null; } sarifResult.RelatedLocations[indices.Item2].NavigateTo(false); sarifResult.RelatedLocations[indices.Item2].ApplyDefaultSourceFileHighlighting(); } }
public void SarifErrorListItem_WhenRuleMetadataIsPresent_PopulatesRuleModelFromSarifRule() { var result = new Result { RuleId = "TST0001", }; var run = new Run { Tool = new Tool { Driver = new ToolComponent { Rules = new List <ReportingDescriptor> { new ReportingDescriptor { Id = "TST0001", }, }, }, }, }; SarifErrorListItem item = MakeErrorListItem(run, result); item.Rule.Id.Should().Be("TST0001"); }
public void SarifErrorListItem_WhenFixIsConfinedToOneFile_IsFixable() { var result = new Result { Fixes = new List <Fix> { new Fix { ArtifactChanges = new List <ArtifactChange> { new ArtifactChange { ArtifactLocation = new ArtifactLocation { Uri = new Uri(FileName, UriKind.Relative), }, Replacements = new List <Replacement> { new Replacement { DeletedRegion = new Region { CharOffset = 52, CharLength = 5, }, }, }, }, new ArtifactChange { ArtifactLocation = new ArtifactLocation { Uri = new Uri(FileName, UriKind.Relative), }, Replacements = new List <Replacement> { new Replacement { DeletedRegion = new Region { CharOffset = 52, CharLength = 5, }, }, }, }, }, }, }, }; SarifErrorListItem item = TestUtilities.MakeErrorListItem(result); CodeAnalysisResultManager.Instance.RunIndexToRunDataCache.Add(item.RunIndex, new RunDataCache()); item.Fixes.Should().BeEmpty(); item.PopulateFixModelsIfNot(); item.Fixes.Should().NotBeEmpty(); item.IsFixable().Should().BeTrue(); }
public void SarifErrorListItem_WhenThereAreNoFixes_IsNotFixable() { var result = new Result(); SarifErrorListItem item = MakeErrorListItem(result); item.IsFixable().Should().BeFalse(); }
public void SarifErrorListItem_WhenMessageIsAbsent_ContainsBlankMessage() { var result = new Result(); SarifErrorListItem item = MakeErrorListItem(result); item.Message.Should().Be(string.Empty); }
public void SarifErrorListItem_WithoutPropertyBags_EmptyProperties() { var result = new Result(); SarifErrorListItem item = TestUtilities.MakeErrorListItem(result); item.Properties.Should().NotBeNull(); item.Properties.Should().BeEmpty(); }
public void SarifErrorListItem_HelpLinkShouldBeSameAs_RuleHelpUri() { string link = "https://example.com/TST0001"; var result = new Result { Message = new Message { Text = "The quick brown fox.", }, RuleId = "TST0001", }; var run = new Run { Tool = new Tool { Driver = new ToolComponent { Rules = new List <ReportingDescriptor> { new ReportingDescriptor { Id = "TST0001", HelpUri = new Uri(link), }, }, }, }, }; SarifErrorListItem item = TestUtilities.MakeErrorListItem(run, result); item.HelpLink.Should().NotBeNull(); item.HelpLink.Should().BeEquivalentTo(link); // without help Uri run = new Run { Tool = new Tool { Driver = new ToolComponent { Rules = new List <ReportingDescriptor> { new ReportingDescriptor { Id = "TST0001" }, }, }, }, }; item = TestUtilities.MakeErrorListItem(run, result); item.HelpLink.Should().BeNull(); }
public void SarifSnapshot_TryGetValue_NoLineNumber() { SarifErrorListItem errorItem = new SarifErrorListItem(); SarifSnapshot snapshot = new SarifSnapshot(String.Empty, new List<SarifErrorListItem>() { errorItem }); Object value; snapshot.TryGetValue(0, "line", out value).Should().Be(true); value.Should().Be(-1); }
public void SarifErrorListItem_WhenFixSpansMultipleFiles_IsNotFixable() { var result = new Result { Fixes = new List <Fix> { new Fix { ArtifactChanges = new List <ArtifactChange> { new ArtifactChange { ArtifactLocation = new ArtifactLocation { Uri = new Uri(FileName, UriKind.Relative), }, Replacements = new List <Replacement> { new Replacement { DeletedRegion = new Region { CharOffset = 52, CharLength = 5, }, }, }, }, new ArtifactChange { ArtifactLocation = new ArtifactLocation { Uri = new Uri("SomeOther" + FileName, UriKind.Relative), }, Replacements = new List <Replacement> { new Replacement { DeletedRegion = new Region { CharOffset = 52, CharLength = 5, }, }, }, }, }, }, }, }; SarifErrorListItem item = MakeErrorListItem(result); item.IsFixable().Should().BeFalse(); }
public void SarifErrorListItem_WhenFixIsConfinedToOneFile_IsFixable() { var result = new Result { Fixes = new List <Fix> { new Fix { ArtifactChanges = new List <ArtifactChange> { new ArtifactChange { ArtifactLocation = new ArtifactLocation { Uri = new Uri(FileName, UriKind.Relative), }, Replacements = new List <Replacement> { new Replacement { DeletedRegion = new Region { CharOffset = 52, CharLength = 5, }, }, }, }, new ArtifactChange { ArtifactLocation = new ArtifactLocation { Uri = new Uri(FileName, UriKind.Relative), }, Replacements = new List <Replacement> { new Replacement { DeletedRegion = new Region { CharOffset = 52, CharLength = 5, }, }, }, }, }, }, }, }; SarifErrorListItem item = MakeErrorListItem(result); item.IsFixable().Should().BeTrue(); }
public void SarifErrorListItem_WhenRegionIsAbsent_HasNoLineMarker() { var item = new SarifErrorListItem { FileName = "file.ext" }; var lineMarker = item.LineMarker; lineMarker.Should().Be(null); }
private async Task <object> CreateNewDifferenceViewerAsync( SarifErrorListItem errorListItem, IProjectionBuffer originalBuffer, IProjectionBuffer newBuffer, string description, FrameworkElement additionalContent) { IDifferenceBuffer diffBuffer = this.differenceBufferFactoryService.CreateDifferenceBuffer( originalBuffer, newBuffer, options: default,
public void SarifSnapshot_TryGetValue_NoLineNumber() { var errorItem = new SarifErrorListItem(); var tableEntry = new SarifResultTableEntry(errorItem); object value; tableEntry.TryGetValue("line", out value).Should().Be(true); value.Should().Be(-1); }
public void SarifErrorListItem_TreatsNotApplicableResultAsNote() { var result = new Result { Kind = ResultKind.NotApplicable, Level = FailureLevel.None, }; SarifErrorListItem item = TestUtilities.MakeErrorListItem(result); item.Level.Should().Be(FailureLevel.Note); }
public void SarifErrorListItem_TreatsOpenResultAsWarning() { var result = new Result { Kind = ResultKind.Open, Level = FailureLevel.None, }; SarifErrorListItem item = TestUtilities.MakeErrorListItem(result); item.Level.Should().Be(FailureLevel.Warning); }
public void SarifErrorListItem_TreatsReviewResultAsWarning() { var result = new Result { Kind = ResultKind.Review, Level = FailureLevel.None, }; SarifErrorListItem item = MakeErrorListItem(result); item.Level.Should().Be(FailureLevel.Warning); }
public void SarifErrorListItem_TreatsPassResultAsNote() { var result = new Result { Kind = ResultKind.Pass, Level = FailureLevel.None, }; SarifErrorListItem item = MakeErrorListItem(result); item.Level.Should().Be(FailureLevel.Note); }
public void SarifErrorListItem_TreatsFailResultAccordingToLevel() { var result = new Result { Level = FailureLevel.Error, Kind = ResultKind.Fail, }; SarifErrorListItem item = MakeErrorListItem(result); item.Level.Should().Be(FailureLevel.Error); }
private int WriteRunToErrorList(Run run, string logFilePath, Solution solution) { RunDataCache dataCache = new RunDataCache(run); CodeAnalysisResultManager.Instance.RunDataCaches.Add(++CodeAnalysisResultManager.Instance.CurrentRunId, dataCache); CodeAnalysisResultManager.Instance.CacheUriBasePaths(run); List <SarifErrorListItem> sarifErrors = new List <SarifErrorListItem>(); var projectNameCache = new ProjectNameCache(solution); StoreFileDetails(run.Artifacts); if (run.Results != null) { foreach (Result result in run.Results) { result.Run = run; var sarifError = new SarifErrorListItem(run, result, logFilePath, projectNameCache); sarifErrors.Add(sarifError); } } if (run.Invocations != null) { foreach (var invocation in run.Invocations) { if (invocation.ToolConfigurationNotifications != null) { foreach (Notification configurationNotification in invocation.ToolConfigurationNotifications) { var sarifError = new SarifErrorListItem(run, configurationNotification, logFilePath, projectNameCache); sarifErrors.Add(sarifError); } } if (invocation.ToolExecutionNotifications != null) { foreach (Notification toolNotification in invocation.ToolExecutionNotifications) { if (toolNotification.Level != FailureLevel.Note) { var sarifError = new SarifErrorListItem(run, toolNotification, logFilePath, projectNameCache); sarifErrors.Add(sarifError); } } } } } (dataCache.SarifErrors as List <SarifErrorListItem>).AddRange(sarifErrors); SarifTableDataSource.Instance.AddErrors(sarifErrors); return(sarifErrors.Count); }
public void SarifSnapshot_TryGetValue_NegativeLineNumber() { int lineNumber = -10; SarifErrorListItem errorItem = new SarifErrorListItem(); errorItem.LineNumber = lineNumber; SarifSnapshot snapshot = new SarifSnapshot(String.Empty, new List<SarifErrorListItem>() { errorItem }); Object value; snapshot.TryGetValue(0, "line", out value).Should().Be(true); value.Should().Be(lineNumber - 1); }
private int WriteRunToErrorList(Run run, string logFilePath, Solution solution) { List <SarifErrorListItem> sarifErrors = new List <SarifErrorListItem>(); var projectNameCache = new ProjectNameCache(solution); StoreFileDetails(run.Files); if (run.Results != null) { foreach (Result result in run.Results) { var sarifError = new SarifErrorListItem(run, result, logFilePath, projectNameCache); sarifErrors.Add(sarifError); } } if (run.Invocations != null) { foreach (var invocation in run.Invocations) { if (invocation.ConfigurationNotifications != null) { foreach (Notification configurationNotification in invocation.ConfigurationNotifications) { var sarifError = new SarifErrorListItem(run, configurationNotification, logFilePath, projectNameCache); sarifErrors.Add(sarifError); } } if (invocation.ToolNotifications != null) { foreach (Notification toolNotification in invocation.ToolNotifications) { if (toolNotification.Level != NotificationLevel.Note) { var sarifError = new SarifErrorListItem(run, toolNotification, logFilePath, projectNameCache); sarifErrors.Add(sarifError); } } } } } foreach (var error in sarifErrors) { CodeAnalysisResultManager.Instance.SarifErrors.Add(error); } SarifTableDataSource.Instance.AddErrors(sarifErrors); return(sarifErrors.Count); }
internal static bool CanNavigateTo(SarifErrorListItem sarifError) { throw new NotImplementedException(); }
bool TryGetSarifResult(ITableEntryHandle entryHandle, out SarifErrorListItem sarifResult) { ITableEntriesSnapshot entrySnapshot; int entryIndex; sarifResult = default(SarifErrorListItem); if (entryHandle.TryGetSnapshot(out entrySnapshot, out entryIndex)) { var snapshot = entrySnapshot as SarifSnapshot; if (snapshot != null) { sarifResult = snapshot.GetItem(entryIndex); } } return sarifResult != null; }
private SarifErrorListItem GetResult(Run run, Result result, string logFilePath) { SarifErrorListItem sarifError = new SarifErrorListItem(run, result, logFilePath); return sarifError; }
private static SarifErrorListItem GetDesignTimeViewModel1() { SarifErrorListItem viewModel = new SarifErrorListItem(); viewModel.Message = "Potential mismatch between sizeof and countof quantities. Use sizeof() to scale byte sizes."; viewModel.Tool = new ToolModel() { Name = "FxCop", Version = "1.0.0.0", }; viewModel.Rule = new RuleModel() { Id = "CA1823", Name = "Avoid unused private fields", HelpUri = "http://aka.ms/analysis/ca1823", DefaultLevel = "Unknown" }; viewModel.Invocation = new InvocationModel() { CommandLine = @"""C:\Temp\Foo.exe"" target.file /o out.sarif", FileName = @"C:\Temp\Foo.exe", }; viewModel.Locations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(11, 1, 11, 2, 0, 0), }); viewModel.Locations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(12, 1, 12, 2, 0, 0), }); viewModel.RelatedLocations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(21, 1, 21, 2, 0, 0), }); viewModel.RelatedLocations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(22, 1, 22, 2, 0, 0), }); viewModel.RelatedLocations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(23, 1, 23, 2, 0, 0), }); viewModel.CallTrees.Add(new CallTree( new List<CallTreeNode> { new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Assignment } }, new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Target = "my_func" }, Children = new List<CallTreeNode> { new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn } } } } })); StackCollection stack1 = new StackCollection("Stack A1"); stack1.Add(new StackFrameModel() { Message = "Message A1.1", FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Line = 11, Column = 1, FullyQualifiedLogicalName ="My.Assembly.Main(string[] args)", Module = "My.Module.dll", }); stack1.Add(new StackFrameModel() { Message = "Message A1.2", FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Line = 12, Column = 1, FullyQualifiedLogicalName = "Our.Shared.Library.Method(int param)", Module = "My.Module.dll", }); stack1.Add(new StackFrameModel() { Message = "Message A1.3", FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Line = 1, Column = 1, FullyQualifiedLogicalName = "Your.PIA.External()", }); viewModel.Stacks.Add(stack1); FixModel fix1 = new FixModel("Replace *.Close() with *.Dispose()."); FileChangeModel fileChange11 = new FileChangeModel(); fileChange11.FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs"; fileChange11.Replacements.Add(new ReplacementModel() { Offset = 1234, DeletedLength = ".Close()".Length, InsertedString = ".Dispose()", }); fix1.FileChanges.Add(fileChange11); viewModel.Fixes.Add(fix1); return viewModel; }