CreateProjectContext() публичный статический Метод

public static CreateProjectContext ( ) : FxCopLogReader.Context
Результат FxCopLogReader.Context
        public void FxCopConverter_CreateResult_FakeContext_NoModule_Resource()
        {
            FxCopLogReader.Context context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineResource("myresource.resx");
            context.RefineMessage("CA0000", "VeryUsefulCheck", null, null, null, null);
            context.RefineIssue("hello!", "test", null, null, null, null, null);

            var    converter = new FxCopConverter();
            Result result    = converter.CreateResult(context);

            result.Locations.First().LogicalLocation.FullyQualifiedName.Should().Be(@"myresource.resx");
        }
        public void FxCopConverter_CreateIssue_FakeContext_NoModule_Member()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineNamespace("mynamespace");
            context.RefineType("mytype");
            context.RefineMember("mymember(string)");
            context.RefineMessage("CA0000", "VeryUsefulCheck", null, null, null);
            context.RefineIssue("hello!", null, null, null, null, null, null);

            FxCopConverter.CreateIssue(context).Locations.Should().Equal(
                new[] {
                new Location
                {
                    AnalysisTarget = new[]
                    {
                        new PhysicalLocationComponent
                        {
                            Uri      = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                            MimeType = MimeType.Binary
                        }
                    },
                    FullyQualifiedLogicalName = "mynamespace.mytype.mymember(string)",
                    LogicalLocation           = new[]
                    {
                        new LogicalLocationComponent
                        {
                            Name = "mynamespace",
                            Kind = LogicalLocationKind.ClrNamespace
                        },
                        new LogicalLocationComponent
                        {
                            Name = "mytype",
                            Kind = LogicalLocationKind.ClrType
                        },
                        new LogicalLocationComponent
                        {
                            Name = "mymember(string)",
                            Kind = LogicalLocationKind.ClrFunction
                        }
                    }
                }
            });
        }
Пример #3
0
        public void FxCopConverter_CreateIssue_FakeContext_NoModule_Member()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineNamespace("mynamespace");
            context.RefineType("mytype");
            context.RefineMember("mymember(string)");
            context.RefineMessage("CA0000", "VeryUsefulCheck", null, null, null, null);
            context.RefineIssue("hello!", null, null, null, null, null, null);

            var expectedLogicalLocations = new Dictionary <string, LogicalLocation>
            {
                {
                    "mynamespace",
                    new LogicalLocation {
                        ParentKey = null, Kind = LogicalLocationKind.Namespace
                    }
                },
                {
                    "mynamespace.mytype",
                    new LogicalLocation {
                        ParentKey = "mynamespace", Name = "mytype", Kind = LogicalLocationKind.Type
                    }
                },
                {
                    "mynamespace.mytype.mymember(string)",
                    new LogicalLocation {
                        ParentKey = "mynamespace.mytype", Name = "mymember(string)", Kind = LogicalLocationKind.Member
                    }
                }
            };

            var    converter = new FxCopConverter();
            Result result    = converter.CreateResult(context);

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
Пример #4
0
        public void FxCopConverter_CreateIssue_FakeContext_Resource()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineModule("mybinary.dll");
            context.RefineResource("myresource.resx");
            context.RefineMessage("CA0000", "VeryUsefulCheck", null, null, null);
            context.RefineIssue("hello!", "test", null, null, @"source", "myfile.cs", 13);

            FxCopConverter.CreateIssue(context).Locations.Should().Equal(new[]
            {
                new Location
                {
                    AnalysisTarget = new PhysicalLocation
                    {
                        Uri = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                    },
                    ResultFile = new PhysicalLocation
                    {
                        Uri    = new Uri("source\\myfile.cs", UriKind.RelativeOrAbsolute),
                        Region = new Region {
                            StartLine = 13
                        }
                    },
                    FullyQualifiedLogicalName = "myresource.resx",
                    LogicalLocation           = new[]
                    {
                        new LogicalLocationComponent
                        {
                            Name = "mybinary.dll",
                            Kind = LogicalLocationKind.ClrModule
                        },
                        new LogicalLocationComponent
                        {
                            Name = "myresource.resx",
                            Kind = LogicalLocationKind.ClrResource
                        }
                    }
                }
            });
        }
Пример #5
0
        public void FxCopLogReader_Context_RefineProjectToMemberIssue()
        {
            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", "MyCategory", "Breaking", "Excluded");
            context.RefineIssue("hello!", "test", "25", "error", "source", "myfile.cs", 13);

            Assert.Equal("mybinary.dll", context.Target);
            Assert.Equal("mybinary.dll", context.Module);
            Assert.Equal("mynamespace", context.Namespace);
            Assert.Equal("mytype", context.Type);
            Assert.Equal("mymember(string)", context.Member);
            Assert.Equal("CA0000", context.CheckId);
            Assert.Equal("1", context.MessageId);
            Assert.Equal("MyCategory", context.Category);
            Assert.Equal("VeryUsefulCheck", context.Typename);
            Assert.Equal("Breaking", context.FixCategory);
            Assert.Equal("hello!", context.Message);
            Assert.Equal("test", context.ResolutionName);
            Assert.Equal("25", context.Certainty);
            Assert.Equal("error", context.Level);
            Assert.Equal("source", context.Path);
            Assert.Equal("myfile.cs", context.File);
            Assert.Equal("Excluded", context.Status);
            Assert.Equal(13, context.Line.Value);

            context.ClearTarget();
            Assert.Null(context.Target);
            Assert.Null(context.Module);
            Assert.Null(context.Namespace);
            Assert.Null(context.Type);
            Assert.Null(context.Member);
            Assert.Null(context.Message);
            Assert.Null(context.ResolutionName);
        }
Пример #6
0
        public void FxCopLogReader_Context_RefineProjectToResourceIssue()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget("mybinary.dll");
            context.RefineModule("mybinary.dll");
            context.RefineResource("myresource.resx");
            context.RefineMessage("CA0000", "VeryUsefulCheck", "1", "MyCategory", "Breaking", null);

            context.RefineIssue("hello!", "test", "25", "error", "source", "myresource.resx", 13);
            Assert.AreEqual("mybinary.dll", context.Target);
            Assert.AreEqual("mybinary.dll", context.Module);
            Assert.AreEqual("myresource.resx", context.Resource);
            Assert.AreEqual("CA0000", context.CheckId);
            Assert.AreEqual("1", context.MessageId);
            Assert.AreEqual("MyCategory", context.Category);
            Assert.AreEqual("VeryUsefulCheck", context.Typename);
            Assert.AreEqual("Breaking", context.FixCategory);
            Assert.AreEqual("hello!", context.Message);
            Assert.AreEqual("test", context.Result);
            Assert.AreEqual("25", context.Certainty);
            Assert.AreEqual("error", context.Level);
            Assert.AreEqual("source", context.Path);
            Assert.AreEqual(null, context.Status);
            Assert.AreEqual("myresource.resx", context.File);
            Assert.AreEqual(13, context.Line.Value);

            context.ClearTarget();
            Assert.IsNull(context.Target);
            Assert.IsNull(context.Module);
            Assert.IsNull(context.Resource);
            Assert.IsNull(context.Namespace);
            Assert.IsNull(context.Type);
            Assert.IsNull(context.Member);
            Assert.IsNull(context.Message);
            Assert.IsNull(context.Result);
        }
Пример #7
0
        public void FxCopLogReader_Context_RefineProjectToExceptionIssue()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineException(true, "CA0001", "binary.dll#namespace#member(string)");
            context.RefineExceptionType("type");
            context.RefineExceptionMessage("message");
            context.RefineStackTrace("trace");
            context.RefineInnerExceptionType("innertype");
            context.RefineInnerExceptionMessage("innermessage");
            context.RefineInnerStackTrace("innertrace");

            string exception = FxCopLogReader.MakeExceptionMessage("Rule", "CA1000", context.ExceptionType, context.ExceptionMessage, context.StackTrace, context.InnerExceptionType, context.InnerExceptionMessage, context.InnerStackTrace);

            context.RefineIssue(exception, null, null, null, null, null, null);

            Assert.Equal("Rule CA1000 exception: type: message trace. Inner Exception: innertype: innermessage innertrace", context.Message);
            Assert.Equal("binary.dll#namespace#member(string)", context.ExceptionTarget);

            context.ClearException();
            Assert.Null(context.Target);
            Assert.Null(context.Module);
            Assert.Null(context.Namespace);
            Assert.Null(context.Type);
            Assert.Null(context.Member);
            Assert.Null(context.Message);
            Assert.Null(context.ResolutionName);

            Assert.False(context.Exception);
            Assert.Null(context.ExceptionType);
            Assert.Null(context.ExceptionMessage);
            Assert.Null(context.StackTrace);
            Assert.Null(context.InnerExceptionType);
            Assert.Null(context.InnerExceptionMessage);
            Assert.Null(context.InnerStackTrace);
        }
Пример #8
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!" })
                },
                Suppressions = new List <Suppression> {
                    new Suppression {
                        Kind = SuppressionKind.InSource
                    }
                },
                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
                            }
                        },
                        LogicalLocation = new LogicalLocation
                        {
                            FullyQualifiedName = expectedLogicalLocation,
                            Index = 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);
        }
Пример #9
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 FileLocation
                {
                    Uri = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                },
                Locations = new List <Location>
                {
                    new Location
                    {
                        PhysicalLocation = new PhysicalLocation
                        {
                            FileLocation = new FileLocation
                            {
                                Uri = new Uri("source\\myfile.cs", UriKind.RelativeOrAbsolute)
                            },
                            Region = new Region {
                                StartLine = 13
                            }
                        },
                        FullyQualifiedLogicalName = expectedLogicalLocation,
                    }
                }
            };

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

            var expectedLogicalLocations = new Dictionary <string, LogicalLocation>
            {
                {
                    "mybinary.dll", new LogicalLocation {
                        ParentKey = null, Kind = LogicalLocationKind.Module
                    }
                },
                {
                    "mybinary.dll!mynamespace",
                    new LogicalLocation {
                        ParentKey = "mybinary.dll", Name = "mynamespace", Kind = LogicalLocationKind.Namespace
                    }
                },
                {
                    "mybinary.dll!mynamespace.mytype",
                    new LogicalLocation {
                        ParentKey = "mybinary.dll!mynamespace", Name = "mytype", Kind = LogicalLocationKind.Type
                    }
                },
                {
                    "mybinary.dll!mynamespace.mytype.mymember(string)",
                    new LogicalLocation {
                        ParentKey = "mybinary.dll!mynamespace.mytype", Name = "mymember(string)", Kind = LogicalLocationKind.Member
                    }
                }
            };

            var    converter = new FxCopConverter();
            Result result    = converter.CreateResult(context);

            foreach (string key in expectedLogicalLocations.Keys)
            {
                expectedLogicalLocations[key].ValueEquals(converter.LogicalLocationsDictionary[key]).Should().BeTrue();
            }
            converter.LogicalLocationsDictionary.Count.Should().Be(expectedLogicalLocations.Count);
        }
Пример #10
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");
            context.RefineIssue("hello!", "test", "uncertain", "error", @"source", "myfile.cs", 13);

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

            var expectedResult = new Result
            {
                RuleId          = "CA0000",
                Message         = "hello!",
                ToolFingerprint = "1#test",
                Locations       = new HashSet <Location>
                {
                    new Location
                    {
                        AnalysisTarget = new PhysicalLocation
                        {
                            Uri = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                        },
                        ResultFile = new PhysicalLocation
                        {
                            Uri    = new Uri("source\\myfile.cs", UriKind.RelativeOrAbsolute),
                            Region = new Region {
                                StartLine = 13
                            }
                        },
                        FullyQualifiedLogicalName = expectedLogicalLocation,
                    }
                },
                Properties = new Dictionary <string, string>
                {
                    { "Level", "error" },
                    { "Category", "FakeCategory" },
                    { "FixCategory", "Breaking" }
                }
            };

            var expectedLogicalLocationComponents = new[]
            {
                new LogicalLocationComponent
                {
                    Name = "mybinary.dll",
                    Kind = LogicalLocationKind.Module
                },
                new LogicalLocationComponent
                {
                    Name = "mynamespace",
                    Kind = LogicalLocationKind.Namespace
                },
                new LogicalLocationComponent
                {
                    Name = "mytype",
                    Kind = LogicalLocationKind.Type
                },
                new LogicalLocationComponent
                {
                    Name = "mymember(string)",
                    Kind = LogicalLocationKind.Member
                }
            };

            var    converter = new FxCopConverter();
            Result result    = converter.CreateResult(context);

            result.Should().Be(expectedResult);

            converter.LogicalLocationsDictionary.Keys.Should().ContainSingle(expectedLogicalLocation);
            var actualLogicalLocationComponents = converter.LogicalLocationsDictionary[expectedLogicalLocation];

            actualLogicalLocationComponents.Should().Equal(expectedLogicalLocationComponents);
        }
        public void FxCopConverter_CreateIssue_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");
            context.RefineIssue("hello!", "test", "uncertain", "error", @"source", "myfile.cs", 13);

            Assert.AreEqual(new Result
            {
                RuleId          = "CA0000",
                ShortMessage    = "VeryUsefulCheck",
                FullMessage     = "hello!",
                ToolFingerprint = "1#test",
                Locations       = new[]
                {
                    new Location
                    {
                        AnalysisTarget = new[]
                        {
                            new PhysicalLocationComponent
                            {
                                Uri      = new Uri("mybinary.dll", UriKind.RelativeOrAbsolute),
                                MimeType = MimeType.Binary
                            }
                        },
                        ResultFile = new[]
                        {
                            new PhysicalLocationComponent
                            {
                                Uri      = new Uri("source\\myfile.cs", UriKind.RelativeOrAbsolute),
                                MimeType = MimeType.CSharp,
                                Region   = new Region {
                                    StartLine = 13
                                }
                            }
                        },
                        FullyQualifiedLogicalName = "mynamespace.mytype.mymember(string)",
                        LogicalLocation           = new[]
                        {
                            new LogicalLocationComponent
                            {
                                Name = "mybinary.dll",
                                Kind = LogicalLocationKind.ClrModule
                            },
                            new LogicalLocationComponent
                            {
                                Name = "mynamespace",
                                Kind = LogicalLocationKind.ClrNamespace
                            },
                            new LogicalLocationComponent
                            {
                                Name = "mytype",
                                Kind = LogicalLocationKind.ClrType
                            },
                            new LogicalLocationComponent
                            {
                                Name = "mymember(string)",
                                Kind = LogicalLocationKind.ClrFunction
                            }
                        }
                    }
                },
                Properties = new Dictionary <string, string>
                {
                    { "Level", "error" },
                    { "Category", "FakeCategory" },
                    { "FixCategory", "Breaking" }
                }
            }, FxCopConverter.CreateIssue(context));
        }