Example #1
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 SetUp()
		{
			string siteRoot = GetSiteRoot();
			string viewPath = Path.Combine(siteRoot, "RenderingTests\\Views");
			Layout = null;
			PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
			Helpers = new HelperDictionary();
			StubMonoRailServices services = new StubMonoRailServices();
			services.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), new StubRoutingEngine());
			services.UrlTokenizer = new DefaultUrlTokenizer();
			UrlInfo 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);
			StubEngineContext.AddService<IViewComponentFactory>(ViewComponentFactory);
			StubEngineContext.AddService<ILoggerFactory>(new ConsoleFactory());
			StubEngineContext.AddService<IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath));
			

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

			ControllerContext = new ControllerContext();
			ControllerContext.Helpers = Helpers;
			ControllerContext.PropertyBag = PropertyBag;
			StubEngineContext.CurrentControllerContext = ControllerContext;


			Helpers["urlhelper"] = Helpers["url"] = new UrlHelper(StubEngineContext);
			Helpers["htmlhelper"] = Helpers["html"] = new HtmlHelper(StubEngineContext);
			Helpers["dicthelper"] = Helpers["dict"] = new DictHelper(StubEngineContext);
			Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(StubEngineContext);


			//FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath);
//			loader.AddAssemblySource(
//				new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
//									   "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));

			viewEngine = new AspViewEngine();
			viewEngine.Service(StubEngineContext);
			AspViewEngineOptions options = new AspViewEngineOptions();
			options.CompilerOptions.AutoRecompilation = true;
			options.CompilerOptions.KeepTemporarySourceFiles = false;
			ICompilationContext context = 
				new CompilationContext(
					new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory),
					new DirectoryInfo(siteRoot),
					new DirectoryInfo(Path.Combine(siteRoot, "RenderingTests\\Views")),
					new DirectoryInfo(siteRoot));

			List<ICompilationContext> compilationContexts = new List<ICompilationContext>();
			compilationContexts.Add(context);
			viewEngine.Initialize(compilationContexts, options);
		}
Example #3
0
        public void Init()
        {
            mocks = new MockRepository();

            MockServices services = new MockServices();

            services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

            viewComponentFactory = new DefaultViewComponentFactory();
            viewComponentFactory.Initialize();
            services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            controller        = mocks.DynamicMock <IController>();
            engineContext     = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle"));
            controllerContext = new ControllerContext();

            factory = new SparkViewFactory();
            factory.Service(services);

            engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            manager = new DefaultViewEngineManager();
            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }
Example #4
0
        public void InitializeProperties()
        {
            var viewComponentFactory = new DefaultViewComponentFactory();

            viewComponentFactory.Service(context);
            context.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engine.Options.ViewProperties = ViewPropertiesInclusionOptions.QueryString;
            controllerContext.LayoutNames = new[] { "PrimaryLayout", "SecondaryLayout" };

            AddCompilation("MainView", typeof(MainView));
            AddCompilation("Layouts_PrimaryLayout", typeof(PrimaryLayout));
            AddCompilation("Layouts_SecondaryLayout", typeof(SecondaryLayout));
            AddCompilation("SecondaryView", typeof(SecondaryView));
            AddCompilation("TrenaryView", typeof(TrenaryView));

            FillPropertyBag(300, context.Request.Params);
            FillPropertyBag(4, context.Request.QueryString);
            FillPropertyBag(40, controllerContext.PropertyBag);

            var outputString = new StringBuilder();
            var stopWatch    = Stopwatch.StartNew();

            for (var i = 0; i < 20; ++i)
            {
                engine.Process("MainView", new StringWriter(outputString), context, controller, controllerContext);
            }
            stopWatch.Stop();

            var elapsed = stopWatch.ElapsedMilliseconds;

            Console.WriteLine(elapsed / 20);
        }
Example #5
0
        public void ComplexScoping()
        {
            var viewComponentFactory = new DefaultViewComponentFactory();

            viewComponentFactory.Service(context);
            context.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engine.Options.ViewProperties = ViewPropertiesInclusionOptions.QueryString;
            controllerContext.LayoutNames = new[] { "PrimaryLayout", "SecondaryLayout" };

            AddCompilation("MainView", typeof(MainView));
            AddCompilation("Layouts_PrimaryLayout", typeof(PrimaryLayout));
            AddCompilation("Layouts_SecondaryLayout", typeof(SecondaryLayout));
            AddCompilation("SecondaryView", typeof(SecondaryView));
            AddCompilation("TrenaryView", typeof(TrenaryView));

            var outputString = new StringBuilder();

            for (var i = 1; i <= 6; ++i)
            {
                controllerContext.PropertyBag["key" + i] = "val" + i + "_C_1";
            }
            controllerContext.PropertyBag["val"] = 1;

            engine.Process("MainView", new StringWriter(outputString), context, controller, controllerContext);


            expected =
                @"Primary layout start
Top capture:TrenaryView3SecondaryView2TrenaryView3SecondaryView2MainView1
Secondary layout start
Main view start
MainView       Keys=[val1_C_1,val2_C_1,val3_C_1,val4_C_1,val5_C_1,val6_C_1]
Secondary view start
SecondaryView  Keys=[val1_S_1,val2_C_1,val3_C_1,val4_S_1,val5_S_1,val6_C_1]
Trenary view start
TrenaryView    Keys=[val1_T_1,val2_T_1,val3_C_1,val4_S_1,val5_T_1,val6_C_1,val7_T_1]
Trenary view end
SecondaryView  Keys=[val1_S_1,val2_C_1,val3_C_1,val4_S_1,val5_S_1,val6_C_1]
MainView       Keys=[val1_C_1,val2_C_1,val3_C_1,val4_C_1,val5_C_1,val6_C_1]
Secondary view start
SecondaryView  Keys=[val1_S_2,val2_C_1,val3_C_1,val4_S_2,val5_S_2,val6_C_1]
Trenary view start
TrenaryView    Keys=[val1_T_1,val2_T_1,val3_C_1,val4_S_2,val5_T_1,val6_C_1,val7_T_1]
Trenary view end
SecondaryView  Keys=[val1_S_2,val2_C_1,val3_C_1,val4_S_2,val5_S_2,val6_C_1]
MainView       Keys=[val1_C_1,val2_C_1,val3_C_1,val4_C_1,val5_C_1,val6_C_1]
Main view end

Secondary layout end

Bottom capture:MainView1SecondaryView2TrenaryView3SecondaryView2TrenaryView3
Primary layout end
";

            Assert.That(outputString.ToString(), Is.EqualTo(expected));
        }
Example #6
0
        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 void ReleaseViewComponent_CallsDispose_OnTheInstance()
    {
        // Arrange
        var context = new ViewComponentContext
        {
        };

        var component = new ActivablePropertiesViewComponent();

        var viewComponentActivator = new Mock <IViewComponentActivator>();

        viewComponentActivator.Setup(vca => vca.Release(context, component))
        .Callback <ViewComponentContext, object>((c, o) => (o as IDisposable)?.Dispose());

        var factory = new DefaultViewComponentFactory(viewComponentActivator.Object);

        // Act
        factory.ReleaseViewComponent(context, component);

        // Assert
        Assert.True(component.Disposed);
    }
    public async Task ReleaseViewComponentAsync_CallsDisposeAsync_OnAsyncDisposableComponents()
    {
        // Arrange
        var context = new ViewComponentContext
        {
        };

        var component = new AsyncDisposableViewComponent();

        var viewComponentActivator = new Mock <IViewComponentActivator>();

        viewComponentActivator.Setup(vca => vca.ReleaseAsync(context, component))
        .Callback <ViewComponentContext, object>((c, o) => (o as IAsyncDisposable)?.DisposeAsync())
        .Returns(default(ValueTask));

        var factory = new DefaultViewComponentFactory(viewComponentActivator.Object);

        // Act
        await factory.ReleaseViewComponentAsync(context, component);

        // Assert
        Assert.True(component.Disposed);
    }
        public void CreateViewComponent_ActivatesProperties_OnTheInstance()
        {
            // Arrange
            var context = new ViewComponentContext
            {
            };

            var component = new ActivablePropertiesViewComponent();
            var activator = new Mock<IViewComponentActivator>();
            activator.Setup(a => a.Create(context))
                .Returns(component);

            var factory = new DefaultViewComponentFactory(activator.Object);

            // Act
            var result = factory.CreateViewComponent(context);

            // Assert
            var activablePropertiesComponent = Assert.IsType<ActivablePropertiesViewComponent>(result);

            Assert.Same(component, activablePropertiesComponent);
            Assert.Same(component.Context, activablePropertiesComponent.Context);
        }
    public void CreateViewComponent_ActivatesProperties_OnTheInstance()
    {
        // Arrange
        var context = new ViewComponentContext
        {
        };

        var component = new ActivablePropertiesViewComponent();
        var activator = new Mock <IViewComponentActivator>();

        activator.Setup(a => a.Create(context))
        .Returns(component);

        var factory = new DefaultViewComponentFactory(activator.Object);

        // Act
        var result = factory.CreateViewComponent(context);

        // Assert
        var activablePropertiesComponent = Assert.IsType <ActivablePropertiesViewComponent>(result);

        Assert.Same(component, activablePropertiesComponent);
        Assert.Same(component.Context, activablePropertiesComponent.Context);
    }
        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();
		}
        public void ReleaseViewComponent_CallsDispose_OnTheInstance()
        {
            // Arrange
            var context = new ViewComponentContext
            {
            };

            var component = new ActivablePropertiesViewComponent();

            var viewComponentActivator = new Mock<IViewComponentActivator>();
            viewComponentActivator.Setup(vca => vca.Release(context, component))
                .Callback<ViewComponentContext, object>((c, o) => (o as IDisposable)?.Dispose());

            var factory = new DefaultViewComponentFactory(viewComponentActivator.Object);

            // Act
            factory.ReleaseViewComponent(context, component);

            // Assert
            Assert.Equal(true, component.Disposed);
        }
        public void SetUp()
        {
            var siteRoot = GetSiteRoot();
            var viewPath = Path.Combine(siteRoot, "RenderingTests\\Views");

            Layout      = null;
            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);
            StubEngineContext.AddService <IViewComponentFactory>(ViewComponentFactory);
            StubEngineContext.AddService <ILoggerFactory>(new ConsoleFactory());
            StubEngineContext.AddService <IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath));


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

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


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


            //FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath);
//			loader.AddAssemblySource(
//				new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
//									   "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));

            viewEngine = new AspViewEngine();
            var options = new AspViewEngineOptions();

            options.CompilerOptions.AutoRecompilation        = true;
            options.CompilerOptions.KeepTemporarySourceFiles = false;
            ((IAspViewEngineTestAccess)viewEngine).SetOptions(options);
            ICompilationContext context =
                new CompilationContext(
                    new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory),
                    new DirectoryInfo(siteRoot),
                    new DirectoryInfo(Path.Combine(siteRoot, "RenderingTests\\Views")),
                    new DirectoryInfo(siteRoot));

            var compilationContexts = new List <ICompilationContext> {
                context
            };

            ((IAspViewEngineTestAccess)viewEngine).SetCompilationContext(compilationContexts);
            viewEngine.Service(StubEngineContext);
        }
Example #15
0
        public void SetUp()
        {
            Layout      = null;
            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);

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


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

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

            var loader = new FileAssemblyViewSourceLoader(viewPath);

            loader.AddAssemblySource(
                new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
                                       "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));

            BooViewEngine = new BooViewEngine
            {
                Options = new BooViewEngineOptions
                {
                    SaveDirectory = Environment.CurrentDirectory,
                    SaveToDisk    = false,
                    Debug         = true,
                    BatchCompile  = false
                }
            };

            BooViewEngine.SetViewSourceLoader(loader);
            BooViewEngine.Initialize();

            BeforEachTest();
        }
Example #16
0
        public void SetUp()
        {
            string viewPath = Path.Combine(SiteRoot, "Views");

            Layout      = null;
            PropertyBag = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            Helpers     = new HelperDictionary();
            MockServices services = new MockServices();

            services.UrlBuilder   = new DefaultUrlBuilder(new MockServerUtility(), new MockRoutingEngine());
            services.UrlTokenizer = new DefaultUrlTokenizer();
            UrlInfo 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");

            MockEngineContext = new MockEngineContext(new MockRequest(), new MockResponse(), services,
                                                      urlInfo);
            MockEngineContext.AddService <IUrlBuilder>(services.UrlBuilder);
            MockEngineContext.AddService <IUrlTokenizer>(services.UrlTokenizer);
            MockEngineContext.AddService <IViewComponentFactory>(ViewComponentFactory);
            MockEngineContext.AddService <ILoggerFactory>(new ConsoleFactory());
            MockEngineContext.AddService <IViewSourceLoader>(new FileAssemblyViewSourceLoader(viewPath));


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

            ControllerContext             = new ControllerContext();
            ControllerContext.Helpers     = Helpers;
            ControllerContext.PropertyBag = PropertyBag;
            MockEngineContext.CurrentControllerContext = ControllerContext;


            Helpers["urlhelper"]        = Helpers["url"] = new UrlHelper(MockEngineContext);
            Helpers["htmlhelper"]       = Helpers["html"] = new HtmlHelper(MockEngineContext);
            Helpers["dicthelper"]       = Helpers["dict"] = new DictHelper(MockEngineContext);
            Helpers["DateFormatHelper"] = Helpers["DateFormat"] = new DateFormatHelper(MockEngineContext);


            //FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader(viewPath);
//			loader.AddAssemblySource(
//				new AssemblySourceInfo(Assembly.GetExecutingAssembly().FullName,
//									   "Castle.MonoRail.Views.Brail.Tests.ResourcedViews"));

            viewEngine = new AspViewEngine();
            viewEngine.Service(MockEngineContext);
            AspViewEngineOptions options = new AspViewEngineOptions();

            options.CompilerOptions.AutoRecompilation        = true;
            options.CompilerOptions.KeepTemporarySourceFiles = false;
            string root = AppDomain.CurrentDomain.BaseDirectory;

            root = root.Substring(0, root.LastIndexOf("Bin\\Debug", StringComparison.InvariantCultureIgnoreCase));
            ICompilationContext context =
                new CompilationContext(
                    new DirectoryInfo(root + @"\Bin\Debug"),
                    new DirectoryInfo(root),
                    new DirectoryInfo(root + @"\RenderingTests\Views"),
                    new DirectoryInfo(root));

            viewEngine.Initialize(context, options);
            System.Console.WriteLine("init");

            BeforEachTest();
        }