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);
        }
Exemple #2
0
		private string RenderHtml(string target, string folderName)
		{
			string returnValue = null;
			var meta = new ModelMetadata();

			foreach (var template in GetTemplate(target, folderName,
												 propertyInfo =>
												 {
													 meta.DisplayName = propertyInfo.Name;
													 meta.Value = ObtainValue(RequestContext.All, target).ToString();
													 meta.Target = target;
												 }))
			{
				using (var writer = new StringWriter(CultureInfo.InvariantCulture))
				{
					var context = new ControllerContext
					{
						Helpers = ControllerContext.Helpers
					};
					context.PropertyBag["model"] = meta;
					Context.Services.ViewEngineManager.ProcessPartial(template, writer, Context, Controller, context);
					returnValue = writer.ToString();
					break;
				}
			}
			return returnValue;
		}
		public void Init()
		{
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
			Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

			_Helper = new LocalizedFormHelper();
			_Helper.ServerUtility = new MockServerUtility();

			_Controller = new MyController();
			_ControllerContext = new ControllerContext();
		}
        public virtual void SetUp()
        {

            PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            Helpers = new HelperDictionary();
            var services = new StubMonoRailServices
                               {
                                   UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine()),
                                   UrlTokenizer = new DefaultUrlTokenizer()
                               };
            var urlInfo = new UrlInfo(
                "example.org", "test", "/TestBrail", "http", 80,
                "http://test.example.org/test_area/test_controller/test_action.tdd",
                Area, ControllerName, Action, "tdd", "no.idea");
            StubEngineContext = new StubEngineContext(new StubRequest(), new StubResponse(), services, urlInfo);
            StubEngineContext.AddService<IUrlBuilder>(services.UrlBuilder);
            StubEngineContext.AddService<IUrlTokenizer>(services.UrlTokenizer);

            ViewComponentFactory = new DefaultViewComponentFactory();
            ViewComponentFactory.Service(StubEngineContext);
            ViewComponentFactory.Initialize();

            StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
            ControllerContext = new ControllerContext
                                    {
                                        Helpers = Helpers, 
                                        PropertyBag = PropertyBag
                                    };
            StubEngineContext.CurrentControllerContext = ControllerContext;


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



            var loader = new FileAssemblyViewSourceLoader("Views");
            _monoRailViewEngine = new NHamlMonoRailViewEngine();
            _monoRailViewEngine.TemplateEngine.Options.TemplateCompiler = new CSharp3TemplateCompiler();
            _monoRailViewEngine.SetViewSourceLoader(loader);
            _templateEngine = _monoRailViewEngine.TemplateEngine;
            _templateEngine.Options.TemplateBaseType = typeof( NHamlMonoRailView );
            


            ViewComponentFactory.Inspect(GetType().Assembly);

        }
 public StubController(){
     ControllerContext = new ControllerContext();
 }
 public StubAdminController(){
     ControllerContext = new ControllerContext();
     // this.Context = new 
 }
 public static ControllerContext GetControllerContext(string layoutName, IDictionary<string, object> parameters)
 {
     var controllerContext = new ControllerContext();
     if (layoutName != null)
     {
         controllerContext.LayoutNames = new[] { layoutName };
     }
     foreach (var pair in parameters)
     {
         controllerContext.PropertyBag[pair.Key] = pair.Value;
     }
     return controllerContext;
 }