internal void Initialize(Type cacheManagerType, Stream cachedComposition, Stream cachedCatalog)
            {
                Requires.NotNull(cacheManagerType, nameof(cacheManagerType));
                Requires.NotNull(cachedComposition, nameof(cachedComposition));
                Requires.NotNull(cachedCatalog, nameof(cachedCatalog));

                // Copy the streams to ones inside our app domain.
                Stream cachedCompositionLocal = CopyStream(cachedComposition);
                Stream cachedCatalogLocal     = CopyStream(cachedCatalog);

                // Deserialize the catalog to verify that it doesn't load any assemblies.
                var catalogManager = new CachedCatalog();

                this.catalog = catalogManager.LoadAsync(cachedCatalogLocal, TestUtilities.Resolver).Result;

                // Deserialize the composition to prepare for the rest of the test.
                var cacheManager     = (ICompositionCacheManager)Activator.CreateInstance(cacheManagerType);
                var containerFactory = cacheManager.LoadExportProviderFactoryAsync(cachedCompositionLocal, TestUtilities.Resolver).GetAwaiter().GetResult();

                this.container = containerFactory.CreateExportProvider();
            }
            internal void Compose(Stream cachedCatalog)
            {
                Requires.NotNull(cachedCatalog, nameof(cachedCatalog));

                Stream cachedCatalogLocal = CopyStream(cachedCatalog);

                // Deserialize the catalog to verify that it doesn't load any assemblies.
                var catalogManager = new CachedCatalog();

                this.catalog = catalogManager.LoadAsync(cachedCatalogLocal, TestUtilities.Resolver).Result;

                var configuration = CompositionConfiguration.Create(this.catalog);

                var cacheManager = new CachedComposition();
                var ms           = new MemoryStream();

                cacheManager.SaveAsync(configuration, ms).GetAwaiter().GetResult();
                ms.Position = 0;

                var containerFactory = cacheManager.LoadExportProviderFactoryAsync(ms, TestUtilities.Resolver).GetAwaiter().GetResult();

                this.container = containerFactory.CreateExportProvider();
            }
Example #3
0
        private static async Task RoundtripCatalogSerializationAsync(ComposableCatalog catalog, ITestOutputHelper output)
        {
            Requires.NotNull(catalog, nameof(catalog));
            Requires.NotNull(output, nameof(output));

            var catalogSerialization = new CachedCatalog();
            var ms = new MemoryStream();

            catalogSerialization.SaveAsync(catalog, ms).Wait();
            ms.Position = 0;
            var deserializedCatalog = await catalogSerialization.LoadAsync(ms, TestUtilities.Resolver);

            var before = new StringWriter();

            catalog.ToString(before);
            var after = new StringWriter();

            deserializedCatalog.ToString(after);

            PrintDiff("BeforeSerialization", "AfterSerialization", before.ToString(), after.ToString(), output);

            Assert.True(catalog.Equals(deserializedCatalog));
        }