public async Task TestArgumentNull() { var compositionBootstrapper = new CompositionBootstrapper(); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.Add((Assembly) null)); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.Add((AssemblyCatalog) null)); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.FindAndLoadAssembly(null)); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.Add((Type) null)); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.Add((ExportProvider) null)); await compositionBootstrapper.InitializeAsync().ConfigureAwait(false); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.Export<string>(null)); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.Release(null)); Assert.Throws<ArgumentNullException>(() => compositionBootstrapper.FillImports(null)); compositionBootstrapper.Dispose(); }
public void TestNotInitialized() { var compositionBootstrapper = new CompositionBootstrapper(); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.Export("Hello")); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetExport<string>()); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetExport<string, IStartupActionMetadata>()); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetExport(typeof(string))); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetService(typeof(string))); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetExports(typeof(string))); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetExports<string>()); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.GetExports<string, IStartupActionMetadata>()); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.Release(null)); Assert.Throws<InvalidOperationException>(() => compositionBootstrapper.FillImports(null)); compositionBootstrapper.Dispose(); }
public async Task TestExportRelease() { using (var compositionBootstrapper = new CompositionBootstrapper()) { await compositionBootstrapper.InitializeAsync().ConfigureAwait(false); // Create a string export with "Hello" var export = compositionBootstrapper.Export("Hello"); // Make sure it's there Assert.Equal("Hello", compositionBootstrapper.GetExport(typeof(string))); // Remove it compositionBootstrapper.Release(export); // Create a string export with "World" compositionBootstrapper.Export("World"); // Make sure it's there Assert.Equal("World", compositionBootstrapper.GetExport(typeof(string))); } }