private DummyFixModel InitializeDummyFixModel()
        {
            var fileSystem = new DummyFileSystem();

            fileSystem.WriteAllBytes("index.html", File.ReadAllBytes(@"TestData\FixModel\index.html"));

            var fixModel = new DummyFixModel("Test dummy", fileSystem);

            var replacements = new List <ReplacementModel>();

            replacements.Add(new ReplacementModel()
            {
                Offset = 191, DeletedLength = 0, InsertedString = "\""
            });
            replacements.Add(new ReplacementModel()
            {
                Offset = 199, DeletedLength = 0, InsertedString = "\""
            });
            replacements.Add(new ReplacementModel()
            {
                Offset = 233, DeletedLength = 3, InsertedString = "img"
            });
            replacements.ForEach(rm => rm.InsertedBytes = Encoding.UTF8.GetBytes(rm.InsertedString));

            var changeModel = new ArtifactChangeModel()
            {
                FilePath = @"C:\source\index.html"
            };

            replacements.ForEach(r => changeModel.Replacements.Add(r));
            fixModel.ArtifactChanges.Add(changeModel);

            return(fixModel);
        }
Exemplo n.º 2
0
        public static ArtifactChangeModel ToArtifactChangeModel(this ArtifactChange fileChange, IDictionary <string, ArtifactLocation> originalUriBaseIds, FileRegionsCache fileRegionsCache)
        {
            if (fileChange == null)
            {
                return(null);
            }

            var model = new ArtifactChangeModel();

            // don't resolve filepath at model creation phase.
            // it will be resolved by TryResolveFilePath later.
            model.FilePath = fileChange.ArtifactLocation.Uri.IsAbsoluteUri ?
                             fileChange.ArtifactLocation.Uri.LocalPath :
                             fileChange.ArtifactLocation.Uri.OriginalString;

            if (fileChange.Replacements != null)
            {
                if (!fileChange.ArtifactLocation.TryReconstructAbsoluteUri(originalUriBaseIds, out Uri resolvedUri))
                {
                    resolvedUri = fileChange.ArtifactLocation.Uri;
                }

                foreach (Replacement replacement in fileChange.Replacements)
                {
                    model.Replacements.Add(replacement.ToReplacementModel(fileRegionsCache, resolvedUri));
                }
            }

            return(model);
        }
        public void ArtifactChangeModel_FromArtifactChange_RelativePath()
        {
            ArtifactChange change = new ArtifactChange
            {
                ArtifactLocation = new ArtifactLocation
                {
                    Uri = new Uri(@"\src\tools\util.cs", UriKind.RelativeOrAbsolute)
                },
                Replacements = new List <Replacement>()
            };

            ArtifactChangeModel model = change.ToArtifactChangeModel();

            model.FilePath.Should().Be(@"\src\tools\util.cs");
        }
Exemplo n.º 4
0
        public static ArtifactChangeModel ToArtifactChangeModel(this ArtifactChange fileChange)
        {
            if (fileChange == null)
            {
                return(null);
            }

            ArtifactChangeModel model = new ArtifactChangeModel();

            if (fileChange.Replacements != null)
            {
                model.FilePath = fileChange.ArtifactLocation.Uri.IsAbsoluteUri ?
                                 fileChange.ArtifactLocation.Uri.LocalPath :
                                 fileChange.ArtifactLocation.Uri.OriginalString;

                foreach (Replacement replacement in fileChange.Replacements)
                {
                    model.Replacements.Add(replacement.ToReplacementModel());
                }
            }

            return(model);
        }
        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",
                DefaultFailureLevel = FailureLevel.None
            };

            viewModel.Invocation = new InvocationModel()
            {
                CommandLine = @"""C:\Temp\Foo.exe"" target.file /o out.sarif",
                FileName    = @"C:\Temp\Foo.exe",
            };

            viewModel.Locations.Add(new LocationModel
            {
                FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs",
                Region   = new Region(11, 1, 11, 2, 0, 0, 0, 0, snippet: null, message: null, sourceLanguage: "en-US", properties: null),
            });

            viewModel.Locations.Add(new LocationModel
            {
                FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs",
                Region   = new Region(12, 1, 12, 2, 0, 0, 0, 0, snippet: null, message: null, sourceLanguage: "en-US", properties: null),
            });

            viewModel.RelatedLocations.Add(new LocationModel
            {
                FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs",
                Region   = new Region(21, 1, 21, 2, 0, 0, 0, 0, snippet: null, message: null, sourceLanguage: "en-US", properties: null),
            });

            viewModel.RelatedLocations.Add(new LocationModel
            {
                FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs",
                Region   = new Region(22, 1, 22, 2, 0, 0, 0, 0, snippet: null, message: null, sourceLanguage: "en-US", properties: null),
            });

            viewModel.RelatedLocations.Add(new LocationModel
            {
                FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs",
                Region   = new Region(23, 1, 23, 2, 0, 0, 0, 0, snippet: null, message: null, sourceLanguage: "en-US", properties: null),
            });

            viewModel.CallTrees.Add(new CallTree(
                                        new List <CallTreeNode>
            {
                new CallTreeNode
                {
                    Location = new ThreadFlowLocation()
                },

                new CallTreeNode
                {
                    Location = new ThreadFlowLocation(),
                    Children = new List <CallTreeNode>
                    {
                        new CallTreeNode
                        {
                            Location = new ThreadFlowLocation()
                        }
                    }
                }
            }, 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().", new FileSystem());
            ArtifactChangeModel fileChange11 = new ArtifactChangeModel();

            fileChange11.FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs";
            fileChange11.Replacements.Add(new ReplacementModel()
            {
                Offset         = 1234,
                DeletedLength  = ".Close()".Length,
                InsertedString = ".Dispose()",
            });
            fix1.ArtifactChanges.Add(fileChange11);
            viewModel.Fixes.Add(fix1);

            return(viewModel);
        }