public async Task TestControlCacheFaultInjection(Type injectorType)
        {
            var injector    = (CompositionManager.ICachingFaultInjector)Activator.CreateInstance(injectorType);
            var caching     = GetCaching(injector);
            var composition = await CompositionManager.CreateRuntimeCompositionFromDiscovery(caching);

            var cacheManager = new CachedComposition();

            await caching.Write(composition, cacheManager);

            Assert.IsFalse(caching.CanUse());
        }
        public async Task TestCacheFileCorrupted()
        {
            var caching = GetCaching();

            await CreateAndWrite(caching);

            File.WriteAllText(caching.MefCacheFile, "corrupted");
            Assert.IsNull(await CompositionManager.TryCreateRuntimeCompositionFromCache(caching), "Cache was able to be constructed from corrupted cache");

            Assert.IsFalse(File.Exists(caching.MefCacheFile), "Cache was not deleted on corruption");
            Assert.IsFalse(File.Exists(caching.MefCacheControlFile), "Cache control was not deleted on corruption");
        }
예제 #3
0
        public async Task TestControlCacheFileStaleList()
        {
            var caching     = GetCaching();
            var composition = await CompositionManager.CreateRuntimeCompositionFromDiscovery(caching);

            var cacheManager = new CachedComposition();

            await caching.Write(composition, cacheManager);

            caching.Assemblies.Add(typeof(Console).Assembly);

            Assert.IsFalse(caching.CanUse());
        }
        public async Task TestCacheControlDataIntegrity()
        {
            var caching = GetCaching();

            var(composition, catalog) = await CompositionManager.CreateRuntimeCompositionFromDiscovery(caching);

            var inputAssemblies = catalog.GetInputAssemblies().Select(x => x.ToString()).ToArray();

            Assert.That(caching.MefAssemblies, Contains.Item(typeof(CompositionManager).Assembly));
            Assert.That(inputAssemblies, Contains.Item(typeof(CompositionManager).Assembly.GetName().ToString()));

            Assert.That(caching.MefAssemblies, Is.Not.Contains(typeof(Console).Assembly));
            Assert.That(inputAssemblies, Contains.Item(typeof(Console).Assembly.GetName().ToString()));
        }
예제 #5
0
        static CompositionManager.Caching GetCaching(CompositionManager.ICachingFaultInjector faultInjector = null, Action <string> onCacheFileRequested = null, [CallerMemberName] string testName = null)
        {
            var assemblies = CompositionManager.ReadAssembliesFromAddins();
            var caching    = new CompositionManager.Caching(assemblies, file => {
                onCacheFileRequested?.Invoke(file);

                var tmpDir = Path.Combine(Util.TmpDir, "mef", testName);
                if (Directory.Exists(tmpDir))
                {
                    Directory.Delete(tmpDir, true);
                }
                Directory.CreateDirectory(tmpDir);
                return(Path.Combine(tmpDir, file));
            }, faultInjector);

            return(caching);
        }
        public async Task ValidateRuntimeCompositionIsValid()
        {
            var mefAssemblies = CompositionManager.ReadAssembliesFromAddins();
            var caching       = new CompositionManager.Caching(mefAssemblies, file => {
                var tmpDir = Path.Combine(Util.TmpDir, "mef", nameof(ValidateRuntimeCompositionIsValid));
                if (Directory.Exists(tmpDir))
                {
                    Directory.Delete(tmpDir, true);
                }
                Directory.CreateDirectory(tmpDir);
                return(Path.Combine(tmpDir, file));
            }, exceptionHandler: new ThrowingHandler());

            var(composition, catalog) = await CompositionManager.CreateRuntimeCompositionFromDiscovery(caching);

            var cacheManager = new CachedComposition();

            await caching.Write(composition, catalog, cacheManager);
        }
예제 #7
0
        public static void AssertExportsContains <TExport, TActual> (this CompositionManager manager)
        {
            var export = manager.ExportProvider.GetExportedValues <TExport> ().Single();

            Assert.That(export, Is.TypeOf <TActual> ());
        }