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());
        }
Exemplo n.º 2
0
        public void RegisterAMappingThatAlreadyExistsThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
        }
Exemplo n.º 3
0
        public void ShouldGetMappingForDerivedTypesThanTheRegisteredOnes()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter);
            var returnedAdapter = regionAdapterMappings.GetMapping(typeof(ItemsControlDescendant));

            Assert.IsNotNull(returnedAdapter);
            Assert.AreSame(regionAdapter, returnedAdapter);
        }
Exemplo n.º 4
0
        public void ShouldGetRegisteredMapping()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            Type registeredType = typeof(ItemsControl);
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(registeredType, regionAdapter);
            var returnedAdapter = regionAdapterMappings.GetMapping(registeredType);

            Assert.IsNotNull(returnedAdapter);
            Assert.AreSame(regionAdapter, returnedAdapter);
        }
Exemplo n.º 5
0
        public void ShouldGetTheMostSpecializedMapping()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var genericAdapter = new MockRegionAdapter();
            var specializedAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), genericAdapter);
            regionAdapterMappings.RegisterMapping(typeof(ItemsControlDescendant), specializedAdapter);
            var returnedAdapter = regionAdapterMappings.GetMapping(typeof(ItemsControlDescendant));

            Assert.IsNotNull(returnedAdapter);
            Assert.AreSame(specializedAdapter, returnedAdapter);
        }
        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            ConfigureRegionAdapterMappingsCalled = true;
            var regionAdapterMappings = base.ConfigureRegionAdapterMappings();

            DefaultRegionAdapterMappings = regionAdapterMappings;

            return regionAdapterMappings;
        }
Exemplo n.º 7
0
        public void ShouldAttachNewRegionByUsingRegisteredRegionAdapterMappings()
        {
            var mappings = new RegionAdapterMappings();
            var mockRegionAdapter = new MockRegionAdapter();
            mappings.RegisterMapping(typeof(DependencyObject), mockRegionAdapter);
            var regionManager = new RegionManager(mappings);
            var control = new ContentControl();

            regionManager.AttachNewRegion(control, "TestRegionName");

            Assert.IsTrue(mockRegionAdapter.InitializeCalled);
            Assert.AreEqual(control, mockRegionAdapter.InitializeArgument);
        }
Exemplo n.º 8
0
        public void RegionGetsRemovedFromRegionManagerWhenRemovedFromScope()
        {
            var mappings = new RegionAdapterMappings();
            mappings.RegisterMapping(typeof(DependencyObject), new MockRegionAdapter());

            RegionManager regionManager = new RegionManager(mappings);
            var regionScopeControl = new ContentControl();
            RegionManager.SetRegionManager(regionScopeControl, regionManager);
            var control = new ItemsControl();
            control.SetValue(RegionManager.RegionNameProperty, "TestRegion");
            regionScopeControl.Content = control;
            Assert.IsTrue(regionManager.Regions.ContainsKey("TestRegion"));

            regionScopeControl.Content = null;

            Assert.IsFalse(regionManager.Regions.ContainsKey("TestRegion"));
        }
        public void RegionGetsAddedInRegionManagerWhenAddedIntoAScope()
        {
            var mappings = new RegionAdapterMappings();
            mappings.RegisterMapping(typeof(DependencyObject), new MockRegionAdapter());

            RegionManager regionManager = new RegionManager(mappings);
            var regionScopeControl = new ContentControl();
            RegionManager.SetRegionManager(regionScopeControl, regionManager);

            var control = new FrameworkElement();
            control.SetValue(RegionManager.RegionNameProperty, "TestRegion");

            Assert.IsFalse(regionManager.Regions.ContainsKey("TestRegion"));
            regionScopeControl.Content = control;
            Assert.IsTrue(regionManager.Regions.ContainsKey("TestRegion"));
            Assert.IsNotNull(regionManager.Regions["TestRegion"]);
        }
Exemplo n.º 10
0
        public void NullControlThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();
            var regionAdapter = new MockRegionAdapter();

            regionAdapterMappings.RegisterMapping(null, regionAdapter);
        }
Exemplo n.º 11
0
 public void GetMappingOfUnregisteredTypeThrows()
 {
     var regionAdapterMappings = new RegionAdapterMappings();
     regionAdapterMappings.GetMapping(typeof(object));
 }
Exemplo n.º 12
0
        public void NullAdapterThrows()
        {
            var regionAdapterMappings = new RegionAdapterMappings();

            regionAdapterMappings.RegisterMapping(typeof(ItemsControl), null);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of <see cref="RegionManager"/>.
 /// </summary>
 /// <param name="mappings">The <see cref="RegionAdapterMappings"/> that
 /// will be used when calling <see cref="AttachNewRegion"/> explicitly
 /// or by creating regions by using attached properties through XAML.
 /// </param>
 public RegionManager(RegionAdapterMappings mappings)
     : this()
 {
     this.regionAdapterMappings = mappings;
 }