コード例 #1
0
        public void Menu_Returns_The_Correct_Current_Menu_Option()
        {
            //Arrange
            HomeController controller = new HomeController();
            
            ControllerContext context = new ControllerContext();
            ViewContext parentView = new ViewContext();

            //Set the parent's view routeData
            parentView.RouteData.Values["controller"] = "Customer";
            parentView.RouteData.Values["action"] = "Index";

            context.RouteData.DataTokens["ParentActionViewContext"] = parentView;

            //Set the context for the controller.
            controller.ControllerContext = context;

            //Act
            ViewResult result = controller.Menu() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
            MenuStateViewModel model = result.ViewData.Model as MenuStateViewModel;
            Assert.IsNotNull(model);
            Assert.IsTrue(model.IsCurrentAction("CustomerList"));
        }
コード例 #2
0
        public void Index_Returns_Welcome_Message()
        {
            //Arrange.
            HomeController controller = new HomeController();

            //Act
            ViewResult result = controller.Index() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
コード例 #3
0
 public void Get_Controller_Instance_Throws_Null_Reference_Exception_When_The_Controller_Type_Is_Null()
 {
     //Arrange
     SIContainer serviceFactory = new SIContainer();
     HomeController controller = new HomeController();
     serviceFactory.ResolveType = x => controller;
     
     
     IoCControllerFactory controllerFactory = new IoCControllerFactory(serviceFactory);
     
     MDefaultControllerFactory baseMole = new MDefaultControllerFactory(controllerFactory);
     
     IoCControllerFactory_Accessor factoryAccessor = new IoCControllerFactory_Accessor(new PrivateObject(controllerFactory));
     baseMole.CreateControllerRequestContextString = (context, name) => factoryAccessor.GetControllerInstance(context, null);
     
     //Act
     HomeController resolvedController = controllerFactory.CreateController(null, "Home") as HomeController;
 }
コード例 #4
0
        public void Get_Controller_Instance_Returns_The_Right_Controller()
        {
            //Arrange
            SIContainer container = new SIContainer();
            
            HomeController controller = new HomeController();
            
            container.ResolveType = x =>controller;
            
            IoCControllerFactory controllerFactory = new IoCControllerFactory(container);
            
            MDefaultControllerFactory baseMole = new MDefaultControllerFactory(controllerFactory);
            //Create a MSTest accessor to access GetControllerInstance

            IoCControllerFactory_Accessor factoryAccessor = new IoCControllerFactory_Accessor(new PrivateObject(controllerFactory));
            
            baseMole.CreateControllerRequestContextString = (context, name) => factoryAccessor.GetControllerInstance(context,typeof(HomeController));
            
            //Act
            HomeController resolvedController = controllerFactory.CreateController(null, "Home") as HomeController;

            //Assert
            Assert.AreSame(controller, resolvedController);
        }