Пример #1
0
        public static void ResolverMultipleCalls()
        {
            var resolver = new ResolverReturnsSomething();

            using (MetadataLoadContext lc = new MetadataLoadContext(resolver))
            {
                Assembly derived = lc.LoadFromByteArray(TestData.s_DerivedClassWithVariationsOnFooImage);

                int expectedCount = 2; // Includes the initial probe for mscorelib
                foreach (string typeName in new string[] { "Derived1", "Derived3", "Derived4", "Derived5", "Derived6" })
                {
                    Type t  = derived.GetType(typeName, throwOnError: true);
                    Type bt = t.BaseType;
                    Assert.Equal(bt.Assembly, resolver.Assembly);
                    Assert.Equal(expectedCount++, resolver.CallCount);
                }
            }
        }
Пример #2
0
        public static void ResolverReturnsSomething()
        {
            var resolver = new ResolverReturnsSomething();

            using (MetadataLoadContext lc = new MetadataLoadContext(resolver))
            {
                Assert.Same(lc, resolver.Context);
                Assert.Equal(1, resolver.CallCount);

                Assembly derived = lc.LoadFromByteArray(TestData.s_DerivedClassWithVariationsOnFooImage);
                Type     t       = derived.GetType("Derived1", throwOnError: true);
                Type     bt      = t.BaseType;

                Assert.Same(lc, resolver.Context);
                Assert.Equal("Foo", resolver.AssemblyName.Name);
                Assert.Equal(2, resolver.CallCount);

                Assembly a = bt.Assembly;
                Assert.Equal(a, resolver.Assembly);
            }
        }