ConvertProblemToSarifResult() public method

public ConvertProblemToSarifResult ( AndroidStudioProblem problem ) : System.Result
problem AndroidStudioProblem
return System.Result
        public void AndroidStudioConverter_ConvertSarifResult_GeneratesLocationWithOnlyPackage()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();

            builder.File           = null;
            builder.Package        = "FancyPackageName";
            builder.Module         = null;
            builder.EntryPointName = null;

            var expectedLocation = new Location
            {
                FullyQualifiedLogicalName = "FancyPackageName"
            };

            var expectedLogicalLocations = new Dictionary <string, LogicalLocation>
            {
                {
                    "FancyPackageName", new LogicalLocation {
                        ParentKey = null, Kind = LogicalLocationKind.Package
                    }
                }
            };

            var    converter = new AndroidStudioConverter();
            Result result    = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
        public void AndroidStudioConverter_ConvertSarifResult_CanRecordSourceFileAndModule()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();
            builder.File = "File Goes Here";
            builder.Package = null;
            builder.Module = "LastResortModule";
            builder.EntryPointName = null;

            var expectedLocation = new Location
            {
                ResultFile = new PhysicalLocation
                {
                    Uri = new Uri("File Goes Here", UriKind.RelativeOrAbsolute),
                },
                FullyQualifiedLogicalName = "LastResortModule"
            };

            var expectedLogicalLocations = new Dictionary<string, LogicalLocation>
            {
                {
                    "LastResortModule", new LogicalLocation { ParentKey = null, Name = "LastResortModule", Kind = LogicalLocationKind.Module }
                }
               };

            var converter = new AndroidStudioConverter();
            Result result = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
        private static LocationInfo GetLocationInfoForBuilder(AndroidStudioProblem.Builder builder)
        {
            var    converter = new AndroidStudioConverter();
            Result result    = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            Location location = result.Locations.First();

            string logicalLocationKey = converter.LogicalLocationsDictionary.Keys.SingleOrDefault();
            IList <LogicalLocationComponent> logicalLocationComponents = logicalLocationKey != null
                ? converter.LogicalLocationsDictionary[logicalLocationKey]
                : new List <LogicalLocationComponent>(0);

            return(new LocationInfo
            {
                Location = location,
                LogicalLocationComponents = logicalLocationComponents
            });
        }
        public void AndroidStudioConverter_ConvertSarifResult_CanRecordSourceFileAndModule()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();

            builder.File           = "File Goes Here";
            builder.Package        = null;
            builder.Module         = "LastResortModule";
            builder.EntryPointName = null;

            var expectedLocation = new Location
            {
                PhysicalLocation = new PhysicalLocation
                {
                    FileLocation = new FileLocation
                    {
                        Uri = new Uri("File Goes Here", UriKind.RelativeOrAbsolute)
                    },
                },
                FullyQualifiedLogicalName = "LastResortModule"
            };

            var expectedLogicalLocations = new Dictionary <string, LogicalLocation>
            {
                {
                    "LastResortModule", new LogicalLocation {
                        ParentKey = null, Kind = LogicalLocationKind.Module
                    }
                }
            };

            var    converter = new AndroidStudioConverter();
            Result result    = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
        public void AndroidStudioConverter_ConvertSarifResult_RecordsModuleAsTopLevelIfPresent()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();

            builder.File           = null;
            builder.Module         = "my_fancy_binary";
            builder.EntryPointType = "method";
            builder.EntryPointName = "my_method";

            var expectedLocation = new Location
            {
                FullyQualifiedLogicalName = "my_fancy_binary\\my_method",
            };

            var expectedLogicalLocations = new Dictionary <string, LogicalLocation>
            {
                {
                    "my_fancy_binary", new LogicalLocation {
                        ParentKey = null, Kind = LogicalLocationKind.Module
                    }
                },
                {
                    @"my_fancy_binary\my_method",
                    new LogicalLocation {
                        ParentKey = "my_fancy_binary", Name = "my_method", Kind = LogicalLocationKind.Member
                    }
                },
            };

            var    converter = new AndroidStudioConverter();
            Result result    = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
        public void AndroidStudioConverter_ConvertSarifResult_GeneratesLocationWithMethodEntryPointAndPackage()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();
            builder.File = null;
            builder.Package = "FancyPackageName";
            builder.Module = null;
            builder.EntryPointType = "method";
            builder.EntryPointName = "my_method";

            var expectedLocation = new Location
            {
                FullyQualifiedLogicalName = "FancyPackageName\\my_method"
            };

            var expectedLogicalLocations = new Dictionary<string, LogicalLocation>
            {
                {
                    "FancyPackageName", new LogicalLocation { ParentKey = null, Name = "FancyPackageName", Kind = LogicalLocationKind.Package }
                },
                {
                    @"FancyPackageName\my_method", new LogicalLocation { ParentKey = "FancyPackageName", Name = "my_method", Kind = LogicalLocationKind.Member }
                },
               };

            var converter = new AndroidStudioConverter();
            Result result = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
        private static LocationInfo GetLocationInfoForBuilder(AndroidStudioProblem.Builder builder)
        {
            var converter = new AndroidStudioConverter();
            Result result = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            Location location = result.Locations.First();

            string logicalLocationKey = converter.LogicalLocationsDictionary.Keys.SingleOrDefault();
            LogicalLocation logicalLocation = logicalLocationKey != null
                ? converter.LogicalLocationsDictionary[logicalLocationKey]
                : null;

            return new LocationInfo
            {
                Location = location,
                LogicalLocation = logicalLocation
            };
        }
        public void AndroidStudioConverter_ConvertSarifResult_RecordsModuleAsTopLevelIfPresent()
        {
            var builder = AndroidStudioProblemTests.GetDefaultProblemBuilder();
            builder.File = null;
            builder.Module = "my_fancy_binary";
            builder.EntryPointType = "method";
            builder.EntryPointName = "my_method";

            var expectedLocation = new Location
            {
                FullyQualifiedLogicalName = "my_fancy_binary\\my_method",
            };

            var expectedLogicalLocations = new Dictionary<string, LogicalLocation>
            {
                {
                    "my_fancy_binary", new LogicalLocation { ParentKey = null, Name = "my_fancy_binary", Kind = LogicalLocationKind.Module }
                },
                {
                    @"my_fancy_binary\my_method",
                    new LogicalLocation { ParentKey = "my_fancy_binary", Name = "my_method", Kind = LogicalLocationKind.Member }
                },
               };

            var converter = new AndroidStudioConverter();
            Result result = converter.ConvertProblemToSarifResult(new AndroidStudioProblem(builder));

            result.Locations[0].ValueEquals(expectedLocation).Should().BeTrue();

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }