public virtual void Init() { mocks = new MockRepository(); var services = new StubMonoRailServices(); services.ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views"); services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader); viewComponentFactory = new DefaultViewComponentFactory(); viewComponentFactory.Initialize(); services.AddService(typeof(IViewComponentFactory), viewComponentFactory); services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); var settings = new SparkSettings(); engine = new SparkViewEngine(settings); services.AddService(typeof(ISparkViewEngine), engine); factory = new SparkViewFactory(); factory.Service(services); controller = MockRepository.GenerateMock<IController>(); controllerContext = new ControllerContext(); var request = new StubRequest(); request.FilePath = ""; var response = new StubResponse(); engineContext = new StubEngineContext(request, response, new UrlInfo("", "Home", "Index", "/", "castle")); engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory); engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry); }
protected override IMockRequest BuildRequest() { StubRequest request = new StubRequest(Cookies); request.UrlReferrer = Referrer; return request; }
public void Init() { selector = new DefaultActionSelector(); var request = new StubRequest(); var response = new StubResponse(); var services = new StubMonoRailServices(); engine = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action1")); }
public void Init() { var request = new StubRequest(); var response = new StubResponse(); services = new StubMonoRailServices(); engStubViewEngineManager = new StubViewEngineManager(); services.ViewEngineManager = engStubViewEngineManager; filterFactoryMock = mockRepository.DynamicMock<IFilterFactory>(); services.FilterFactory = filterFactoryMock; engineContext = new StubEngineContext(request, response, services, null); }
public void CanGetItemByIdFromRequest() { ARFetcher fetcher = new ARFetcher(new DefaultConverter()); ParameterInfo parameter = typeof(MyController).GetMethod("MyAction").GetParameters()[0]; ARFetchAttribute attribute = (ARFetchAttribute)parameter.GetCustomAttributes(typeof(ARFetchAttribute), true)[0]; StubRequest request = new StubRequest(); request.Params["id"] = account1.Id.ToString(); Account record = (Account)fetcher.FetchActiveRecord( parameter, attribute, request, new Dictionary<string, object>()); Assert.AreEqual(account1.Id, record.Id); }
public void CanGetItemByIdFromRequest_UsingArray() { var fetcher = new ARFetcher(new DefaultConverter()); var parameter = typeof(MyController).GetMethod("MyAction2").GetParameters()[0]; var attribute = (ARFetchAttribute)parameter.GetCustomAttributes(typeof(ARFetchAttribute), true)[0]; var request = new StubRequest(); request.Params.Add("id", account1.Id.ToString()); request.Params.Add("id", account2.Id.ToString()); var records = (Account[])fetcher.FetchActiveRecord( parameter, attribute, request, new Dictionary<string, object>()); Assert.AreEqual(account1.Id, records[0].Id); Assert.AreEqual(account2.Id, records[1].Id); }
public void DelegatesToDynamicAction() { var dynAction = new ActionStub(); var executor = new DynamicActionExecutor(dynAction); var req = new StubRequest(); var res = new StubResponse(); var services = new StubMonoRailServices(); IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action")); var retVal = executor.Execute(engineContext, new DummyController(), new ControllerContext()); Assert.IsTrue(dynAction.WasExecuted); Assert.AreEqual(3, retVal); }
public void CompatibleExecutorDelegatesInvocationToControllerUsingDelegate() { var controller = new BaseController(); var actionMeta = new ActionMetaDescriptor(); ActionMethodExecutorCompatible.InvokeOnController delegateToController = controller.InvokeMethodStub; var executor = new ActionMethodExecutorCompatible(GetActionMethod(controller), actionMeta, delegateToController); var req = new StubRequest(); var res = new StubResponse(); var services = new StubMonoRailServices(); IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action")); var retVal = executor.Execute(engineContext, controller, new ControllerContext()); Assert.IsTrue(controller.WasExecuted); Assert.AreEqual(2, retVal); }
public void ExecutesActionAndReturnValue() { BaseController controller = new BaseController(); ActionMetaDescriptor actionMeta = new ActionMetaDescriptor(); ActionMethodExecutor executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta); StubRequest req = new StubRequest(); StubResponse res = new StubResponse(); StubMonoRailServices services = new StubMonoRailServices(); IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action")); object retVal = executor.Execute(engineContext, controller, new ControllerContext()); Assert.IsTrue(controller.WasExecuted); Assert.AreEqual(1, retVal); }