コード例 #1
0
ファイル: BaseViewComponentTests.cs プロジェクト: Eilon/spark
        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);
        }
コード例 #2
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);
			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();
		}
コード例 #3
0
		public void Init()
		{
			selector = new DefaultActionSelector();

			var request = new StubRequest();
			var response = new StubResponse();
			var services = new StubMonoRailServices();
			engine = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action1"));
		}
コード例 #4
0
		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);
		}
コード例 #5
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);

        }
コード例 #6
0
		public void DelegatesToDynamicAction()
		{
			var dynAction = new ActionStub();

			var executor = new DynamicActionExecutor(dynAction);

			var req = new StubRequest();
			var res = new StubResponse();
			var services = new StubMonoRailServices();
			IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));

			var retVal = executor.Execute(engineContext, new DummyController(), new ControllerContext());
			Assert.IsTrue(dynAction.WasExecuted);
			Assert.AreEqual(3, retVal);
		}
コード例 #7
0
        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 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);
		}
コード例 #9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="StubEmailTemplateService"/> class.
		/// </summary>
		/// <param name="context">The context.</param>
		public StubEmailTemplateService(StubEngineContext context)
		{
			this.context = context;
		}
コード例 #10
0
		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);
		}
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StubEmailTemplateService"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public StubEmailTemplateService(StubEngineContext context)
 {
     this.context = context;
 }
コード例 #12
0
		public override void Process(string templateName, string layoutName, TextWriter output, 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;
			}

			var stubContext = new StubEngineContext();

			Process(templateName, output, stubContext, null, controllerContext);
		}
コード例 #13
0
		/// <summary>
		/// Allows modifying of the engine context created by <see cref="BuildRailsEngineContext"/>
		/// </summary>
		/// <param name="stubEngineContext">The engine context to modify</param>
		protected virtual void InitializeEngineContext(StubEngineContext stubEngineContext)
		{}
コード例 #14
0
 /// <summary>
 /// Adds the default mock email services to the context.
 /// </summary>
 /// <param name="stubEngineContext"></param>
 protected virtual void AddEmailServices(StubEngineContext stubEngineContext)
 {
     stubEngineContext.Services.EmailTemplateService = new StubEmailTemplateService(stubEngineContext);
     stubEngineContext.Services.EmailSender = new StubSmtpSender(stubEngineContext);
 }
コード例 #15
0
		/// <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);
		}
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StubSmtpSender"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public StubSmtpSender(StubEngineContext context)
 {
     this.context = context;
 }
コード例 #17
0
		/// <summary>
		/// Initializes a new instance of the <see cref="StubSmtpSender"/> class.
		/// </summary>
		/// <param name="context">The context.</param>
		public StubSmtpSender(StubEngineContext context)
		{
			this.context = context;
		}
コード例 #18
0
		/// <summary>
		/// Builds the a mock context. You can override this method to
		/// create a special configured mock context.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="response">The response.</param>
		/// <param name="services">The services.</param>
		/// <param name="trace">The trace.</param>
		/// <param name="urlInfo">The URL info.</param>
		/// <returns></returns>
		protected virtual StubEngineContext BuildRailsEngineContext(IMockRequest request, IMockResponse response, 
			IMonoRailServices services, ITrace trace, UrlInfo urlInfo)
		{
			StubEngineContext engine = new StubEngineContext(request, response, services, urlInfo);
			engine.Trace = trace;
			return engine;
		}