コード例 #1
0
            internal void TestWithCache(Stream cacheStream, string substitutedAssemblyPath, int oldMetadataToken)
            {
                var resolver = new Resolver(new CustomAssemblyLoader(substitutedAssemblyPath));
                var exportProviderFactory = this.cacheManager.LoadExportProviderFactoryAsync(cacheStream, resolver).GetAwaiter().GetResult();
                var exportProvider = exportProviderFactory.CreateExportProvider();

                // Avoid using GetExportedValue<T> since the default load context will still pick up the original assembly,
                // and the cast will fail.
                var importDefinition = new ImportDefinition(
                    typeof(DiscoverablePart1).FullName,
                    ImportCardinality.ExactlyOne,
                    ImmutableDictionary<string, object>.Empty,
                    ImmutableList<IImportSatisfiabilityConstraint>.Empty);
                var export = exportProvider.GetExports(importDefinition).Single();
                AssertEx.NotNull(export.Value);
                AssertEx.Equal(typeof(DiscoverablePart1).FullName, export.Value.GetType().FullName);

                // Validate that we loaded the substituted assembly and that the metadata token is different (to assert we're testing something useful)
                AssertEx.Equal(substitutedAssemblyPath, export.Value.GetType().Assembly.Location);
                AssertEx.NotEqual(oldMetadataToken, GetMetadataTokenForDefaultCtor(export.Value));
            }