Esempio n. 1
0
        public void ToArtifactChangeModel_ArtifactChangeIsNull()
        {
            ArtifactChange artifactChange = null;

            var model = artifactChange.ToArtifactChangeModel(new Dictionary <string, ArtifactLocation>(), new FileRegionsCache());

            model.Should().BeNull();

            model = artifactChange.ToArtifactChangeModel(new Dictionary <string, Uri>(), new FileRegionsCache());
            model.Should().BeNull();
        }
        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");
        }
        public void ArtifactChangeModel_FromArtifactChange_RelativePath()
        {
            var change = new ArtifactChange
            {
                ArtifactLocation = new ArtifactLocation
                {
                    Uri = new Uri(@"\src\tools\util.cs", UriKind.RelativeOrAbsolute),
                },
                Replacements = new List <Replacement>(),
            };

            var model = change.ToArtifactChangeModel(s_emptyOriginalUriBaseIds, s_emptyFileRegionsCache);

            model.FilePath.Should().Be(@"\src\tools\util.cs");
        }
Esempio n. 4
0
        public void ToArtifactChangeModel_ArtifactLocationRelativePath()
        {
            string         relativePath   = "path/to/file1";
            ArtifactChange artifactChange = new ArtifactChange
            {
                ArtifactLocation = new ArtifactLocation
                {
                    Uri = new Uri(relativePath, UriKind.Relative),
                }
            };

            var model = artifactChange.ToArtifactChangeModel(new Dictionary <string, ArtifactLocation>(), new FileRegionsCache());

            model.Should().NotBeNull();
            model.FilePath.Should().BeEquivalentTo(relativePath);
            model.FileName.Should().BeEquivalentTo("file1");
        }
Esempio n. 5
0
        public void ToArtifactChangeModel_WithReplacement()
        {
            string         uriId          = "SRCROOT";
            string         relativePath   = "path/to/file1";
            ArtifactChange artifactChange = new ArtifactChange
            {
                ArtifactLocation = new ArtifactLocation
                {
                    Uri       = new Uri(relativePath, UriKind.Relative),
                    UriBaseId = uriId,
                },
                Replacements = new[]
                {
                    new Replacement {
                        DeletedRegion = new Region {
                            CharOffset = 0, CharLength = 10
                        }
                    },
                }
            };

            var uriBaseIds = new Dictionary <string, ArtifactLocation>
            {
                { uriId, new ArtifactLocation {
                      Uri = new Uri("file:///etc/", UriKind.Absolute)
                  } }
            };

            var model = artifactChange.ToArtifactChangeModel(uriBaseIds, new FileRegionsCache());

            model.Should().NotBeNull();
            model.FilePath.Should().BeEquivalentTo(relativePath);
            model.FileName.Should().BeEquivalentTo("file1");
            model.Replacements.Should().NotBeEmpty();
            model.Replacements.Count.Should().Be(1);
        }
Esempio n. 6
0
        public static ArtifactChangeModel ToArtifactChangeModel(this ArtifactChange fileChange, IDictionary <string, Uri> originalUriBaseIds, FileRegionsCache fileRegionsCache)
        {
            if (fileChange == null)
            {
                return(null);
            }

            Dictionary <string, ArtifactLocation> uriToArtifactLocationMap = null;

            if (originalUriBaseIds != null)
            {
                // convert IDictionary<string, Uri> to IDictionary<string, ArtifactLocation> which
                // is needed by Sarif.SDK extension method ArtifactLocation.TryReconstructAbsoluteUri()
                uriToArtifactLocationMap = new Dictionary <string, ArtifactLocation>(originalUriBaseIds.Count);
                foreach (KeyValuePair <string, Uri> entry in originalUriBaseIds)
                {
                    uriToArtifactLocationMap.Add(entry.Key, new ArtifactLocation {
                        Uri = entry.Value
                    });
                }
            }

            return(fileChange.ToArtifactChangeModel(uriToArtifactLocationMap, fileRegionsCache));
        }