Esempio n. 1
0
        public void Throw_When_Empty_Stirng_IsPassed()
        {
            UsageQueryAggregator agg = new UsageQueryAggregator();

            agg.AddVisitScope("test");
            Assert.Throws <ArgumentException>(() => new WhoUsesStringConstant(agg, ""));
        }
Esempio n. 2
0
        public void Cannot_Find_Word_If_Casing_Is_Different()
        {
            UsageQueryAggregator agg = new UsageQueryAggregator();

            agg.AddVisitScope(TestConstants.BaseLibV1);
            new WhoUsesStringConstant(agg, "GLOBAL A STRING", true, StringComparison.Ordinal);
            agg.Analyze(TestConstants.DependandLibV1Assembly);
            Assert.AreEqual(0, agg.MethodMatches.Count);
        }
Esempio n. 3
0
        public void Can_Find_Word_Case_InsenstiveSensitive()
        {
            UsageQueryAggregator agg = new UsageQueryAggregator();

            agg.AddVisitScope(TestConstants.BaseLibV1);
            new WhoUsesStringConstant(agg, "GLOBAL A STRING", true, StringComparison.OrdinalIgnoreCase);
            agg.Analyze(TestConstants.DependandLibV1Assembly);
            Assert.AreEqual(2, agg.MethodMatches.Count);
        }
Esempio n. 4
0
        public void Can_Find_Substring()
        {
            UsageQueryAggregator agg = new UsageQueryAggregator();

            agg.AddVisitScope(TestConstants.BaseLibV1);
            new WhoUsesStringConstant(agg, "Global A");
            agg.Analyze(TestConstants.DependandLibV1Assembly);
            Assert.AreEqual(3, agg.MethodMatches.Count);
            Assert.AreEqual(1, agg.FieldMatches.Count);
        }
Esempio n. 5
0
        public override void Execute()
        {
            base.Execute();
            if (!IsValid)
            {
                Help();
                return;
            }

            Writer.SetCurrentSheet(mySearchHeader);
            Writer.PrintRow("{0,-60}", null, myParsedArgs.StringConstant);

            List <string> searchScope = myParsedArgs.Queries1.GetFiles().ToList();

            Writer.SetCurrentSheet(myResultHeader);
            base.LoadAssemblies(myParsedArgs.Queries2, (assembly, file) =>
            {
                using (UsageQueryAggregator agg = new UsageQueryAggregator(myParsedArgs.SymbolServer))
                {
                    new WhoUsesStringConstant(agg,
                                              myParsedArgs.StringConstant,
                                              myParsedArgs.WordMatch,
                                              myParsedArgs.CaseSensitiveMatch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);

                    if (searchScope.Count == 0)
                    {
                        // Force aggregator to search inside all files if no definig assemblies have been passsed.
                        agg.AddVisitScope(file);
                    }
                    else
                    {
                        searchScope.ForEach((dll) => agg.AddVisitScope(dll));
                    }

                    agg.Analyze(assembly);
                    foreach (var result in agg.MethodMatches)
                    {
                        Writer.PrintRow("{0,-60};{1,-100}; {2}; {3}; {4}; {5}; {6}; {7}",
                                        () => GetFileInfoWhenEnabled(result.SourceFileName),
                                        result.Match.DeclaringType.FullName,
                                        result.Match.Print(MethodPrintOption.Full),
                                        "",
                                        result.Annotations["String"],
                                        result.Annotations.Item,
                                        Path.GetFileName(file),
                                        result.SourceFileName,
                                        result.LineNumber
                                        );
                    }

                    foreach (var result in agg.FieldMatches)
                    {
                        Writer.PrintRow("{0,-60};{1,-100}; {2}; {3}; {4}; {5}; {6}; {7}",
                                        () => GetFileInfoWhenEnabled(result.SourceFileName),
                                        result.Match.DeclaringType.FullName,
                                        "",
                                        result.Match.Print(FieldPrintOptions.Modifiers | FieldPrintOptions.SimpleType | FieldPrintOptions.Visibility),
                                        result.Annotations["String"],
                                        result.Annotations.Item,
                                        Path.GetFileName(file),
                                        result.SourceFileName,
                                        ""
                                        );
                    }
                }
            });
        }