Exemple #1
0
        public void Search()
        {
            target(Search);

            String addr = ctx.Post("webAddress");

            if (strUtil.IsNullOrEmpty(addr) || addr.StartsWith("http:") == false)
            {
                set("dirAndFiles", "");
                return;
            }

            IWebContext webContext = MockWebContext.New(ctx.viewer.Id, addr, new StringWriter());

            AdminSecurityUtils.SetSession(webContext);
            try {
                new CoreHandler().ProcessRequest(webContext);
            }
            catch (Exception ex) {
                set("dirAndFiles", "<div class=\"warning\">" + lang("exSearchViews") + "</div><div style=\"border:1px #f2f2f2 solid; margin-top:10px; padding:10px;display:none;\">" + ex.ToString().Replace(Environment.NewLine, "<br/>") + "</div>");
                return;
            }

            List <string> list = CurrentRequest.getItem(Template.loadedTemplates) as List <string>;

            bindResults(list);
        }
Exemple #2
0
        public static MvcContext GetOne(IMember objOwner, int appId)
        {
            IWebContext webContext = MockWebContext.New(1, "http://localhost/", new System.IO.StringWriter());

            MvcContext ctx = new MvcContext(webContext);

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();

            route.setAppId(appId);   // 为了让生成的link链接中有appId,必须设置此项
            ctx.utils.setRoute(route);

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();

            viewer.obj = new User();
            ctx.utils.setViewerContext(viewer);

            // owner
            OwnerContext owner = new OwnerContext();

            owner.Id  = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext(owner);

            // app
            IAppContext app = new AppContext();

            app.Id  = appId;
            app.obj = BlogApp.findById(appId);
            app.setAppType(typeof(BlogApp));     // 如果要使用alang语言包,必须设置此项
            ctx.utils.setAppContext(app);

            return(ctx);
        }
Exemple #3
0
        /// <summary>
        /// We simply obtain a fully configured context ready to use for a test case.
        /// </summary>
        /// <returns>
        /// Returns a web context.
        /// </returns>
        protected IWebContext GetContext()
        {
            IWebContext context = new MockWebContext(ServiceContainer.Instance, new AssemblyResourceAdapter(Assembly.GetExecutingAssembly(), "Behaviour"));
            IList <IProcessBehaviour> behaviours = context.Services.GetService <List <IProcessBehaviour> >("test-behaviours");

            context.Register(behaviours);
            return(context);
        }
        private static MvcContext getContextInit() {

            String urlRoot = "http://" + SystemInfo.Authority;


            IWebContext webContext = MockWebContext.New( 1, urlRoot, new System.IO.StringWriter() );

            MvcContext ctx = new MvcContext( webContext );
            return ctx;
        }
 public void Setup()
 {
     _httpContext = new MockWebContext();
     _mapper      = new Mock <IMapper>(MockBehavior.Strict);
     _entryAccess = new Mock <IEntryAccess>();
     _sut         = new EntryController(_entryAccess.Object, _mapper.Object)
     {
         ControllerContext = MockWebContext.BasicControllerContext()
     };
 }
Exemple #6
0
        private static MvcContext getContextInit()
        {
            String urlRoot = sys.Url.SchemeStr + SystemInfo.Authority;


            IWebContext webContext = MockWebContext.New(1, urlRoot, new System.IO.StringWriter());

            MvcContext ctx = new MvcContext(webContext);

            return(ctx);
        }
Exemple #7
0
        public void TestInvalidDateStringFormats(string dateString)
        {
            MockWebContext ctx = new MockWebContext();

            ctx.Query.Add("date", new StringValues(dateString));

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateDateAttribute attr = new ValidateDateAttribute();

            attr.OnActionExecuting(actExeContext);

            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        [InlineData("{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}")] // missing ending '}' character
        public void ValidateInvalidGuids(string guid)
        {
            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("id", guid);

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateIdAttribute attr = new ValidateIdAttribute("id");

            attr.OnActionExecuting(actExeContext);

            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Exemple #9
0
        public void ValidateInvalidBusinessIds(string businessId)
        {
            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("code", businessId);

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateRegExAttribute attr = new ValidateRegExAttribute("code", @"^[0-9]{7}-[0-9]{1}$");

            attr.OnActionExecuting(actExeContext);

            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Exemple #10
0
        public void ValidateValidBusinessIds(string businessId)
        {
            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("code", businessId);

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateRegExAttribute attr = new ValidateRegExAttribute("code", @"^[0-9]{7}-[0-9]{1}$");

            attr.OnActionExecuting(actExeContext);

            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be(0);
        }
        public void ValidateValidGuids(string guid)
        {
            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("id", guid);

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateIdAttribute attr = new ValidateIdAttribute("id");

            attr.OnActionExecuting(actExeContext);

            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be(0);
        }
        public void ValidateInvalidValue()
        {
            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("id", "{CA761232-ED42-11CE-BACD-00AA0057B223"); // missing ending curly brace

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidationBaseAttribute attr = new ValidationBaseAttribute("id", new ValidGuidAttribute());

            attr.OnActionExecuting(actExeContext);

            // bad request response, http status code 400
            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public void ValidateValidValue()
        {
            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("id", "{CA761232-ED42-11CE-BACD-00AA0057B223}");

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidationBaseAttribute attr = new ValidationBaseAttribute("id", new ValidGuidAttribute());

            attr.OnActionExecuting(actExeContext);

            // if the argument needs to be present when using this validator then we should expect here validation error with http status code 400 or 422
            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be(0);
        }
        public void ShouldHandleKeyNameNotFound()
        {
            // the attribute should handle cases that the key is not found instead of code causing KeyNotFoundException
            // caller has no idea what key is missing
            // attribute implementation skips null values so it should also skip validation if the key is not found?

            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("id", "{CA761232-ED42-11CE-BACD-00AA0057B223}");

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateIdAttribute attr = new ValidateIdAttribute("notfoundkeyname");

            attr.OnActionExecuting(actExeContext);

            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Exemple #15
0
        protected String makeHtml(String addr, List <String> nextMakeUrls)
        {
            StringWriter sw         = new StringWriter();
            IWebContext  webContext = MockWebContext.New(addr, sw);
            MvcContext   ctx        = new MvcContext(webContext);

            ctx.SetItem("_makeHtml", true);

            new CoreHandler().ProcessRequest(ctx);

            List <String> relativeUrls = ctx.GetItem("_relativeUrls") as List <String>;

            if (relativeUrls != null && relativeUrls.Count > 0)
            {
                nextMakeUrls.AddRange(relativeUrls);
            }

            return(sw.ToString());
        }
Exemple #16
0
        public void TestValidDateStringFormats(string dateString)
        {
            MockWebContext ctx = new MockWebContext();

            // null value would cause sequence contains no elements exception
            // so we use null here to indicate not to include the date parameter
            if (dateString != null)
            {
                ctx.Query.Add("date", new StringValues(dateString));
            }

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateDateAttribute attr = new ValidateDateAttribute();

            attr.OnActionExecuting(actExeContext);

            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be(0);
        }
Exemple #17
0
        public void ShouldHandleKeyNameNotFound()
        {
            // the attribute should handle cases that the key is not found instead of code causing KeyNotFoundException
            // caller has no idea what key is missing
            // attribute implementation skips null values so it should also skip validation if the key is not found?
            // either way the Exception should be handled and return correct message and status code

            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("code", "1234567-8");

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidateRegExAttribute attr = new ValidateRegExAttribute("notfoundkeyname", @"^[0-9]{7}-[0-9]{1}$");

            attr.OnActionExecuting(actExeContext);

            // if everything is ok the status is not changed so default 0 value is the expected value and not http 200
            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public void ValidatorShouldntThrowWhenKeyNameIsMissingFromRequest()
        {
            // it shouldn't throw if it is ok that the value is missing from request
            // for example with guid attribute null and empty values are ok by the validator
            // or the implementation of the validator should be changed so that it doesn't
            // crash with KeyNotFoundException, the code should check if the required key exists and if not return
            // the similiar response (json) as it currently returns if the supplied value is not valid

            MockWebContext ctx = new MockWebContext();

            ctx.ActionArguments.Add("id", "{CA761232-ED42-11CE-BACD-00AA0057B223}");

            var actExeContext = ctx.CreateActionExecutingContext();

            ValidationBaseAttribute attr = new ValidationBaseAttribute("notfoundkeyname", new ValidGuidAttribute());

            attr.OnActionExecuting(actExeContext);

            // if the argument needs to be present when using this validator then we should expect here validation error with http status code 400 or 422
            actExeContext.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
 public void Setup()
 {
     controller = new AccountController {
         ControllerContext = MockWebContext.BasicContext()
     };
 }
 /// <summary>
 /// We simply obtain a fully configured context ready to use for a test case.
 /// </summary>
 /// <returns>
 /// Returns a web context.
 /// </returns>
 protected IWebContext GetContext()
 {
     IWebContext context = new MockWebContext(ServiceContainer.Instance, new AssemblyResourceAdapter(Assembly.GetExecutingAssembly(), "Behaviour"));
     IList<IProcessBehaviour> behaviours = context.Services.GetService<List<IProcessBehaviour>>("test-behaviours");
     context.Register(behaviours);
     return context;
 }