/// <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)
 {
     return(new StubEngineContext(request, response, services, urlInfo)
     {
         Trace = trace
     });
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="StubEngineContext"/> class.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="response">The response.</param>
		/// <param name="services">The services.</param>
		/// <param name="urlInfo">The URL info.</param>
		public StubEngineContext(IMockRequest request, IMockResponse response, IMonoRailServices services, UrlInfo urlInfo)
		{
			this.request = request;
			this.response = response;
			this.services = services;
			this.urlInfo = urlInfo;

			if (response != null)
			{
				response.UrlInfo = urlInfo;
				response.UrlBuilder = services.UrlBuilder;
			}
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="StubEngineContext"/> class.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        /// <param name="services">The services.</param>
        /// <param name="urlInfo">The URL info.</param>
        public StubEngineContext(IMockRequest request, IMockResponse response, IMonoRailServices services, UrlInfo urlInfo)
        {
            this.request  = request;
            this.response = response;
            this.Services = services;
            this.urlInfo  = urlInfo;

            if (response != null)
            {
                response.UrlInfo    = urlInfo;
                response.UrlBuilder = services.UrlBuilder;
            }
        }
        /// <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);
        }
示例#5
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;
 }
示例#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;
 }
		/// <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 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);
			flash = flash ?? context.Flash;
			controller = controller ?? new ControllerStub();
			controllerContext = controllerContext ?? new ControllerContextStub();
			controllerContext.PropertyBag = propertyBag;
			context.Flash = flash;
		}
示例#8
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;
 }
		/// <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;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="StubEngineContext"/> class.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="response">The response.</param>
		/// <param name="urlInfo">The URL info.</param>
		public StubEngineContext(IMockRequest request, IMockResponse response, UrlInfo urlInfo)
			: this(request, response, new StubMonoRailServices(), urlInfo)
		{
		}
		/// <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)
		{
			return new StubEngineContext(request, response, services, urlInfo)
			{
				Trace = trace
			};
		}
		/// <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);
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="StubEngineContext"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="response">The response.</param>
 /// <param name="urlInfo">The URL info.</param>
 public StubEngineContext(IMockRequest request, IMockResponse response, UrlInfo urlInfo)
     : this(request, response, new StubMonoRailServices(), urlInfo)
 {
 }