Esempio n. 1
0
        public void MakeUriAbsoluteVisitor_VisitPhysicalLocation_DoesNotSetUriIfNotInDictionary()
        {
            var run = new Run
            {
                OriginalUriBaseIds = new Dictionary <string, ArtifactLocation>
                {
                    ["%TEST%"] = new ArtifactLocation {
                        Uri = new Uri("C:/github/sarif/")
                    }
                }
            };

            // Initializes visitor with run in order to retrieve uri base id mappings
            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();

            visitor.VisitRun(run);

            PhysicalLocation location = new PhysicalLocation()
            {
                ArtifactLocation = new ArtifactLocation {
                    UriBaseId = "%TEST2%", Uri = new Uri("src/file.cs", UriKind.Relative)
                }
            };

            PhysicalLocation newLocation = visitor.VisitPhysicalLocation(location);

            newLocation.ArtifactLocation.UriBaseId.Should().NotBeNull();
            newLocation.ArtifactLocation.Uri.Should().BeEquivalentTo(new Uri("src/file.cs", UriKind.Relative));
        }
Esempio n. 2
0
        public void MakeUriAbsoluteVisitor_VisitRun_SetsAbsoluteUriForAllApplicableFiles()
        {
            Run run = GenerateRunForTest(new Dictionary <string, ArtifactLocation>()
            {
                ["%TEST1%"] = new ArtifactLocation {
                    Uri = new Uri(@"C:\srcroot\")
                },
                ["%TEST2%"] = new ArtifactLocation {
                    Uri = new Uri(@"D:\bld\out\")
                }
            });

            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();

            Run newRun = visitor.VisitRun(run);

            // Validate.
            newRun.Artifacts[0].Location.Uri.ToString().Should().Be(@"file:///C:/srcroot/src/file1.cs");
            newRun.Artifacts[1].Location.Uri.ToString().Should().Be(@"file:///D:/bld/out/src/file2.dll");
            newRun.Artifacts[2].Location.Uri.ToString().Should().Be(@"file:///C:/srcroot/src/archive.zip");
            newRun.Artifacts[3].Location.Uri.ToString().Should().Be(@"file3.cs");
            newRun.Artifacts[4].Location.Uri.ToString().Should().Be(@"archive2.gz");
            newRun.Artifacts[5].Location.Uri.ToString().Should().Be(@"file4.cs");

            // Operation should zap all uri base ids
            newRun.Artifacts.Where(f => f.Location.UriBaseId != null).Any().Should().BeFalse();
        }
Esempio n. 3
0
        public void MakeUriAbsoluteVisitor_VisitRun_DoesNotSetAbsoluteUriIfNotApplicable()
        {
            Dictionary <string, ArtifactLocation> uriMapping = new Dictionary <string, ArtifactLocation>()
            {
                ["%TEST3%"] = new ArtifactLocation {
                    Uri = new Uri(@"C:\srcroot\")
                },
                ["%TEST4%"] = new ArtifactLocation {
                    Uri = new Uri(@"D:\bld\out\")
                }
            };

            Run expectedRun = GenerateRunForTest(uriMapping);
            Run actualRun   = expectedRun.DeepClone();

            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();
            Run newRun = visitor.VisitRun(actualRun);

            expectedRun.ValueEquals(actualRun).Should().BeTrue();
        }