private static Func <HttpContextBase> BuildContextFunc()
        {
            return(() =>
            {
                var context = HttpContext.Current;

                if (context != null)
                {
                    return new HttpContextWrapper(context);
                }

                return FakeHttpContext.Root();
            });
        }
        public void InitController()
        {
            controllerContext = new ControllerContext
            {
                HttpContext = FakeHttpContext.Root()
            };

            cache.Get("Category", () => new List <Category> {
                new Category
                {
                    CategoryCode = "601",
                    CategoryName = "公司新闻",
                    //CategoryTypeCode = 6,
                }
            });
        }
Exemple #3
0
        public void InitController()
        {
            controllerContext = new ControllerContext
            {
                HttpContext = FakeHttpContext.Root()
            };

            cache.Get("SysConfig", () => new List <SysConfigModel> {
                new SysConfigModel
                {
                    ConfigName = "config"
                }
            });
            // controller = new ArticleInfoController(new ArticleInfoService())
            //{
            //    ControllerContext = controllerContext
            //};
        }
Exemple #4
0
        /// <summary>
        /// Creates the setup conditions for a <see cref="GivenController"/>.As with the <see cref="RequestContext"/> to allow for mocking on the object.
        /// This is the full version and there are shorter wrapper for specific headers <see cref="WithLocation"/>, <see cref="WithReferrer"/> and <see cref="WithUserAgent"/>.
        /// <example>
        /// <code>
        ///     GivenController.As&lt;UserController>()
        ///         .Should(x => x.AssertResultIs&lt;HeadResult>().StatusCode.ShouldBe(HttpStatusCode.OK))
        ///         .WhenCalling(x => x.Show());
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="setupAction">The setup action.</param>
        /// <returns></returns>
        public ActionExpectations <T> WithRequest(Action <HttpRequestBase> setupAction)
        {
            if (setupAction != null)
            {
                if (MockRequest == null)
                {
                    var fakeHttpContext = FakeHttpContext.Root();
                    MockRequest = MockRepository.GenerateMock <HttpRequestBase>();
                    var mockResponse = MockRepository.GenerateMock <HttpResponseBase>();

                    fakeHttpContext.SetResponse(mockResponse);
                    fakeHttpContext.SetRequest(MockRequest);

                    MockController.ControllerContext = new ControllerContext(new RequestContext(fakeHttpContext, new RouteData()),
                                                                             MockController);
                }
                setupAction(MockRequest);
            }
            return(this);
        }
        // todo: Move to a Seleno.Mvc project if established
        public TPage To <TController, TPage>(Expression <Action <TController> > action, IDictionary <string, object> routeValues = null)
            where TController : Controller
            where TPage : UiComponent, new()
        {
            var requestContext = new RequestContext(FakeHttpContext.Root(), new RouteData());

            var actionRouteValues = ExpressionHelper.GetRouteValuesFromExpression(action);

            if (routeValues != null)
            {
                foreach (var v in routeValues)
                {
                    actionRouteValues[v.Key] = v.Value;
                }
            }

            var urlHelper   = new UrlHelper(requestContext, _routeCollection);
            var relativeUrl = urlHelper.RouteUrl(new RouteValueDictionary(actionRouteValues));

            return(To <TPage>(relativeUrl));
        }
Exemple #6
0
 public virtual void Register(ContainerBuilder builder)
 {
     builder.Register <HttpContextBase>(c => { return(HttpContext.Current != null ? new HttpContextWrapper(HttpContext.Current) : (FakeHttpContext.Root() as HttpContextBase)); });
     builder.RegisterType <AppDomainTypeFinder>().As <ITypeFinder>().SingleInstance();
     builder.RegisterGeneric(typeof(ConfigurationProvider <>)).As(typeof(IConfigurationProvider <>)).SingleInstance();
     builder.RegisterType <SettingService>().As <ISettingService>().SingleInstance();
     builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().SingleInstance();
     builder.RegisterType <WebHelper>().As <IWebHelper>().SingleInstance();
     builder.RegisterType <DefaultLogger>().As <ILogger>().SingleInstance();
     builder.RegisterType <FileSystemStorageProvider>().As <IStorageProvider>().SingleInstance();
 }