Exemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Initialize the IOC container and some of the default services
            var container = new WindsorContainer();
            container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));
            container.Register(Component.For<IWindsorContainer>().Instance(container));
            container.Register(Component.For<ILog>().ImplementedBy<DwightsLog>());
            container.Register(Component.For<IDispatcher>().Instance(new WpfDispatcher(Dispatcher)));
            container.Register(Component.For<ShellWindow>().LifeStyle.Transient);
            container.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>().LifeStyle.Singleton);
            container.Register(Component.For<IRegionManager>().ImplementedBy<RegionManager>().LifeStyle.Singleton);
            container.Register(Component.For<IApplicationResourcesManager>().ImplementedBy<ApplicationResourcesManager>().LifeStyle.Singleton);

            // Setup the region adapter mappings
            var regionMappings = new RegionAdapterMappings();
            regionMappings.RegisterMapping(typeof(ContentControl), new ContentControlRegionAdapter());
            regionMappings.RegisterMapping(typeof(ItemsControl), new ItemsControlRegionAdapter());
            container.Register(Component.For<RegionAdapterMappings>().Instance(regionMappings));

            // Setup the main window
            MainWindow = container.Resolve<ShellWindow>();
            MainWindow.Show();

            // Define the modules to load
            var modules = new StaticModuleEnumerator()
                .AddModule(typeof(SearchModule))
                .AddModule(typeof(AdvertisingModule))
                .AddModule(typeof(AdventureWorksSearchModule));
            
            // Load the modules
            var moduleLoader = new ModuleLoader(new WindsorContainerAdapter(container), new TraceLogger());
            moduleLoader.Initialize(modules.GetModules());
        }
        public void GetModuleReturnsModuleInfoForModule()
        {
            var enumerator = new StaticModuleEnumerator();
            enumerator.AddModule(typeof(MockModule));
            enumerator.AddModule(typeof(AnotherModule));

            var module = enumerator.GetModule(typeof(MockModule).Name);
            Assert.AreEqual(typeof(MockModule).FullName, module.ModuleType);
        }
        public void CanPassDependantModules()
        {
            var enumerator = new StaticModuleEnumerator();
            enumerator.AddModule(typeof(MockModule), "DependentModule");

            var modules = enumerator.GetModules();
            Assert.IsNotNull(modules[0].DependsOn);
            Assert.AreEqual(1, modules[0].DependsOn.Count);
            Assert.AreEqual("DependentModule", modules[0].DependsOn[0]);
        }
        public void CanAddModuleToEnumerator()
        {
            var enumerator = new StaticModuleEnumerator();
            enumerator.AddModule(typeof(MockModule));

            var modules = enumerator.GetModules();
            Assert.AreEqual(1, modules.Length);
            Assert.AreEqual(typeof(MockModule).Name, modules[0].ModuleName);
            Assert.AreEqual(typeof(MockModule).FullName, modules[0].ModuleType);
            Assert.AreEqual(typeof(MockModule).Assembly.Location, modules[0].AssemblyFile);
        }
        public void GetStartupModulesReturnsAllModules()
        {
            var enumerator = new StaticModuleEnumerator();
            enumerator.AddModule(typeof(MockModule));
            enumerator.AddModule(typeof(AnotherModule));

            var startupModules = enumerator.GetStartupLoadedModules();
            Assert.AreEqual(2, startupModules.Length);

            var allModules = enumerator.GetModules();
            Assert.AreSame(allModules[0], startupModules[0]);
        }
        public void TestGetModuleStatusInformationWithoutLoadedModules()
        {
            StaticModuleEnumerator moduleEnumerator = new StaticModuleEnumerator();
            IUnityContainer container = new UnityContainer();

            moduleEnumerator.AddModule(typeof(ModuleMock));

            // Register the loopback construction used by compositewpf and
            // inject the unity extension for module tracking
            container.RegisterInstance<IUnityContainer>(container);
            container.AddNewExtension<ModuleTrackingUnityExtension>();

            container.RegisterInstance<IModuleCatalog>(moduleEnumerator);
            container.RegisterInstance<IModuleStatusService>(container.Resolve<ModuleStatusService>());

            ReadOnlyCollection<ModuleStatusInfo> modules = container.Resolve<IModuleStatusService>().GetModules();

            Assert.IsNotNull(modules);
            Assert.AreEqual(1, modules.Count);
            Assert.AreEqual(ModuleStatus.Unloaded, modules[0].Status);
        }
        public void FluentInterfaceShouldReturnTheSameInstance()
        {
            var enumerator = new StaticModuleEnumerator();

            Assert.AreSame(enumerator, enumerator.AddModule(typeof(MockModule)));
        }