Esempio n. 1
0
 public static HttpContextBase DynamicHttpContextBase()
 {
     var mocks = new MockRepository();
     var context = mocks.DynamicHttpContextBase();
     mocks.ReplayAll();
     return context;
 }
        public void Handler_should_match_route()
        {
            var handler = new DebugHttpHandler();
            var mocks = new MockRepository();
            var context = mocks.DynamicHttpContextBase();

            SetupResult.For(context.Request.AppRelativeCurrentExecutionFilePath).Return("~/Home/");
            SetupResult.For(context.Request.PathInfo).Return("Index");

            var routes = new RouteCollection
                             {
                                 new Route("{controller}/{action}/{id}", null, new MvcRouteHandler()),
                                 new Route("{controller}/{action}", null, new MvcRouteHandler()),
                                 new Route("{controller}/{action}", new RouteValueDictionary(new Hash(Controller => "Home")),
                                           new MvcRouteHandler())
                             };
            RouteDebugger.RewriteRoutesForTesting(routes);

            mocks.ReplayAll();
            var routeData = new RouteData(routes[0], new DebugRouteHandler());
            routeData.Values.Add("Controller", "Home");
            routeData.Values.Add("Action", "Index");

            handler.RequestContext = new RequestContext(context, routeData);
            handler.ProcessRequest(context, routes);

            Assert.That(context.Response.Output.ToString().Contains("<tr><td>Controller</td><td>Home&nbsp;</td></tr>"));
        }
        public void DebugRouteHandler_should_create_DebugHttpHandler()
        {
            var mocks = new MockRepository();
            var handler = new DebugRouteHandler();
            var context = new RequestContext(mocks.DynamicHttpContextBase(), new RouteData());

            var httpHandler = handler.GetHttpHandler(context);
            Assert.That(httpHandler, Is.InstanceOf<DebugHttpHandler>());
            Assert.That(((DebugHttpHandler)httpHandler).RequestContext, Is.SameAs(context));
        }
        public void ControllerSetsViewEngine()
        {
            MockRepository mocks = new MockRepository();
            RequestContext context = new RequestContext(mocks.DynamicHttpContextBase(), new RouteData());

            SparkControllerFactory controllerFactory = new SparkControllerFactory();
            MvcContrib.ConventionController controller =
                (MvcContrib.ConventionController)((IControllerFactory)controllerFactory).CreateController(context, "Convention");

            Assert.IsNotNull(controller.ViewEngine);
            Assert.IsAssignableFrom(typeof(SparkViewFactory), controller.ViewEngine);
        }
        public void Setup()
        {
            _container = new WindsorContainer();
            _factory = new WindsorControllerFactory(_container);

            _container.AddComponent("simplecontroller", typeof(WindsorSimpleController));
            _container.AddComponent("StubDependency", typeof(IDependency), typeof(StubDependency));
            _container.AddComponent("dependencycontroller", typeof(WindsorDependencyController));

            _factory.InitializeWithControllerTypes(typeof(WindsorSimpleController), typeof(WindsorDependencyController));

            var mocks = new MockRepository();
            _context = new RequestContext(mocks.DynamicHttpContextBase(), new RouteData());
            mocks.ReplayAll();
        }
Esempio n. 6
0
		public void Setup()
		{
			_mocks = new MockRepository();
			_context = _mocks.DynamicHttpContextBase();
			SetupResult.For(_context.Request.FilePath).Return("Test.mvc");
		    var view = _mocks.DynamicMock<IView>();
			_viewContext = new ViewContext(new ControllerContext(_context, new RouteData(), _mocks.DynamicMock<ControllerBase>()), view, new ViewDataDictionary(), new TempDataDictionary());
			_helper = new HtmlHelper(_viewContext, new ViewPage());
			_people = new List<Person>
			              	{
			              		new Person { Id = 1, Name = "Jeremy", DateOfBirth = new DateTime(1987, 4, 19)}
			              	};
			AddToViewData("people", _people);
			_mocks.ReplayAll();

		}
Esempio n. 7
0
        public virtual void SetUp()
        {
            HttpMethodToReturn = "GET";
            EcmaScriptVersionToReturn = new Version(1, 1);

            mockRepository = new MockRepository();
            HttpContext = mockRepository.DynamicHttpContextBase();
            SetupResult.For(Request.UserHostAddress).Return("::1");
            SetupResult.For(Request.UserHostName).Return("::1");
            SetupResult.For(Request.RequestType).Do(new Func<string>(() => HttpMethodToReturn)); //.Return("GET");
            SetupResult.For(Request.HttpMethod).Do(new Func<string>(() => HttpMethodToReturn));
            SetupResult.For(Request.PhysicalApplicationPath).Return("http://testing/mycontroller/test");
            SetupResult.For(Request.Url).Return(new Uri("http://testing/mycontroller/test"));
            mockRepository.Replay(Request);
            SetupResult.For(Request.Browser.EcmaScriptVersion).Do(new Func<Version>(() => EcmaScriptVersionToReturn));
            SetupResult.For(Request.Browser.Browser).Return("Firefox 2.0.11");
            SetupResult.For(HttpContext.User.Identity).Return(new MockIdentity {Name = string.Empty});
            mockRepository.ReplayAll();
        }
 public void SetUp()
 {
     _mocks = new MockRepository();
     _controllerContext = new ControllerContext(_mocks.DynamicHttpContextBase(), new RouteData(), _mocks.DynamicMock<ControllerBase>());
     _mocks.ReplayAll();
 }
Esempio n. 9
0
        private void SetupHtmlHelper(object model , Dictionary<string,object> viewData)
        {
            _mocks = new MockRepository();
            _context = _mocks.DynamicHttpContextBase();
            SetupResult.For(_context.Request.FilePath).Return("Test.mvc");
            var view = _mocks.DynamicMock<IView>();
            _viewContext = new ViewContext(new ControllerContext(_context, new RouteData(), _mocks.DynamicMock<ControllerBase>()), view, new ViewDataDictionary(), new TempDataDictionary(), new StringWriter());
            _helper = new HtmlHelper(_viewContext, new ViewPage());

            if (model != null)
            {
                _viewContext.ViewData.Model = model;
            }
            if (viewData!=null)
            {
                foreach(string key in viewData.Keys)
                {
                    _viewContext.ViewData.Add(key, viewData[key]);
                }

            }

            _mocks.ReplayAll();
        }
        public void Handler_should_not_match_route()
        {
            var handler = new DebugHttpHandler();
            var mocks = new MockRepository();
            var context = mocks.DynamicHttpContextBase();

            SetupResult.For(context.Request.AppRelativeCurrentExecutionFilePath).Return("~/");
            SetupResult.For(context.Request.PathInfo).Return(string.Empty);

            var routes = new RouteCollection();
            RouteDebugger.RewriteRoutesForTesting(routes);

            mocks.ReplayAll();

            var routeData = new RouteData(DebugRoute.Singleton, new DebugRouteHandler());

            handler.RequestContext = new RequestContext(context, routeData);
            handler.ProcessRequest(context, routes);

            Assert.That(context.Response.Output.ToString().Contains("<strong class=\"false\">NO MATCH!</strong>"));
        }
 public void Initialize()
 {
     _mocks = new MockRepository();
     _context = _mocks.DynamicHttpContextBase();
     _mocks.ReplayAll();
 }