Ejemplo n.º 1
0
        public void FxCopConverter_CreateResult_FakeContext_Member()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineModule("mybinary.dll");
            context.RefineNamespace("mynamespace");
            context.RefineType("mytype");
            context.RefineMember("mymember(string)");
            context.RefineMessage("CA0000", "VeryUsefulCheck", "1", "FakeCategory", "Breaking", "ExcludedInSource");
            context.RefineIssue(null, "test", "uncertain", "error", @"source", "myfile.cs", 13);
            context.RefineItem("hello!");

            string expectedLogicalLocation = "mynamespace.mytype.mymember(string)";

            var expectedResult = new Result
            {
                RuleId  = "CA0000",
                Message = new Message {
                    Arguments = new List <string>(new string[] { "hello!" })
                },
                SuppressionStates   = SuppressionStates.SuppressedInSource,
                PartialFingerprints = new Dictionary <string, string>(),
                AnalysisTarget      = new ArtifactLocation
                {
                    Uri = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                },
                Locations = new List <Location>
                {
                    new Location
                    {
                        PhysicalLocation = new PhysicalLocation
                        {
                            ArtifactLocation = new ArtifactLocation
                            {
                                Uri = new Uri("source\\myfile.cs", UriKind.RelativeOrAbsolute)
                            },
                            Region = new Region {
                                StartLine = 13
                            }
                        },
                        FullyQualifiedLogicalName = expectedLogicalLocation,
                        LogicalLocationIndex      = 3
                    }
                }
            };

            expectedResult.PartialFingerprints.Add("UniqueId", "1#test");
            expectedResult.SetProperty("Level", "error");
            expectedResult.SetProperty("Category", "FakeCategory");
            expectedResult.SetProperty("FixCategory", "Breaking");

            var expectedLogicalLocations = new List <LogicalLocation>
            {
                new LogicalLocation {
                    ParentIndex = -1, Name = "mybinary.dll", Kind = LogicalLocationKind.Module
                },
                new LogicalLocation {
                    ParentIndex = 0, Name = "mynamespace", FullyQualifiedName = "mybinary.dll!mynamespace", Kind = LogicalLocationKind.Namespace
                },
                new LogicalLocation {
                    ParentIndex = 1, Name = "mytype", FullyQualifiedName = "mybinary.dll!mynamespace.mytype", Kind = LogicalLocationKind.Type
                },
                new LogicalLocation {
                    ParentIndex = 2, Name = "mymember(string)", FullyQualifiedName = "mybinary.dll!mynamespace.mytype.mymember(string)", Kind = LogicalLocationKind.Member
                }
            };
            var    converter = new FxCopConverter();
            Result result    = converter.CreateResult(context);

            ValidateLogicalLocations(expectedLogicalLocations, converter.LogicalLocations);
        }