상속: System.Collections.Hashtable
        public void Init()
        {
            mocks = new MockRepository();
            factory = new SparkViewFactory();
            engineContext = mocks.CreateMock<IEngineContext>();
            server = new MockServerUtility();
            request = mocks.CreateMock<IRequest>();
            response = mocks.CreateMock<IResponse>();

            controller = mocks.CreateMock<IController>();
            controllerContext = mocks.CreateMock<IControllerContext>();
            routingEngine = mocks.CreateMock<IRoutingEngine>();
            output = new StringWriter();
            helpers = new HelperDictionary();

            propertyBag = new Dictionary<string, object>();
            flash = new Flash();
            session = new Dictionary<string, object>();
            requestParams = new NameValueCollection();
            contextItems = new Dictionary<string, object>();


            SetupResult.For(engineContext.Server).Return(server);
            SetupResult.For(engineContext.Request).Return(request);
            SetupResult.For(engineContext.Response).Return(response);
            SetupResult.For(engineContext.CurrentController).Return(controller);
            SetupResult.For(engineContext.CurrentControllerContext).Return(controllerContext);
            SetupResult.For(engineContext.Flash).Return(flash);
            SetupResult.For(engineContext.Session).Return(session);
            SetupResult.For(engineContext.Items).Return(contextItems);

            SetupResult.For(request.Params).Return(requestParams);

            SetupResult.For(controllerContext.LayoutNames).Return(new[] { "default" });
            SetupResult.For(controllerContext.Helpers).Return(helpers);
            SetupResult.For(controllerContext.PropertyBag).Return(propertyBag);

            SetupResult.For(routingEngine.IsEmpty).Return(true);

            var urlBuilder = new DefaultUrlBuilder(server, routingEngine);

            var serviceProvider = mocks.CreateMock<IServiceProvider>();
            var viewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            SetupResult.For(serviceProvider.GetService(typeof(IViewSourceLoader))).Return(viewSourceLoader);
            SetupResult.For(serviceProvider.GetService(typeof(ILoggerFactory))).Return(new NullLogFactory());
            SetupResult.For(serviceProvider.GetService(typeof(ISparkViewEngine))).Return(null);
            SetupResult.For(serviceProvider.GetService(typeof(IUrlBuilder))).Return(urlBuilder);
            SetupResult.For(serviceProvider.GetService(typeof(IViewComponentFactory))).Return(null);
            mocks.Replay(serviceProvider);

            SetupResult.For(engineContext.GetService(null)).IgnoreArguments().Do(
                new Func<Type, object>(serviceProvider.GetService));

            factory.Service(serviceProvider);


            manager = new DefaultViewEngineManager();
            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }
예제 #2
0
		public void FlashKeep()
		{
			Flash flash = new Flash();

			flash.Now("test1","hello");
			flash.Now("test2","hello");

			flash.Keep("test1");

			flash.Sweep();

			Assert.IsTrue( flash.ContainsKey("test1") );
			Assert.IsFalse( flash.ContainsKey("test2") );

			flash = new Flash(flash);
			flash.Sweep();

			Assert.IsTrue( flash.Count == 0 );

			flash.Now("test1","hello");
			flash.Now("test2","hello");

			flash.Keep();

			flash.Sweep();

			Assert.IsTrue( flash.ContainsKey("test1") );
			Assert.IsTrue( flash.ContainsKey("test2") );
		}
예제 #3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Flash"/> class.
		/// </summary>
		/// <param name="copy">The copy.</param>
		public Flash(Flash copy) : base(StringComparer.InvariantCultureIgnoreCase)
		{
			if (copy == null) return;

			foreach(DictionaryEntry entry in copy)
			{
				base.Add(entry.Key, entry.Value);
			}
		}
예제 #4
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Flash"/> class.
		/// </summary>
		/// <param name="copy">The copy.</param>
		public Flash(Flash copy)
		{
			if (copy == null) return;

			foreach(DictionaryEntry entry in copy)
			{
				base.Add(entry.Key, entry.Value);
			}
		}
예제 #5
0
		public void FlashNow()
		{
			Flash flash = new Flash();

			flash.Now("test","hello");

			Assert.IsTrue( flash.ContainsKey("test") );

			flash.Sweep();

			Assert.IsFalse( flash.ContainsKey("test") );
		}
예제 #6
0
		public void SimpleTest()
		{
			Flash flash = new Flash();

			flash["test"] = "hello";

			flash.Sweep();

			Assert.IsTrue( flash.ContainsKey("test") );

			flash = new Flash(flash);

			Assert.IsTrue( flash.ContainsKey("test") );
		}
예제 #7
0
		/// <summary>
		/// Handles MonoRail's actions before the controller action started processing
		/// </summary>
		/// <param name="context">The context.</param>
	    protected void BeforeControllerProcess(HttpContext context)
	    {
	        if (!sessionless)
	        {
	            // Now we have a session
	            engineContext.Session = ResolveSession(context);
	        }

	        IDictionary session = engineContext.Session;

	        Flash flash;

	        if (session != null)
	        {
	            flash = new Flash((Flash) session[Flash.FlashKey]);
	        }
	        else
	        {
	            flash = new Flash();
	        }

	        engineContext.Flash = flash;

	        // items added to be used by the test context
	        context.Items["mr.controller"] = controller;
	        context.Items["mr.flash"] = engineContext.Flash;
	        context.Items["mr.propertybag"] = controllerContext.PropertyBag;
	        context.Items["mr.session"] = context.Session;

	        AcquireCustomSession();
	    }
예제 #8
0
		public void FlashDiscard()
		{
			var flash = new Flash
			{
				{ "test1", "hello" }, 
				{ "test2", "hello" }
			};

			flash.Discard("test2");

			flash.Sweep();

			Assert.IsTrue( flash.ContainsKey("test1") );
			Assert.IsFalse( flash.ContainsKey("test2") );

			flash = new Flash(flash);
			flash.Sweep();

			Assert.IsTrue( flash.Count == 0 );

			flash.Add("test1","hello");
			flash.Add("test2","hello");

			flash.Discard();

			flash = new Flash(flash);
			flash.Sweep();

			Assert.IsFalse( flash.ContainsKey("test1") );
			Assert.IsFalse( flash.ContainsKey("test2") );

			flash = new Flash
			{
				{ "test1", "hello" }, 
				{ "test1", "hello update" }
			};

			Assert.AreEqual("hello update", flash["test1"]);

			flash.Discard("test1");

			flash.Sweep();

			Assert.IsFalse(flash.ContainsKey("test1"));
		}