public void ItemsAreAddedToTheTopOfTheCollection()
            {
                collection.Add("Added First");
                Assert.Equal(1, collection.Count);
                Assert.Equal("Added First", collection[0]);

                collection.Add("Added Second");
                Assert.Equal(2, collection.Count);
                Assert.Equal("Added Second", collection[0]);
                Assert.Equal("Added First", collection[1]);
            }
示例#2
0
        public static StackCollection ToStackCollection(this Stack stack, int resultId, int runIndex)
        {
            if (stack == null)
            {
                return(null);
            }

            var model = new StackCollection(stack.Message?.Text);

            if (stack.Frames != null)
            {
                foreach (StackFrame frame in stack.Frames)
                {
                    model.Add(frame.ToStackFrameModel(resultId, runIndex));
                }
            }

            return(model);
        }
        public static StackCollection ToStackCollection(this Stack stack)
        {
            if (stack == null)
            {
                return(null);
            }

            StackCollection model = new StackCollection(stack.Message?.Text);

            if (stack.Frames != null)
            {
                foreach (StackFrame frame in stack.Frames)
                {
                    model.Add(frame.ToStackFrameModel());
                }
            }

            return(model);
        }
示例#4
0
        public static StackCollection ToStackCollection(this Stack stack)
        {
            if (stack == null)
            {
                return null;
            }

            StackCollection model = new StackCollection(stack.Message);

            if (stack.Frames != null)
            {
                foreach (StackFrame frame in stack.Frames)
                {
                    model.Add(frame.ToStackFrameModel());
                }
            }

            return model;
        }
示例#5
0
        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
                            }
                        }
                    }
                }
            }, SarifViewerPackage.SarifToolWindow));

            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);
        }
示例#6
0
        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;
        }