Пример #1
0
        public void InitializeControllers_TwoControllers_BothAreRegisteredAndControllerFactoryIsPrepared()
        {
            // Arrange
            var registeredControllers = new List <Type>(2);
            var initializer           = new DummyControllerContainerInitializer();

            using (new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(), new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();
                Config.RegisterSection <ProjectConfig>();
                Config.RegisterSection <ResourcesConfig>();

                initializer.RegisterControllerFactoryMock = () => ObjectFactory.Container.RegisterType <ISitefinityControllerFactory, DummyControllerFactory>();

                initializer.RegisterControllerMock = registeredControllers.Add;

                // Act
                initializer.InitializeControllersPublic(new[] { typeof(DummyController), typeof(DummyControllerContainerInitializer) });
            }

            // Assert
            Assert.IsInstanceOfType(ControllerBuilder.Current.GetControllerFactory(), typeof(DummyControllerFactory), "Controller factory was not set.");
            Assert.AreEqual(2, registeredControllers.Count, "Not all widgets were registered.");
            Assert.IsTrue(registeredControllers.Contains(typeof(DummyController)), "The first controller was not registered.");
            Assert.IsTrue(registeredControllers.Contains(typeof(DummyControllerContainerInitializer)), "The second controller was not registered.");
        }
        public void InitializeControllers_TwoControllers_BothAreRegisteredAndControllerFactoryIsPrepared()
        {
            //Arrange
            var registeredControllers = new List <Type>(2);
            var initializer           = new DummyControllerContainerInitializer();

            using (new ObjectFactoryContainerRegion())
            {
                initializer.RegisterControllerFactoryMock = () =>
                {
                    ObjectFactory.Container.RegisterType <ISitefinityControllerFactory, DummyControllerFactory>();
                };

                initializer.RegisterControllerMock = (t) =>
                {
                    registeredControllers.Add(t);
                };

                //Act
                initializer.InitializeControllersPublic(new[] { typeof(DummyController), typeof(DummyControllerContainerInitializer) });
            }

            //Assert
            Assert.IsInstanceOfType(ControllerBuilder.Current.GetControllerFactory(), typeof(DummyControllerFactory), "Controller factory was not set.");
            Assert.AreEqual(2, registeredControllers.Count, "Not all widgets were registered.");
            Assert.IsTrue(registeredControllers.Contains(typeof(DummyController)), "The first controller was not registered.");
            Assert.IsTrue(registeredControllers.Contains(typeof(DummyControllerContainerInitializer)), "The second controller was not registered.");
        }