예제 #1
0
        List <SourceFile> GetSourceFiles()
        {
            var files = new List <SourceFile>();

            if (context.ViewRootDir.Exists == false)
            {
                throw new Exception(string.Format("Could not find views folder [{0}]", context.ViewRootDir));
            }

            foreach (string templateExtension in TemplateExtensions)
            {
                FileInfo[] templateFilenames = context.ViewRootDir.GetFiles("*" + templateExtension, SearchOption.AllDirectories);
                foreach (FileInfo fileInfo in templateFilenames)
                {
                    string viewName = fileInfo.FullName.Replace(context.ViewRootDir.FullName, "");
                    var    file     = new SourceFile
                    {
                        TemplateFullPath = fileInfo.FullName,
                        ViewName         = viewName,
                        ClassName        = AspViewEngine.GetClassName(viewName),
                        ViewSource       = File.ReadAllText(fileInfo.FullName)
                    };
                    file.RenderBody = file.ViewSource;
                    files.Add(file);
                }
            }
            return(files);
        }
예제 #2
0
		public void SetupFixture()
		{
			AspViewEngineOptions options = new AspViewEngineOptions(new AspViewCompilerOptions());
			engine = new AspViewEngine();
			//engine.Initialize(options);
			engineWithTestAccess = engine;
		}
예제 #3
0
        public void SetupFixture()
        {
            AspViewEngineOptions options = new AspViewEngineOptions(new AspViewCompilerOptions());

            engine = new AspViewEngine();
            //engine.Initialize(options);
            engineWithTestAccess = engine;
        }
예제 #4
0
 /// <summary>
 /// Creating default stub and mocks
 /// </summary>
 protected virtual void Clear()
 {
     expected    = null;
     writer      = null;
     engine      = null;
     cookies     = null;
     request     = null;
     response    = null;
     url         = null;
     trace       = null;
     propertyBag = null;
     flash       = null;
     controller  = null;
     context     = null;
 }
		/// <summary>
		/// Creating default stub and mocks
		/// </summary>
		protected virtual void CreateDefaultStubsAndMocks()
		{
			writer = writer ?? new StringWriter();
			engine = engine ?? new AspViewEngine();
			cookies = cookies ?? new Dictionary<string, HttpCookie>();
			request = request ?? new MockRequest(cookies);
			response = response ?? new MockResponse(cookies);
			url = url ?? new UrlInfo("", "Stub", "Stub");
			trace = trace ?? new MockTrace();
			propertyBag = propertyBag ?? new Hashtable();
			monoRailServices = monoRailServices ?? new MockServices();
			context = context ?? new MockEngineContext(request, response, monoRailServices, url);
			flash = flash ?? context.Flash;
			controller = controller ?? new ControllerStub();
			controllerContext = controllerContext ?? new ControllerContextStub();
			controllerContext.PropertyBag = propertyBag;
			context.Flash = flash;
		}
예제 #6
0
 /// <summary>
 /// Creating default stub and mocks
 /// </summary>
 protected virtual void CreateDefaultStubsAndMocks()
 {
     writer                        = writer ?? new StringWriter();
     engine                        = engine ?? new AspViewEngine();
     cookies                       = cookies ?? new Dictionary <string, HttpCookie>();
     request                       = request ?? new MockRequest(cookies);
     response                      = response ?? new MockResponse(cookies);
     url                           = url ?? new UrlInfo("", "Stub", "Stub");
     trace                         = trace ?? new MockTrace();
     propertyBag                   = propertyBag ?? new Hashtable();
     monoRailServices              = monoRailServices ?? new MockServices();
     context                       = context ?? new MockEngineContext(request, response, monoRailServices, url);
     flash                         = flash ?? context.Flash;
     controller                    = controller ?? new ControllerStub();
     controllerContext             = controllerContext ?? new ControllerContextStub();
     controllerContext.PropertyBag = propertyBag;
     context.Flash                 = flash;
 }
예제 #7
0
 /// <summary>
 /// Creating default stub and mocks
 /// </summary>
 protected virtual void CreateDefaultStubsAndMocks()
 {
     writer = writer ?? new StringWriter();
     engine = engine ?? new AspViewEngine();
     engine.GetType().GetField("options", BindingFlags.Static | BindingFlags.NonPublic).SetValue(engine, new AspViewEngineOptions());
     cookies          = cookies ?? new Dictionary <string, HttpCookie>();
     request          = request ?? new StubRequest(cookies);
     response         = response ?? new StubResponse(cookies);
     url              = url ?? new UrlInfo("", "Stub", "Stub");
     trace            = trace ?? new StubTrace();
     propertyBag      = propertyBag ?? new Hashtable();
     monoRailServices = monoRailServices ?? new StubMonoRailServices();
     context          = context ?? new StubEngineContext(request, response, monoRailServices, url);
     AspViewEngine.InitializeViewsStack(context);
     flash                         = flash ?? context.Flash;
     controller                    = controller ?? new ControllerStub();
     controllerContext             = controllerContext ?? new ControllerContextStub();
     controllerContext.PropertyBag = propertyBag;
     context.Flash                 = flash;
 }
		public void SetUp()
		{
			var testInstance = new MyApplication();
			oldApplicationInstanceGetter = AspViewEngine.GetApplicationInstance;
			AspViewEngine.GetApplicationInstance = () => testInstance;
			var basePath = Environment.CurrentDirectory;
			engine = new AspViewEngine();
			engineWithTestAccess = engine;			

			engineWithTestAccess.SetViewSourceLoader(new StubViewSourceLoader());
			engineWithTestAccess.SetCompilationContext(
				new List<ICompilationContext>
					{
						new CompilationContext(
							new DirectoryInfo(basePath),
							new DirectoryInfo(basePath),
							new DirectoryInfo(basePath),
							new DirectoryInfo(basePath))
					});
		}
예제 #9
0
        public void SetUp()
        {
            var testInstance = new MyApplication();

            oldApplicationInstanceGetter         = AspViewEngine.GetApplicationInstance;
            AspViewEngine.GetApplicationInstance = () => testInstance;
            var basePath = Environment.CurrentDirectory;

            engine = new AspViewEngine();
            engineWithTestAccess = engine;

            engineWithTestAccess.SetViewSourceLoader(new StubViewSourceLoader());
            engineWithTestAccess.SetCompilationContext(
                new List <ICompilationContext>
            {
                new CompilationContext(
                    new DirectoryInfo(basePath),
                    new DirectoryInfo(basePath),
                    new DirectoryInfo(basePath),
                    new DirectoryInfo(basePath))
            });
        }
예제 #10
0
        public static List <SourceFile> GetSourceFiles(string siteRoot)
        {
            List <SourceFile> files          = new List <SourceFile>();
            string            viewsDirectory = Path.Combine(siteRoot, "Views");

            if (!Directory.Exists(viewsDirectory))
            {
                throw new Exception(string.Format("Could not find views folder [{0}]", viewsDirectory));
            }

            string[] fileNames = Directory.GetFiles(viewsDirectory, "*.aspx", SearchOption.AllDirectories);
            foreach (string fileName in fileNames)
            {
                SourceFile file = new SourceFile();
                file.ViewName   = fileName.Replace(viewsDirectory, "");
                file.ClassName  = AspViewEngine.GetClassName(file.ViewName);
                file.ViewSource = ReadFile(fileName);
                file.RenderBody = file.ViewSource;
                files.Add(file);
            }
            return(files);
        }
		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);
		}
예제 #12
0
        protected void AddCompilation(string key, Type viewType)
        {
            string className = AspViewEngine.GetClassName(key);

            ((IAspViewEngineTestAccess)engine).Compilations.Add(className, viewType);
        }
예제 #13
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();
        }
		/// <summary>
		/// Creating default stub and mocks
		/// </summary>
		protected virtual void CreateDefaultStubsAndMocks()
		{
			writer = writer ?? new StringWriter();
			engine = engine ?? new AspViewEngine();
			engine.GetType().GetField("options", BindingFlags.Static | BindingFlags.NonPublic).SetValue(engine, new AspViewEngineOptions());
			cookies = cookies ?? new Dictionary<string, HttpCookie>();
			request = request ?? new StubRequest(cookies);
			response = response ?? new StubResponse(cookies);
			url = url ?? new UrlInfo("", "Stub", "Stub");
			trace = trace ?? new StubTrace();
			propertyBag = propertyBag ?? new Hashtable();
			monoRailServices = monoRailServices ?? new StubMonoRailServices();
			context = context ?? new StubEngineContext(request, response, monoRailServices, url);
			AspViewEngine.InitializeViewsStack(context);
			flash = flash ?? context.Flash;
			controller = controller ?? new ControllerStub();
			controllerContext = controllerContext ?? new ControllerContextStub();
			controllerContext.PropertyBag = propertyBag;
			context.Flash = flash;
		}
		/// <summary>
		/// Creating default stub and mocks
		/// </summary>
		protected virtual void Clear()
		{
			expected = null;
			writer = null;
			engine = null;
			cookies = null;
			request = null;
			response = null;
			url = null;
			trace = null;
			propertyBag = null;
			flash = null;
			controller = null;
			context = null;
		}
		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();
		}
        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);
        }