public async Task TestStartupShutdown() { // Especially for testing SetEntryAssembly(GetType().Assembly); using (IApplicationBootstrapper bootstrapper = new ApplicationBootstrapper(ApplicationName)) { // Add all file starting with Dapplo and ending on .dll or .dll.gz bootstrapper.FindAndLoadAssemblies("Dapplo*"); var iniConfig = new IniConfig(ApplicationName, ApplicationName); // Fix startup issues due to unloaded configuration await iniConfig.LoadIfNeededAsync(); bootstrapper.ExportProviders.Add(new ServiceProviderExportProvider(iniConfig, bootstrapper)); // Add test project, without having a direct reference #if DEBUG bootstrapper.AddScanDirectory(@"..\..\..\Dapplo.Addons.TestAddon\bin\Debug"); #else bootstrapper.AddScanDirectory(@"..\..\..\Dapplo.Addons.TestAddon\bin\Release"); #endif bootstrapper.FindAndLoadAssembly("Dapplo.Addons.TestAddon"); // Test if our test addon was loaded Assert.True(bootstrapper.KnownFiles.Count(addon => addon.EndsWith("TestAddon.dll")) > 0); // Initialize, so we can export Assert.True(await bootstrapper.InitializeAsync().ConfigureAwait(false), "Not initialized"); // test Export, this should work before Run as some of the addons might need some stuff. var part = bootstrapper.Export(this); // Start the composition, and IStartupActions Assert.True(await bootstrapper.RunAsync().ConfigureAwait(false), "Couldn't run"); // test import Assert.NotNull(bootstrapper.GetExport<ApplicationBootstrapperTests>().Value); // test release bootstrapper.Release(part); Assert.False(bootstrapper.GetExports<ApplicationBootstrapperTests>().Any()); // Test localization of a test addon, with the type specified. This is possible due to Export[typeof(SomeAddon)] Assert.True(bootstrapper.GetExports<IStartupAction>().Count() == 2); // Test localization of a IStartupAction with meta-data, which is exported via [StartupAction(DoNotAwait = true)] var hasAwaitStartFalse = bootstrapper.GetExports<IStartupAction, IStartupActionMetadata>().Any(x => x.Metadata.AwaitStart == false); Assert.True(hasAwaitStartFalse); } // Dispose automatically calls IShutdownActions }