示例#1
0
            public TestBase(int numContexts)
            {
                _contexts       = new ResourceAssemblyLoadContext[numContexts];
                _testClassTypes = new Type[numContexts];

                _checker = new CollectibleChecker(numContexts);
            }
示例#2
0
        private static WeakReference <AssemblyLoadContext> CreateCollectible(CollectibleChecker checker)
        {
            var expectedContext = new ResourceAssemblyLoadContext(true);

            checker.SetAssemblyLoadContext(0, expectedContext);
            return(new WeakReference <AssemblyLoadContext>(expectedContext));
        }
示例#3
0
        public static void Unload_CollectibleWithNoAssemblyLoaded()
        {
            // Use a collectible ALC + Unload
            // Check that we receive the Unloading event

            var checker = new CollectibleChecker(1);

            CreateAndLoadContext(checker);
            checker.GcAndCheck();
        }
示例#4
0
        static void CreateAndLoadContext(CollectibleChecker checker)
        {
            var alc = new ResourceAssemblyLoadContext(true);

            checker.SetAssemblyLoadContext(0, alc);

            alc.Unload();

            // Check that any attempt to load an assembly after an explicit Unload will fail
            Assert.Throws <InvalidOperationException>(() => alc.LoadFromAssemblyPath(Path.GetFullPath("none.dll")));
        }
示例#5
0
        public static void Finalizer_CollectibleWithNoAssemblyLoaded()
        {
            // Use a collectible ALC, let the finalizer call Unload
            // Check that we receive the Unloading event

            var checker = new CollectibleChecker(1);
            // Create the ALC in another method to allow the finalizer to run
            WeakReference <AssemblyLoadContext> weakRef = CreateCollectible(checker);

            checker.GcAndCheck();

            // Check that the ALC was also released
            AssemblyLoadContext alc;

            Assert.False(weakRef.TryGetTarget(out alc));
        }