public void Get_All_Non_Public_Methods() { MethodQuery query = new MethodQuery("!public * *( * )"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(19, matches.Count, "Non public methods"); }
public void Can_Get_Constructor_By_Name() { MethodQuery query = new MethodQuery("* ClassWithManyMethods()"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(1, matches.Count, "Should be able to get default ctor"); }
public void Get_Generic_Method_Fails_If_ParameterCount_Is_Different() { MethodQuery query = new MethodQuery("public Func<int> GenericMethod<T>(T a)"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(0, matches.Count); }
public void Get_Method_By_Name() { MethodQuery query = new MethodQuery("* * ProtectedVoid1( * )"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(1, matches.Count); }
public void Can_Differentiate_Methods_With_GenericParameters() { TypeDefinition baseClassMethod = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.ApiChanges.PublicBaseClass"); var baseMethods = new MethodQuery("public void DoSomeThing(System.Collections.Generic.List<int> l)").GetMethods(baseClassMethod); Assert.AreEqual(1, baseMethods.Count, "Should get only one method with generic parameter"); UsageQueryAggregator agg = new UsageQueryAggregator(); new WhoUsesMethod(agg, baseMethods); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(2, agg.MethodMatches.Count, "Method match count"); HashSet <string> methods = new HashSet <string>(from m in agg.MethodMatches select m.Match.Print(MethodPrintOption.Full)); Assert.IsTrue(methods.Contains("public void CallGenericIntFunc(PublicBaseClass cl)")); var methodWithFloatAsGenericParam = new MethodQuery("public void DoSomeThing(System.Collections.Generic.List<float> l)").GetMethods(baseClassMethod); Assert.AreEqual(1, methodWithFloatAsGenericParam.Count, "Did not find long function"); agg.Dispose(); agg = new UsageQueryAggregator(); new WhoUsesMethod(agg, methodWithFloatAsGenericParam); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual("public void CallGenericFloatFunc(PublicBaseClass cl)", agg.MethodMatches[0].Match.Print(MethodPrintOption.Full)); }
public void Get_All_PublicNonVirtual_Methods() { MethodQuery query = new MethodQuery("public !virtual * *( * )"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(6, matches.Count, "All Public, Non Virtual methods"); }
public void Get_Internal_Static_Void_Methods() { MethodQuery query = new MethodQuery("internal static void *()"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(2, matches.Count); Assert.AreEqual("InternalStaticVoid1", matches[0].Name); }
public void Get_Method_With_GenericReturnType_With_Partial_TypeNames() { MethodQuery query = new MethodQuery("IList<Exception> MethodWithGenericReturnType()"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(1, matches.Count); Assert.AreEqual("MethodWithGenericReturnType", matches[0].Name); }
public void Get_Method_With_GenericArgument_With_Partial_TypeNames() { MethodQuery query = new MethodQuery("void DisposeToolsHandlers(IList<Exception> exceptions_in_out)"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(1, matches.Count); Assert.AreEqual("DisposeToolsHandlers", matches[0].Name); }
public void Get_Method_With_ArgumentArray_And_Return_Type() { MethodQuery query = new MethodQuery("string GetString(byte[] bytes)"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(1, matches.Count); Assert.AreEqual("GetString", matches[0].Name); }
public void Query_For_Public_Methods() { MethodQuery query = new MethodQuery("public * *( * )"); // match all public methods"); Assert.AreEqual("*", query.NameFilter, "Name filter is none"); Assert.AreEqual(".*", query.ReturnTypeFilter.ToString(), "Return filter is none"); Assert.IsNull(query.ArgumentFilters, "Argument filter is none"); }
public void Get_Private_Static_Void1() { MethodQuery query = new MethodQuery(" private static void *( ) "); var matches = query.GetMethods(myTestClass); Assert.AreEqual(2, matches.Count); Assert.AreEqual("PrivateStaticVoid1", matches[0].Name); }
public void Get_Protected_Void_Methods() { MethodQuery query = new MethodQuery("protected void *()"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(4, matches.Count); Assert.AreEqual("ProtectedVoid1", matches[0].Name); }
public void Get_Generic_Method() { MethodQuery query = new MethodQuery("public Func<int> GenericMethod<T>(T a, int b)"); var matches = query.GetMethods(myTestClass); Assert.AreEqual(1, matches.Count); Assert.AreEqual("GenericMethod", matches[0].Name); }
public void Get_ProtectedInternalVirtual_Void_Methods() { MethodQuery query = new MethodQuery("protected internal virtual void *() "); var matches = query.GetMethods(myTestClass); Assert.AreEqual(2, matches.Count); Assert.AreEqual("ProtectedInteralVirtualVoid1", matches[0].Name); }
public void Query_For_Protected_Methods() { // match all protected methods with one parameter MethodQuery query = new MethodQuery("protected * *(* a)"); Assert.AreEqual("*", query.NameFilter, "NameFilter"); Assert.AreEqual(".*", query.ReturnTypeFilter.ToString(), "ReturnTypeFilter"); Assert.AreEqual(1, query.ArgumentFilters.Count, "Argument filter"); Assert.AreEqual(".*", query.ArgumentFilters[0].Key.ToString(), "Argument type filter"); Assert.AreEqual("*a", query.ArgumentFilters[0].Value, "Argument name filter"); }
public void Parse_Args_With_No_Generics() { var match = new MethodQuery("void Func( int a, System.Int32 b, string c)"); Assert.AreEqual(3, match.ArgumentFilters.Count); Assert.IsTrue(match.ArgumentFilters[0].Key.IsMatch("xxxSystem.Int32")); Assert.AreEqual("*a", match.ArgumentFilters[0].Value); Assert.IsTrue(match.ArgumentFilters[1].Key.IsMatch("System.Int32")); Assert.AreEqual("*b", match.ArgumentFilters[1].Value); Assert.IsTrue(match.ArgumentFilters[2].Key.IsMatch("System.String")); Assert.AreEqual("*c", match.ArgumentFilters[2].Value); }
public void Parse_Args_With_Spaces() { MethodQuery query = new MethodQuery("void Function( int a , short b, string c )"); Assert.AreEqual(3, query.ArgumentFilters.Count, "Argument Filters"); Assert.IsTrue(query.ArgumentFilters[0].Key.IsMatch("System.Int32")); Assert.AreEqual("*a", query.ArgumentFilters[0].Value); Assert.IsTrue(query.ArgumentFilters[1].Key.IsMatch("xxxSystem.Int16")); Assert.AreEqual("*b", query.ArgumentFilters[1].Value); Assert.IsTrue(query.ArgumentFilters[2].Key.IsMatch("System.String")); Assert.AreEqual("*c", query.ArgumentFilters[2].Value); }
public void Parse_Args_With_Nested_Generics() { MethodQuery query = new MethodQuery("void Func<int>(Func<int> a, Func<Func<int , bool > , byte > b, Func<int,Func<int,int>> c )"); Assert.AreEqual(3, query.ArgumentFilters.Count, "Argument Filters"); Assert.IsTrue(query.ArgumentFilters[0].Key.IsMatch("Func`1<System.Int32>")); Assert.AreEqual("*a", query.ArgumentFilters[0].Value); Assert.IsTrue(query.ArgumentFilters[1].Key.IsMatch("*.Func`2<.*Func`2<.*System.Int32,.*System.Boolean>,.*System.Byte>")); Assert.AreEqual("*b", query.ArgumentFilters[1].Value); Assert.IsTrue(query.ArgumentFilters[2].Key.IsMatch(".*Func`2<.*System.Int32,Func`2<.*System.Int32,.*System.Int32>>")); Assert.AreEqual("*c", query.ArgumentFilters[2].Value); Assert.AreEqual("Func", query.NameFilter); }
public void Parse_Args_With_Arrays() { MethodQuery query = new MethodQuery("int [] Function( int [] a , short []b, string [][] c )"); Assert.AreEqual(3, query.ArgumentFilters.Count, "Argument Filters"); Assert.IsTrue(query.ArgumentFilters[0].Key.IsMatch(".*System.Int32[]")); Assert.AreEqual("*a", query.ArgumentFilters[0].Value); Assert.IsTrue(query.ArgumentFilters[1].Key.IsMatch(".*System.Int16[]")); Assert.AreEqual("*b", query.ArgumentFilters[1].Value); Assert.IsTrue(query.ArgumentFilters[2].Key.IsMatch(".*System.String[][]")); Assert.AreEqual("*c", query.ArgumentFilters[2].Value); Assert.AreEqual(".*int\\[]", query.ReturnTypeFilter.ToString()); }
public override bool ExtractAndValidateTypeQuery(string query) { bool lret = base.ExtractAndValidateTypeQuery(query); if (lret == false) { Out.WriteLine("The Type/Method query must be of the form <TypeName>( [modifier] <returnType> <methodName>(<parameters>))"); } else { myMethodQuery = new MethodQuery(base.myInnerQuery); } return(lret); }
public void Can_Find_Method_With_Out_Parameters() { TypeDefinition publicBaseClassType = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.ApiChanges.PublicBaseClass"); MethodDefinition method = new MethodQuery("public bool CheckForUpdates(*)").GetSingleMethod(publicBaseClassType); using (UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.MethodUsage", "ClassWhichUsesMethods"))) { new WhoUsesMethod(agg, new List <MethodDefinition> { method }); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count); Assert.AreEqual("CallCheckForUpdates", agg.MethodMatches[0].Match.Name); } }
public void Can_Find_Method_With_Generic_ReturnType_And_Generic_Arguments() { TypeDefinition baseClassMethod = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.ApiChanges.PublicGenericClass`1"); var baseMethods = new MethodQuery("public Func<U> GenericFunction<U, V>(U arg1, V arg2)").GetMethods(baseClassMethod); Assert.AreEqual(1, baseMethods.Count, "Should get only one method with generic parameter"); UsageQueryAggregator agg = new UsageQueryAggregator(); new WhoUsesMethod(agg, baseMethods); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual("public void CallGenericFuncWithGenericReturnType()", agg.MethodMatches[0].Match.Print(MethodPrintOption.Full)); agg.Dispose(); }
public void Can_Find_Method_Of_NonGeneric_Nested_Type() { TypeDefinition baseClassMethod = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.MethodQueries.NestedNonGenericClass/NestedInnerNonGenericClass/NestedInnerInnerNonGenericClass"); var baseMethods = new MethodQuery("* MethodOfInnerMostNonGenericClass(*)").GetMethods(baseClassMethod); Assert.AreEqual(1, baseMethods.Count, "Should get only one method from nested class"); UsageQueryAggregator agg = new UsageQueryAggregator( new TypeQuery("DependantLibV1.MethodUsage", "ClassWhichUsesNonGenericNestedClass")); new WhoUsesMethod(agg, baseMethods); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual("private void UsingMethod()", agg.MethodMatches[0].Match.Print(MethodPrintOption.Full)); agg.Dispose(); }
public void Invalid_MethodQuery() { var query = new MethodQuery("blahh"); }
public void Invalid_Missing_Return_Type_Throws() { var query = new MethodQuery("Func()"); }