Inheritance: IDependencyResolver
Example #1
0
        public void CanResolveHomeController()
        {
            //Arrange
            var windsorContainer = new WindsorContainer();
            windsorContainer.Configure();
            var resolver = new WindsorDependencyResolver(new WindsorIoCContainer(windsorContainer));
            DependencyResolver.SetResolver(resolver);
            IControllerActivator controllerActivator = new StandardControllerActivator();

            //Act
            IController controller = controllerActivator.Create(null, typeof (HomeController));

            //Assert
            Assert.IsNotNull(controller);
        }
Example #2
0
        public void CanReturnAnInstanceOfRequestedTypeWhenThatTypeIsRegistered()
        {
            //Arrange
            var container = MockRepository.GenerateMock<IWindsorContainer>();
            var kernel = MockRepository.GenerateMock<IKernel>();
            kernel.Expect(x => x.HasComponent(typeof (HomeController))).Return(true);
            container.Expect(x => x.Resolve(typeof (HomeController))).Return(new HomeController());
            container.Expect(x => x.Kernel).Return(kernel);
            IDependencyResolver resolver = new WindsorDependencyResolver(new WindsorIoCContainer(container));

            //Act
            object item = resolver.GetService(typeof (HomeController));

            //Assert
            Assert.IsNotNull(item);
        }
Example #3
0
        public void ShouldCallContainerForResolution()
        {
            //Arrange
            var container = MockRepository.GenerateMock<IWindsorContainer>();
            var kernel = MockRepository.GenerateMock<IKernel>();
            kernel.Expect(x => x.HasComponent(typeof (HomeController))).Return(true);
            container.Expect(x => x.Kernel).Return(kernel);
            IDependencyResolver resolver = new WindsorDependencyResolver(new WindsorIoCContainer(container));

            //Act
            object item = resolver.GetService(typeof (HomeController));

            //Assert
            container.AssertWasCalled(x => x.Resolve(typeof (HomeController)));
        }
Example #4
0
 private static void SetupIoC()
 {
     var container = new WindsorIoCContainer(new WindsorContainer().Configure());
     var resolver = new WindsorDependencyResolver(container);
     DependencyResolver.SetResolver(resolver);
 }