Exemplo n.º 1
0
 static void TestTypeByNameWithNoInvalidAssembly(ITestIsolationContext context)
 {
     context.AssemblyLoad("HarmonyTestsDummyAssemblyC");
     Assert.NotNull(AccessTools.TypeByName(typeof(Harmony).FullName));
     Assert.NotNull(AccessTools.TypeByName(typeof(Test_AccessTools).FullName));
     Assert.Null(AccessTools.TypeByName("HarmonyTestsDummyAssemblyA.Class1"));
     Assert.Null(AccessTools.TypeByName("HarmonyTestsDummyAssemblyB.Class1"));
     Assert.Null(AccessTools.TypeByName("HarmonyTestsDummyAssemblyB.Class2"));
     Assert.NotNull(AccessTools.TypeByName("HarmonyTestsDummyAssemblyC.Class1"));
     Assert.Null(AccessTools.TypeByName("IAmALittleTeaPot.ShortAndStout"));
 }
Exemplo n.º 2
0
 static void TestTypeByNameWithInvalidAssembly(ITestIsolationContext context)
 {
     // HarmonyTestsDummyAssemblyB has a dependency on HarmonyTestsDummyAssemblyA, but we've ensured that
     // HarmonyTestsDummyAssemblyA.dll is NOT available (i.e. not in HarmonyTests output dir).
     context.AssemblyLoad("HarmonyTestsDummyAssemblyB");
     context.AssemblyLoad("HarmonyTestsDummyAssemblyC");
     // Even if 0Harmony.dll isn't loaded yet and thus would be automatically loaded after the invalid assemblies,
     // TypeByName tries Type.GetType first, which always works for a type in the executing assembly (0Harmony.dll).
     Assert.NotNull(AccessTools.TypeByName(typeof(Harmony).FullName));
     // The current executing assembly (HarmonyTests.dll) was definitely already loaded before above loads.
     Assert.NotNull(AccessTools.TypeByName(typeof(Test_AccessTools).FullName));
     // HarmonyTestsDummyAssemblyA is explicitly missing, so it's the same as the unknown type case - see below.
     Assert.Null(AccessTools.TypeByName("HarmonyTestsDummyAssemblyA.Class1"));
     // HarmonyTestsDummyAssemblyB.GetTypes() should throw ReflectionTypeLoadException due to missing HarmonyTestsDummyAssemblyA,
     // but this is caught and returns successfully loaded types.
     // HarmonyTestsDummyAssemblyB.Class1 depends on HarmonyTestsDummyAssemblyA, so it's not loaded successfully.
     Assert.Null(AccessTools.TypeByName("HarmonyTestsDummyAssemblyB.Class1"));
     // HarmonyTestsDummyAssemblyB.Class2 doesn't depend on HarmonyTestsDummyAssemblyA, so it's loaded successfully.
     Assert.NotNull(AccessTools.TypeByName("HarmonyTestsDummyAssemblyB.Class2"));
     // TypeByName's search should find HarmonyTestsDummyAssemblyB before HarmonyTestsDummyAssemblyC, but this is fine.
     Assert.NotNull(AccessTools.TypeByName("HarmonyTestsDummyAssemblyC.Class1"));
     // TypeByName's search for an unknown type should always find HarmonyTestsDummyAssemblyB first, which is again fine.
     Assert.Null(AccessTools.TypeByName("IAmALittleTeaPot.ShortAndStout"));
 }