Esempio n. 1
0
 public void Init()
 {
     request       = new StubRequest();
     response      = new StubResponse();
     services      = new StubMonoRailServices();
     engineContext = new StubEngineContext(request, response, services, null);
 }
Esempio n. 2
0
        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);
        }
		public void Init()
		{
			request = new StubRequest();
			response = new StubResponse();
			services = new StubMonoRailServices();
			engineContext = new StubEngineContext(request, response, services, null);
		}
		public virtual void Setup()
		{
			response = new StubResponse();
			var url = new UrlInfo("eleutian.com", "www", virtualDirectory, "http", 80, 
				Path.Combine(Path.Combine("Area", "Controller"), "Action"), "Area", "Controller", "Action", "rails", "");
			
			var stubEngineContext = new StubEngineContext(new StubRequest(), response, new StubMonoRailServices(), url)
			{
				Server = MockRepository.GenerateMock<IServerUtility>()
			};

			railsContext = stubEngineContext;
			serverUtility = railsContext.Server;

			argumentConversionService = MockRepository.GenerateMock<IArgumentConversionService>();

			controller = new TestController();
			controller.Contextualize(railsContext, MockRepository.GenerateStub<IControllerContext>());
			
			parameters = new Hashtable();
			
			services = MockRepository.GenerateMock<ICodeGeneratorServices>();
			services.Expect(s => s.ArgumentConversionService).Return(argumentConversionService).Repeat.Any();
			services.Expect(s => s.Controller).Return(controller).Repeat.Any();
			services.Expect(s => s.RailsContext).Return(railsContext).Repeat.Any();
			argumentConversionService.Expect(s => s.CreateParameters()).Return(parameters).Repeat.Any();
		}
Esempio n. 5
0
        public void ValidateTest()
        {
            //Act
            Quest        quest    = new FakeQuest();
            StubResponse response = new StubResponse();

            IQuestValidator <StubResponse> firstValidator = MockRepository.GenerateStrictMock <IQuestValidator <StubResponse> >();

            firstValidator.
            Expect(v => v.Validate(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Return(response);

            IQuestValidator <StubResponse> secondValidator = MockRepository.GenerateStrictMock <IQuestValidator <StubResponse> >();

            secondValidator.
            Expect(v => v.Validate(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Return(response);

            CompositeQuestValidator <StubResponse> validator = new CompositeQuestValidator <StubResponse>(new [] { firstValidator, secondValidator });

            //Arrange
            StubResponse returnedResponse = validator.Validate(quest);

            //Assert
            Assert.IsNotNull(returnedResponse);

            firstValidator.VerifyAllExpectations();
            secondValidator.VerifyAllExpectations();
        }
Esempio n. 6
0
        public virtual void Setup()
        {
            response = new StubResponse();
            var url = new UrlInfo("eleutian.com", "www", virtualDirectory, "http", 80,
                                  Path.Combine(Path.Combine("Area", "Controller"), "Action"), "Area", "Controller", "Action", "rails", "");

            var stubEngineContext = new StubEngineContext(new StubRequest(), response, new StubMonoRailServices(), url)
            {
                Server = MockRepository.GenerateMock <IServerUtility>()
            };

            railsContext  = stubEngineContext;
            serverUtility = railsContext.Server;

            argumentConversionService = MockRepository.GenerateMock <IArgumentConversionService>();

            controller = new TestController();
            controller.Contextualize(railsContext, MockRepository.GenerateStub <IControllerContext>());

            parameters = new Hashtable();

            services = MockRepository.GenerateMock <ICodeGeneratorServices>();
            services.Expect(s => s.ArgumentConversionService).Return(argumentConversionService).Repeat.Any();
            services.Expect(s => s.Controller).Return(controller).Repeat.Any();
            services.Expect(s => s.RailsContext).Return(railsContext).Repeat.Any();
            argumentConversionService.Expect(s => s.CreateParameters()).Return(parameters).Repeat.Any();
        }
Esempio n. 7
0
        public void RegisterNewCodeFiscale(string codeFiscale, int registrationId, int subRegistrationId, int labelId)
        {
            var configurableResponses = new StubResponse
            {
                Items = new[]
                {
                    new CodeFiscaleData
                    {
                        SubregistrationResponseCode          = subRegistrationId,
                        IndividualAccountOpeningResponseCode = registrationId,
                        Subregistration2ResponseCode         = subRegistrationId,
                        FiscalCode = codeFiscale
                    }
                }
            };

            var serializer = new XmlSerializer(typeof(StubResponse));
            var builder    = new StringBuilder();
            var settings   = new XmlWriterSettings {
                OmitXmlDeclaration = true
            };

            using (var stringWriter = XmlWriter.Create(builder, settings))
            {
                var ns = new XmlSerializerNamespaces();
                ns.Add(string.Empty, string.Empty);

                serializer.Serialize(stringWriter, configurableResponses, ns);
            }

            var url = string.Format(_configuration.CreateCodeFiscaleUrl, labelId);

            _requestHandler.ExecutePost(url, builder.ToString());
        }
		public void RedirectToUrlDoesNotTouchUrl()
		{
			UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
			StubResponse response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
			response.RedirectToUrl("/uol/com/folha");
			Assert.AreEqual("/uol/com/folha", response.RedirectedTo);
		}
Esempio n. 9
0
        public void RedirectToUrlDoesNotTouchUrl()
        {
            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());

            response.RedirectToUrl("/uol/com/folha");
            Assert.AreEqual("/uol/com/folha", response.RedirectedTo);
        }
Esempio n. 10
0
 protected override IMockResponse BuildResponse(UrlInfo info)
 {
     var response = new StubResponse(info,
                                     new DefaultUrlBuilder(),
                                     new StubServerUtility(),
                                     new RouteMatch(),
                                     referrer);
     return response;
 }
		public void Init()
		{
			var request = new StubRequest();
			response = new StubResponse();
			services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			engineContext = new StubEngineContext(request, response, services, null);
		}
        public void Init()
        {
            var request = new StubRequest();

            response = new StubResponse();
            services = new StubMonoRailServices();
            engStubViewEngineManager   = new StubViewEngineManager();
            services.ViewEngineManager = engStubViewEngineManager;
            engineContext = new StubEngineContext(request, response, services, null);
        }
Esempio n. 13
0
		public void RedirectToUrlWithQueryStringAsDict()
		{
			UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
			StubResponse response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
			response.RedirectToUrl("/uol/com/folha", DictHelper.Create("id=1", "name=john doe"));
			Assert.AreEqual("/uol/com/folha?id=1&name=john+doe", response.RedirectedTo);

			response.RedirectToUrl("/uol/com/folha?something=1", DictHelper.Create("id=1", "name=john doe"));
			Assert.AreEqual("/uol/com/folha?something=1&id=1&name=john+doe", response.RedirectedTo);
		}
Esempio n. 14
0
        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 ShouldThrowAnExceptionIfCantCreateAnIndex()
        {
            var response = new StubResponse(400);

            MockElasticClient.Setup(x => x.CreateIndex(It.IsAny <IndexName>(), It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), It.IsAny <string>())).Returns(response);

            var indexMaintainer = new ElasticsearchApprenticeshipIndexMaintainer(MockElasticClient.Object, Mock.Of <IElasticsearchMapper>(), Mock.Of <ILog>(), Mock.Of <IElasticsearchConfiguration>());

            Assert.Throws <ConnectionException>(() => indexMaintainer.CreateIndex("testindex"));
        }
Esempio n. 16
0
        public void RedirectToUrlWithQueryStringAsDict()
        {
            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());

            response.RedirectToUrl("/uol/com/folha", DictHelper.Create("id=1", "name=john doe"));
            Assert.AreEqual("/uol/com/folha?id=1&name=john+doe", response.RedirectedTo);

            response.RedirectToUrl("/uol/com/folha?something=1", DictHelper.Create("id=1", "name=john doe"));
            Assert.AreEqual("/uol/com/folha?something=1&id=1&name=john+doe", response.RedirectedTo);
        }
		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);
		}
Esempio n. 18
0
		public void RedirectToSiteRootUsesAppVirtualDir()
		{
			UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
			StubResponse response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
			response.RedirectToSiteRoot();
			Assert.AreEqual("/", response.RedirectedTo);

			url = new UrlInfo("area", "home", "index", "/app", ".castle");
			response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
			response.RedirectToSiteRoot();
			Assert.AreEqual("/app/", response.RedirectedTo);
		}
		public void Init()
		{
			resourceFactoryMock = mockRepository.DynamicMock<IResourceFactory>();

			StubRequest request = new StubRequest();
			StubResponse response = new StubResponse();
			services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			services.ResourceFactory = resourceFactoryMock;
			engineContext = new StubEngineContext(request, response, services, null);
		}
Esempio n. 20
0
		public void Redirect_ToControllerAction()
		{
			UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
			StubResponse response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
			response.Redirect("cart", "view");
			Assert.AreEqual("/area/cart/view.castle", response.RedirectedTo);

			url = new UrlInfo("", "home", "index", "", ".castle");
			response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
			response.Redirect("cart", "view");
			Assert.AreEqual("/cart/view.castle", response.RedirectedTo);
		}
        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);
        }
Esempio n. 22
0
        public void RedirectUsingRoute_SpecifyingParameters()
        {
            engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));

            var match = new RouteMatch();

            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, match);

            response.RedirectUsingRoute("cart", "checkout", DictHelper.Create("param1=Marge"));
            Assert.AreEqual("/something/Marge/admin/cart/checkout", response.RedirectedTo);
        }
Esempio n. 23
0
        public void RedirectToSiteRootUsesAppVirtualDir()
        {
            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());

            response.RedirectToSiteRoot();
            Assert.AreEqual("/", response.RedirectedTo);

            url      = new UrlInfo("area", "home", "index", "/app", ".castle");
            response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
            response.RedirectToSiteRoot();
            Assert.AreEqual("/app/", response.RedirectedTo);
        }
Esempio n. 24
0
        public void Redirect_ToAreaControllerAction()
        {
            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());

            response.Redirect("admin", "cart", "view");
            Assert.AreEqual("/admin/cart/view.castle", response.RedirectedTo);

            url      = new UrlInfo("", "home", "index", "", ".castle");
            response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
            response.Redirect("admin", "cart", "view");
            Assert.AreEqual("/admin/cart/view.castle", response.RedirectedTo);
        }
Esempio n. 25
0
        public void RedirectUsingRoute_InheritingParameters()
        {
            engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));

            var match = new RouteMatch();

            match.AddNamed("param1", "Homer");

            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, match);

            response.RedirectUsingRoute("cart", "checkout", true);
            Assert.AreEqual("/something/Homer/admin/cart/checkout", response.RedirectedTo);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        public void ExecutesActionAndReturnValue()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            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(1, retVal);
        }
		public void Init()
		{
			StubRequest request = new StubRequest();
			response = new StubResponse();
			StubMonoRailServices services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			engineContext = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action"));

			generator = new JQueryAjaxProxyGenerator();
			generator.ControllerTree = services.ControllerTree;
			generator.ControllerDescriptorBuilder = services.ControllerDescriptorProvider;

			services.ControllerTree.AddController("area", "controller1", typeof(NoAjaxController));
			services.ControllerTree.AddController("", "controller2", typeof(AjaxController));
		}
        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);
        }
Esempio n. 30
0
        public virtual void Setup()
        {
            _mocks    = new MockRepository();
            _services = _mocks.DynamicMock <ICodeGeneratorServices>();
            _response = new StubResponse();
            UrlInfo url =
                new UrlInfo("eleutian.com", "www", _virtualDirectory, "http", 80,
                            Path.Combine(Path.Combine("Area", "Controller"), "Action"), "Area", "Controller", "Action", "rails",
                            "");

            _railsContext =
                new StubEngineContext(new StubRequest(), _response, new StubMonoRailServices(), url);

            ((StubEngineContext)_railsContext).Server = _mocks.DynamicMock <IServerUtility>();
            _serverUtility = _railsContext.Server;

            _argumentConversionService = _mocks.DynamicMock <IArgumentConversionService>();
            _controller = new TestController();
        }
Esempio n. 31
0
        public void Init()
        {
            var request = new StubRequest();

            response = new StubResponse();
            var services = new StubMonoRailServices();

            engStubViewEngineManager   = new StubViewEngineManager();
            services.ViewEngineManager = engStubViewEngineManager;
            engineContext = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action"));

            generator = new PrototypeAjaxProxyGenerator
            {
                ControllerTree = services.ControllerTree,
                ControllerDescriptorBuilder = services.ControllerDescriptorProvider
            };

            services.ControllerTree.AddController("area", "controller1", typeof(NoAjaxController));
            services.ControllerTree.AddController("", "controller2", typeof(AjaxController));
        }
        public async Task ShouldFilterOutStandardsThatAreNotValid()
        {
            var response     = new StubResponse(400);
            var mockResponse = new Mock <IBulkResponse> {
                DefaultValue = DefaultValue.Mock
            };
            var mockSettings = new Mock <IInfrastructureSettings>();

            mockSettings.SetupGet(x => x.FrameworkIdFormat).Returns("{0}{1}{2}");
            MockElasticClient.Setup(x => x.CreateIndex(It.IsAny <IndexName>(), It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >(), It.IsAny <string>())).Returns(response);
            MockElasticClient.Setup(x => x.BulkAsync(It.IsAny <IBulkRequest>(), It.IsAny <string>())).Returns(Task.FromResult <IBulkResponse>(mockResponse.Object));

            var indexMaintainer = new ElasticsearchApprenticeshipIndexMaintainer(
                MockElasticClient.Object,
                new ElasticsearchMapper(mockSettings.Object, Mock.Of <IOrganisationTypeProcessor>()),
                Mock.Of <ILog>(),
                Mock.Of <IElasticsearchConfiguration>());

            await indexMaintainer.IndexStandards("testindex", StandardsTestData4001WithOneNull());

            MockElasticClient.Verify(x => x.BulkAsync(It.IsAny <IBulkRequest>(), It.IsAny <string>()), Times.Exactly(1));
        }
Esempio n. 33
0
		public void RedirectUsingRoute_InheritingParameters()
		{
			engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));

			RouteMatch match = new RouteMatch();
			match.AddNamed("param1", "Homer");

			UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
			StubResponse response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, match);
			response.RedirectUsingRoute("cart", "checkout", true);
			Assert.AreEqual("/something/Homer/admin/cart/checkout", response.RedirectedTo);
		}
        public void SetUp()
        {
            var en = CultureInfo.CreateSpecificCulture("en");

            Thread.CurrentThread.CurrentCulture   = en;
            Thread.CurrentThread.CurrentUICulture = en;

            Layout      = null;
            PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            Helpers     = new HelperDictionary();
            var services = new StubMonoRailServices
            {
                UrlBuilder    = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()),
                UrlTokenizer  = new DefaultUrlTokenizer(),
                CacheProvider = new StubCacheProvider()
            };

            services.AddService(typeof(ICacheProvider), services.CacheProvider);

            var urlInfo = new UrlInfo(
                "example.org", "test", "", "http", 80,
                "http://test.example.org/test_area/test_controller/test_action.tdd",
                Area, ControllerName, Action, "tdd", "no.idea");

            Response      = new StubResponse();
            EngineContext = new StubEngineContext(new StubRequest(), Response, services,
                                                  urlInfo);

            services.AddService(typeof(IEngineContext), EngineContext);
            EngineContext.AddService <IEngineContext>(EngineContext);

            EngineContext.AddService <IUrlBuilder>(services.UrlBuilder);
            EngineContext.AddService <IUrlTokenizer>(services.UrlTokenizer);
            EngineContext.AddService <ICacheProvider>(services.CacheProvider);

            ViewComponentFactory = new DefaultViewComponentFactory();
            ViewComponentFactory.Service(EngineContext);

            EngineContext.AddService <IViewComponentFactory>(ViewComponentFactory);
            services.AddService(typeof(IViewComponentFactory), ViewComponentFactory);

            EngineContext.AddService <IViewComponentDescriptorProvider>(new DefaultViewComponentDescriptorProvider());
            services.AddService(typeof(IViewComponentDescriptorProvider), EngineContext.GetService <IViewComponentDescriptorProvider>());

            ControllerContext = new ControllerContext {
                Helpers = Helpers, PropertyBag = PropertyBag
            };
            EngineContext.CurrentControllerContext = ControllerContext;

            Helpers["formhelper"]       = Helpers["form"] = new FormHelper(EngineContext);
            Helpers["urlhelper"]        = Helpers["url"] = new UrlHelper(EngineContext);
            Helpers["dicthelper"]       = Helpers["dict"] = new DictHelper(EngineContext);
            Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(EngineContext);

            var viewPath = Path.Combine(ViewSourcePath, "Views");

            var loader = new FileAssemblyViewSourceLoader(viewPath);

            services.ViewSourceLoader = loader;
            services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);
            EngineContext.AddService <IViewSourceLoader>(services.ViewSourceLoader);

            Controller = new BaseTestFixtureController();
            Controller.Contextualize(EngineContext, ControllerContext);

            VelocityViewEngine = new NVelocityViewEngine();
            services.AddService(typeof(IViewEngine), VelocityViewEngine);
            EngineContext.AddService <IViewEngine>(VelocityViewEngine);

            VelocityViewEngine.SetViewSourceLoader(loader);
            VelocityViewEngine.Service(services);

            var viewEngineManager = new DefaultViewEngineManager();

            viewEngineManager.RegisterEngineForExtesionLookup(VelocityViewEngine);
            services.EmailTemplateService = new EmailTemplateService(viewEngineManager);

            BeforEachTest();
        }
		public void SetUp()
		{
			var en = CultureInfo.CreateSpecificCulture("en");

			Thread.CurrentThread.CurrentCulture = en;
			Thread.CurrentThread.CurrentUICulture = en;

			Layout = null;
			PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
			Helpers = new HelperDictionary();
			var services = new StubMonoRailServices
			               	{
			               		UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()),
			               		UrlTokenizer = new DefaultUrlTokenizer(),
			               		CacheProvider = new StubCacheProvider()
			               	};
			services.AddService(typeof(ICacheProvider), services.CacheProvider);

			var urlInfo = new UrlInfo(
				"example.org", "test", "", "http", 80,
				"http://test.example.org/test_area/test_controller/test_action.tdd",
				Area, ControllerName, Action, "tdd", "no.idea");
			Response = new StubResponse();
			EngineContext = new StubEngineContext(new StubRequest(), Response, services,
			                                          urlInfo);

			services.AddService(typeof(IEngineContext), EngineContext);
			EngineContext.AddService<IEngineContext>(EngineContext);

			EngineContext.AddService<IUrlBuilder>(services.UrlBuilder);
			EngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer);
			EngineContext.AddService<ICacheProvider>(services.CacheProvider);

			ViewComponentFactory = new DefaultViewComponentFactory();
			ViewComponentFactory.Service(EngineContext);

			EngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
			services.AddService(typeof(IViewComponentFactory), ViewComponentFactory);

			EngineContext.AddService<IViewComponentDescriptorProvider>(new DefaultViewComponentDescriptorProvider());
			services.AddService(typeof(IViewComponentDescriptorProvider), EngineContext.GetService<IViewComponentDescriptorProvider>());

			ControllerContext = new ControllerContext { Helpers = Helpers, PropertyBag = PropertyBag };
			EngineContext.CurrentControllerContext = ControllerContext;

			Helpers["formhelper"] = Helpers["form"] = new FormHelper(EngineContext);
			Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(EngineContext);
			Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(EngineContext);
			Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(EngineContext);

			var viewPath = Path.Combine(ViewSourcePath, "Views");

			var loader = new FileAssemblyViewSourceLoader(viewPath);

			services.ViewSourceLoader = loader;
			services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);
			EngineContext.AddService<IViewSourceLoader>(services.ViewSourceLoader);

			Controller = new BaseTestFixtureController();
			Controller.Contextualize(EngineContext, ControllerContext);

			VelocityViewEngine = new NVelocityViewEngine();
			services.AddService(typeof(IViewEngine), VelocityViewEngine);
			EngineContext.AddService<IViewEngine>(VelocityViewEngine);

			VelocityViewEngine.SetViewSourceLoader(loader);
			VelocityViewEngine.Service(services);

			var viewEngineManager = new DefaultViewEngineManager();
			viewEngineManager.RegisterEngineForExtesionLookup(VelocityViewEngine);
			services.EmailTemplateService = new EmailTemplateService(viewEngineManager);

			BeforEachTest();
		}
Esempio n. 36
0
		public void RedirectUsingRoute_SpecifyingParameters()
		{
			engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));

			RouteMatch match = new RouteMatch();

			UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
			StubResponse response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, match);
			response.RedirectUsingRoute("cart", "checkout", DictHelper.Create("param1=Marge"));
			Assert.AreEqual("/something/Marge/admin/cart/checkout", response.RedirectedTo);
		}