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 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() { helper = new JSONHelper(); var services = new StubMonoRailServices { JSONSerializer = new NewtonsoftJSONSerializer() }; helper.SetContext(new StubEngineContext(null, null, services, null)); }
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); }
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); ViewComponentFactory.Initialize(); 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(); }
public void Init() { mocks = new MockRepository(); serviceProvider = new StubMonoRailServices(); var viewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views"); viewSourceLoader.Service(this.serviceProvider); serviceProvider.ViewSourceLoader = viewSourceLoader; serviceProvider.AddService(typeof(IViewSourceLoader), viewSourceLoader); Configure(); controllerContext = new ControllerContext(); propertyBag = controllerContext.PropertyBag; controllerContext.LayoutNames = new []{"default"}; output = new StringWriter(); server = new StubServerUtility(); routingEngine = MockRepository.GenerateMock<IRoutingEngine>(); var urlBuilder = new DefaultUrlBuilder(server, routingEngine); serviceProvider.UrlBuilder = urlBuilder; serviceProvider.AddService(typeof(IUrlBuilder), urlBuilder); InitUrlInfo("", "home", "index"); response = engineContext.Response; }
public void Init() { mocks = new MockRepository(); serviceProvider = new StubMonoRailServices(); var viewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views"); viewSourceLoader.Service(this.serviceProvider); serviceProvider.ViewSourceLoader = viewSourceLoader; serviceProvider.AddService(typeof(IViewSourceLoader), viewSourceLoader); Configure(); controllerContext = new ControllerContext(); propertyBag = controllerContext.PropertyBag; controllerContext.LayoutNames = new [] { "default" }; output = new StringWriter(); server = new StubServerUtility(); routingEngine = MockRepository.GenerateMock <IRoutingEngine>(); var urlBuilder = new DefaultUrlBuilder(server, routingEngine); serviceProvider.UrlBuilder = urlBuilder; serviceProvider.AddService(typeof(IUrlBuilder), urlBuilder); InitUrlInfo("", "home", "index"); response = engineContext.Response; }
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(); 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(); 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 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); }
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 Init() { var settings = new SparkSettings(); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader("MonoRail.Tests.Views")); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); _factory = new SparkViewFactory(); _factory.Service(services); }
/// <summary> /// Constructs a mock context. /// </summary> /// <param name="areaName">Name of the area.</param> /// <param name="controllerName">Name of the controller.</param> /// <param name="actionName">Name of the action.</param> /// <param name="contextInitializer">The context initializer.</param> protected void BuildEngineContext(string areaName, string controllerName, string actionName, ContextInitializer contextInitializer) { var info = BuildUrlInfo(areaName, controllerName, actionName); services = BuildServices(); request = BuildRequest(); request.RawUrl = info.UrlRaw; response = BuildResponse(info); trace = BuildTrace(); context = BuildRailsEngineContext(request, response, services, trace, info); AddEmailServices(context); contextInitializer(context); }
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 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 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 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 SetUp() { controller = new ReturnBinderTestController(); viewEngineManager = new InjectableStubViewEngineManager(); PrepareController(controller); services = controller.Context.Services as StubMonoRailServices; services.ViewEngineManager = viewEngineManager; engineContext = controller.Context as StubEngineContext; engineContext.Request.Headers.Add("User-Agent", "Test Fixture"); controllerContext = services.ControllerContextFactory. Create("", "ReturnBinderTest", "Index", services.ControllerDescriptorProvider.BuildDescriptor(controller)); controller.Contextualize(controller.Context, controllerContext); viewEngineManager.RegisterTemplate(string.Format("ReturnBinderTest{0}Index", Path.DirectorySeparatorChar)); }
public void SetUp() { controller = new ReturnBinderTestController(); viewEngineManager = new InjectableStubViewEngineManager(); PrepareController(controller); services = controller.Context.Services as StubMonoRailServices; services.ViewEngineManager = viewEngineManager; engineContext = controller.Context as StubEngineContext; engineContext.Request.Headers.Add("User-Agent", "Test Fixture"); controllerContext = services.ControllerContextFactory. Create("", "ReturnBinderTest", "Index", services.ControllerDescriptorProvider.BuildDescriptor(controller)); controller.Contextualize(controller.Context, controllerContext); viewEngineManager.RegisterTemplate("ReturnBinderTest\\Index"); }
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 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 override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.CodeBase.Replace("file:///", ""); var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var appBinPath = Path.GetDirectoryName(assemblyPath); var appBasePath = Path.GetDirectoryName(appBinPath); var viewPath = ViewPath; if (string.IsNullOrEmpty(viewPath)) { viewPath = "Views"; } if (!Directory.Exists(Path.Combine(appBasePath, viewPath)) && Directory.Exists(Path.Combine(appBinPath, viewPath))) { appBasePath = appBinPath; } var webFileHack = Path.Combine(appBasePath, "web"); var viewsLocation = Path.Combine(appBasePath, viewPath); if (!string.IsNullOrEmpty(TargetAssemblyFile)) { targetPath = Path.Combine(appBinPath, TargetAssemblyFile); } // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(appBinPath, e.Name + ".dll"))); var settings = (ISparkSettings)config.GetSection("spark"); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader(viewsLocation)); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); var factory = new SparkViewFactory(); factory.Service(services); // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) { DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); } factory.Precompile(batch); base.Install(stateSaver); }
public void StubMonoRailServices_Should_Return_Null_If_Service_Cannot_Be_Found() { var services = new StubMonoRailServices(); Assert.IsNull(services.GetService<MR_ISSUE_476>()); }
/// <summary> /// Constructs a mock context. /// </summary> /// <param name="areaName">Name of the area.</param> /// <param name="controllerName">Name of the controller.</param> /// <param name="actionName">Name of the action.</param> /// <param name="contextInitializer">The context initializer.</param> protected void BuildEngineContext(string areaName, string controllerName, string actionName, ContextInitializer contextInitializer) { var info = BuildUrlInfo(areaName, controllerName, actionName); services = BuildServices(); request = BuildRequest(); request.RawUrl = info.UrlRaw; response = BuildResponse(info); trace = BuildTrace(); context = BuildRailsEngineContext(request, response, services, trace, info); AddEmailServices( context ); contextInitializer(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 StubMonoRailServices_Should_Return_Null_If_Service_Cannot_Be_Found() { var services = new StubMonoRailServices(); Assert.IsNull(services.GetService <MR_ISSUE_476>()); }
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); }
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(); }
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); }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.CodeBase.Replace("file:///", ""); var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var appBinPath = Path.GetDirectoryName(assemblyPath); var appBasePath = Path.GetDirectoryName(appBinPath); var viewPath = ViewPath; if (string.IsNullOrEmpty(viewPath)) viewPath = "Views"; if (!Directory.Exists(Path.Combine(appBasePath, viewPath)) && Directory.Exists(Path.Combine(appBinPath, viewPath))) { appBasePath = appBinPath; } var webFileHack = Path.Combine(appBasePath, "web"); var viewsLocation = Path.Combine(appBasePath, viewPath); if (!string.IsNullOrEmpty(TargetAssemblyFile)) targetPath = Path.Combine(appBinPath, TargetAssemblyFile); // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(appBinPath, e.Name + ".dll"))); var settings = (ISparkSettings)config.GetSection("spark"); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader(viewsLocation)); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); var factory = new SparkViewFactory(); factory.Service(services); // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); factory.Precompile(batch); base.Install(stateSaver); }