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 DiffMethods() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.MethodClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.MethodClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); try { Assert.AreEqual(12, diff.Methods.RemovedCount, "Removed methods count"); Assert.AreEqual(7, diff.Methods.AddedCount, "Added methods"); } finally { if (ExceptionHelper.InException) { Console.WriteLine("Removed methods"); foreach (var method in diff.Methods.Removed) { Console.WriteLine("{0}", method.ObjectV1.Print(MethodPrintOption.Full)); } Console.WriteLine("Added methods"); foreach (var method in diff.Methods.Added) { Console.WriteLine("{0}", method.ObjectV1.Print(MethodPrintOption.Full)); } } } }
public void DiffEvents() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.EventClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.EventClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); try { Assert.AreEqual(7, diff.Events.RemovedCount, "Removed events"); Assert.AreEqual(10, diff.Events.AddedCount, "Added events"); } finally { if (ExceptionHelper.InException) { Console.WriteLine("Removed events"); foreach (var ev in diff.Events.Removed) { Console.WriteLine("{0}", ev.ObjectV1.Print()); } Console.WriteLine("Added events"); foreach (var ev in diff.Events.Added) { Console.WriteLine("{0}", ev.ObjectV1.Print()); } } } }
public void PrintVariousFields() { TypeDefinition publicClassWithManyFields = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, TestConstants.PublicClassWithManyFields); List <string> myFieldDefinitions = new List <string> { "private int privateIntField", "private List<string> privateListField", "private const int privateConstant - Value: 9", "internal readonly int internalReadOnyInt", "public static readonly int publicReadOnlyStaticint", "public static int publicStaticIntField", "public const int publicConstStaticInt - Value: 999", "protected int protectedIntField", "protected internal int protectedInternalField", "protected const int protectedstaticconstField - Value: 879", "private List<string> privateListField1", "private List<string> privateListField2", "protected static readonly int protectedstaticreadonlyField", "protected internal int protectedInternalField", "protected internal static int protectedInternalStaticField", "public static System.DateTime publicStaticDateTimeField", "protected internal const string protectedInternalConstString - Value: Test Value" }; foreach (FieldDefinition field in publicClassWithManyFields.Fields) { string fieldStr = field.Print(FieldPrintOptions.All); Console.WriteLine(fieldStr); Assert.IsTrue(myFieldDefinitions.Contains(fieldStr), String.Format("Got field string: #{0}# which is not part of required string list", fieldStr)); } }
public void DiffBaseClassAndInmplementedInterfaces() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.ClassWithInterfacesAndBaseClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.ClassWithInterfacesAndBaseClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); try { Assert.IsTrue(diff.HasChangedBaseType, "Base class type has changed"); Assert.AreEqual("EventArgs", diff.TypeV1.BaseType.Name, "Base Type V1"); Assert.AreEqual("ResolveEventArgs", diff.TypeV2.BaseType.Name, "Base Type V2"); Assert.AreEqual(2, diff.Interfaces.RemovedCount, "Removed interfaces"); Assert.AreEqual(1, diff.Interfaces.AddedCount, "Added interfaces"); } finally { if (ExceptionHelper.InException) { Console.WriteLine("Removed interfaces"); foreach (var remItf in diff.Interfaces.Removed) { Console.WriteLine("{0}", remItf.ObjectV1.FullName); } Console.WriteLine("Added interfaces"); foreach (var addItf in diff.Interfaces.Added) { Console.WriteLine("{0}", addItf.ObjectV1.FullName); } } } }
public void Can_Find_Non_Compilergenerated_Generic_Field() { UsageQueryAggregator agg = new UsageQueryAggregator( new TypeQuery("BaseLibrary.FieldQuery", "PublicClassWithManyEventsAndMethods")); TypeDefinition func = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Collections.Generic.KeyValuePair`2"); new WhoHasFieldOfType(agg, func); try { agg.Analyze(TestConstants.BaseLibV1Assembly); Assert.AreEqual(1, agg.FieldMatches.Count, "Field match count"); Assert.AreEqual("ProtectedKeyValuePairField", agg.FieldMatches[0].Match.Name, "Field Name"); } finally { if (ExceptionHelper.InException) { foreach (var res in agg.FieldMatches) { Console.WriteLine("Found field: {0}, file: {1}", res.Match.Print(FieldPrintOptions.All), res.SourceFileName); } } } }
public void Can_Find_Field_Where_Type_Is_A_Generic_Parameter() { UsageQueryAggregator agg = new UsageQueryAggregator( new TypeQuery("BaseLibrary.FieldQuery", "PublicClassWithManyEventsAndMethods")); TypeDefinition decimalType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Decimal"); new WhoHasFieldOfType(agg, decimalType); try { agg.Analyze(TestConstants.BaseLibV1Assembly); Assert.AreEqual(1, agg.FieldMatches.Count, "Field match count"); Assert.AreEqual("myDecimalField", agg.FieldMatches[0].Match.Name, "Field Name"); } finally { if (ExceptionHelper.InException) { foreach (var res in agg.FieldMatches) { Console.WriteLine("Found field: {0}, file: {1}", res.Match.Print(FieldPrintOptions.All), res.SourceFileName); } } } }
public void PrintVariousEvents() { TypeDefinition classWithManyEvents = TypeQuery.GetTypeByName( TestConstants.BaseLibV1Assembly, "BaseLibrary.EventQueries.ClassWithManyEvents"); string[] evDefinitions = new string[] { "public event Func<int> PublicEvent", "public event Func<bool> PublicEvent2", "protected event Func<int> ProtectedEvent", "internal event Func<int> InternalEvent", "private event System.Action PrivateEvent", "public virtual event Func<int> PublicVirtualEvent", "public static event System.Action PublicStaticEvent", "private event EventHandler<EventArgs> SceneChanged" }; foreach (EventDefinition ev in classWithManyEvents.Events) { string evStr = ev.Print(); Console.WriteLine("{0}", evStr); Assert.IsTrue(evDefinitions.Contains(evStr), "Event string should be part of list"); } }
public void Validate_That_Simple_Method_Calls_From_Local_Variable_Is_Found() { TypeDefinition baseClassMethod = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.ApiChanges.PublicBaseClass"); var baseMethods = MethodQuery.AllMethods.GetMethods(baseClassMethod); UsageQueryAggregator agg = new UsageQueryAggregator(); new WhoUsesMethod(agg, baseMethods); try { agg.Analyze(TestConstants.DependandLibV1Assembly); var results = agg.MethodMatches; Assert.AreEqual(8, results.Count); } finally { if (ExceptionHelper.InException) { foreach (var res in agg.MethodMatches) { Console.WriteLine("Got method call at {0} {1} {2}", res.Match.Print(MethodPrintOption.Full), res.SourceFileName, res.LineNumber); } } agg.Dispose(); } }
public void Can_Find_IDisposable_Implementer_Without_Pdb() { var iDisposable = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.IDisposable"); UsageQueryAggregator agg = new UsageQueryAggregator(); new WhoImplementsInterface(agg, iDisposable); try { agg.Analyze(TestConstants.DependandLibV1Assembly); var results = agg.TypeMatches; Assert.AreEqual(2, results.Count); } finally { if (ExceptionHelper.InException) { foreach (var typeMatch in agg.TypeMatches) { Console.WriteLine("IDisposable is implemeted by {0}: {1}", typeMatch.Match.Print(), typeMatch.SourceFileName); } } } }
public void Can_Find_Reference_Type_Instantiations() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoInstantiatesQueries", "ClassWhichInstantiatesReferenceType")); new WhoInstantiatesType(agg, TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.ApiChanges.PublicGenericClass`1")); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "Should get ctor call"); }
public void DiffBaseClassWithChangeInGenericTypeArgs() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.ClassWithGenericBase"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.ClassWithGenericBase"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); Assert.IsTrue(diff.HasChangedBaseType, "Base Type has changed generic argument"); }
public void Can_Find_Value_Type_Instantiations() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoInstantiatesQueries", "ClassWhichInstantiatesValueType")); new WhoInstantiatesType(agg, TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.DateTime")); new WhoInstantiatesType(agg, TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Threading.AsyncFlowControl")); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(3, agg.MethodMatches.Count, "Should get ctor call"); }
public void Can_Detect_Enum_Usage_In_Switch_Case() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("BaseLibrary.TypeUsageQuery", "SwitchOfEnumValues")); new WhoUsesType(agg, TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.StringSplitOptions")); agg.Analyze(TestConstants.BaseLibV1Assembly); Assert.AreEqual(2, agg.MethodMatches.Count, "method match count"); Assert.AreEqual("UsingSwitchWithEnum", agg.MethodMatches[0].Match.Name); }
public void Can_Detect_Type_Usage_In_Interface() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("BaseLibrary.TypeUsageQuery", "ITestInterface")); new WhoUsesType(agg, TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.String")); agg.Analyze(TestConstants.BaseLibV1Assembly); Assert.AreEqual(2, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual(WhoUsesType.UsedAsMethodReturnType, agg.MethodMatches[0].Annotations.Reason); Assert.AreEqual(WhoUsesType.UsedAsMethodParameterReason, agg.MethodMatches[1].Annotations.Reason); }
public void PrintVariousMethods() { TypeDefinition classWithMetods = TypeQuery.GetTypeByName( TestConstants.BaseLibV1Assembly, "BaseLibrary.Extensions.ClassWithGenericMethodArgs"); foreach (MethodDefinition method in classWithMetods.Methods) { Console.WriteLine("{0}", method.Print(MethodPrintOption.Full)); } }
public void Can_Find_TypeOfAndCast_Calls() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "CastToTypeAndTypeof")); new WhoUsesType(agg, TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.IDisposable")); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(2, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual(WhoUsesType.CastReason, agg.MethodMatches[0].Annotations.Reason); Assert.AreEqual(WhoUsesType.TypeOfReason, agg.MethodMatches[1].Annotations.Reason); }
public void Can_Find_Type_As_Field_Type() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassWithSearchedFieldType")); var charType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Char"); new WhoUsesType(agg, charType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.FieldMatches.Count, "field match count"); Assert.AreEqual("CharEvent", agg.FieldMatches[0].Match.Name); }
public void Can_Find_Type_As_Base_Interface() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassImplementsInterface")); var iDisposable = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.IDisposable"); new WhoUsesType(agg, iDisposable); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.TypeMatches.Count, "Type match count"); Assert.AreEqual("ClassImplementsInterface", agg.TypeMatches[0].Match.Name); }
public void Can_Find_Type_As_Base_Class() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassDerivesFromException")); var exType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Exception"); new WhoUsesType(agg, exType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.TypeMatches.Count, "Type match count"); Assert.AreEqual("ClassDerivesFromException", agg.TypeMatches[0].Match.Name); }
public void Can_Find_GenericParameters_Of_Base_Type() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassWhichDerivesFromGenericBaseClass")); var decimalType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Decimal"); new WhoUsesType(agg, decimalType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.TypeMatches.Count, "Type match count"); Assert.AreEqual("DependantLibV1.WhoUsesTypeInSignature.ClassWhichDerivesFromGenericBaseClass", agg.TypeMatches[0].Match.FullName); }
public void DiffWithItselfMustReturnEmptyDiff() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.ClassWithGenericBase"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV1, myQueries); Assert.IsFalse(diff.HasChangedBaseType, "Base Type has changed generic argument"); Assert.AreEqual(0, diff.Events.Count); Assert.AreEqual(0, diff.Fields.Count); Assert.AreEqual(0, diff.Interfaces.Count); Assert.AreEqual(0, diff.Methods.Count); }
public void CanFindTypesThatDeriveFromGenericBaseClasses() { var genList = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Collections.Generic.List`1"); UsageQueryAggregator agg = new UsageQueryAggregator(); new WhoDerivesFromType(agg, genList); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(2, agg.TypeMatches.Count); }
public void Can_Find_Genericparameters_Of_Base_Interface() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("BaseLibrary.ApiChanges", "IGenericInteface")); var floatType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Single"); new WhoUsesType(agg, floatType); agg.Analyze(TestConstants.BaseLibV1Assembly); Assert.AreEqual(3, agg.TypeMatches.Count, "Type match count"); Assert.AreEqual("BaseLibrary.ApiChanges.IGenericInteface", agg.TypeMatches[0].Match.FullName); }
public void Can_Find_Type_In_Method_Argument_List_Used_As_Generic_Parameter() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassWithFunctionWithGenericArguments")); var byteType = TypeQuery.GetTypeByName(TestConstants.DependandLibV1Assembly, "DependantLibV1.WhoUsesTypeInSignature.StructWithFunctionWithSearchedParameter"); new WhoUsesType(agg, byteType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "method match count"); Assert.AreEqual("FuncWithGenricMethodArgs", agg.MethodMatches[0].Match.Name); }
public void Can_Find_Type_In_Method_Argument_List() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "StructWithFunctionWithSearchedParameter")); var byteType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Byte"); new WhoUsesType(agg, byteType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "method match count"); Assert.AreEqual("FuncWithByteParamter", agg.MethodMatches[0].Match.Name); }
public void Can_Find_GenericMethodInvocations_With_Type_Parameters() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "UsageClass")); var decimalType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.Decimal"); new WhoUsesType(agg, decimalType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(2, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual("UseGenericMethod", agg.MethodMatches[0].Match.Name); Assert.AreEqual("UseGenericMethod", agg.MethodMatches[1].Match.Name); }
public void Can_Find_Type_In_Constrained_Calls() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassWithUsingStatement")); var byteType = TypeQuery.GetTypeByName(TestConstants.MscorlibAssembly, "System.IDisposable"); new WhoUsesType(agg, byteType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(2, agg.MethodMatches.Count, "method match count"); Assert.AreEqual("FunctionWithUsingStatement", agg.MethodMatches[0].Match.Name); Assert.AreEqual("UsingDisposeableStruct", agg.MethodMatches[1].Match.Name); }
public void Can_Find_All_Subscribers_To_Static_And_Instance_Events() { TypeDefinition type = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.ApiChanges.PublicBaseClass"); List <EventDefinition> evs = new EventQuery().GetMatchingEvents(type); Assert.AreEqual(2, evs.Count, "Class has events defined"); UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.MethodUsage")); new WhoUsesEvents(agg, evs); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(3, agg.MethodMatches.Count); }
public void Can_Find_Type_In_Method_Return_Type_In_Interface() { UsageQueryAggregator agg = new UsageQueryAggregator(new TypeQuery("DependantLibV1.WhoUsesTypeInSignature", "ClassWithGenericTypeArguments")); var dateTimeType = TypeQuery.GetTypeByName( TestConstants.MscorlibAssembly, "System.DateTime"); new WhoUsesType(agg, dateTimeType); agg.Analyze(TestConstants.DependandLibV1Assembly); Assert.AreEqual(1, agg.MethodMatches.Count, "Method match count"); Assert.AreEqual("public virtual IEnumerator<DateTime> GetEnumerator()", agg.MethodMatches[0].Match.Print(MethodPrintOption.Full)); }