public void UrlForBlogWithEndingWildcardMatchesBlogPostPageInSaidBlog()
 {
     _stubContextAccessor.Set(new StubHttpContext("~/my-blog/my-blog-post"));
     var context = new ConditionEvaluationContext { FunctionName = "url", Arguments = new[] { "~/my-blog/*" } };
     _urlCondition.Evaluate(context);
     Assert.That(context.Result, Is.True);
 }
Beispiel #2
0
        public void Evaluate(ConditionEvaluationContext evaluationContext) {
            if (!String.Equals(evaluationContext.FunctionName, "url", StringComparison.OrdinalIgnoreCase))
                return;

            var context = _httpContextAccessor.Current();
            var url = Convert.ToString(evaluationContext.Arguments[0]);
            if (url.StartsWith("~/")) {
                url = url.Substring(2);
                var appPath = context.Request.ApplicationPath;
                if (appPath == "/")
                    appPath = "";

                if(!String.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
                    appPath = String.Concat(appPath, "/", _shellSettings.RequestUrlPrefix);

                url = String.Concat(appPath, "/", url);
            }

            if (!url.Contains("?"))
                url = url.TrimEnd('/');

            var requestPath = context.Request.Path;
            if (!requestPath.Contains("?"))
                requestPath = requestPath.TrimEnd('/');

            evaluationContext.Result = url.EndsWith("*")
                ? requestPath.StartsWith(url.TrimEnd('*'), StringComparison.OrdinalIgnoreCase)
                : string.Equals(requestPath, url, StringComparison.OrdinalIgnoreCase);
        }
 public void UrlForHomePageDoesNotMatchAboutPagePath()
 {
     _stubContextAccessor.Set(new StubHttpContext("~/about"));
     var context = new ConditionEvaluationContext { FunctionName = "url", Arguments = new[] { "~/" } };
     _urlCondition.Evaluate(context);
     Assert.That(context.Result, Is.False);
 }
 public void UrlForAboutPageWithEndingSlashMatchesAboutPagePath()
 {
     _stubContextAccessor.Set(new StubHttpContext("~/About/"));
     var context = new ConditionEvaluationContext { FunctionName = "url", Arguments = new[] { "~/about" } };
     _urlCondition.Evaluate(context);
     Assert.That(context.Result, Is.True);
 }
        public void Evaluate(ConditionEvaluationContext evaluationContext) {
            if (evaluationContext.FunctionName == "add") {
                evaluationContext.Result = Convert.ToInt32(evaluationContext.Arguments[0]) + Convert.ToInt32(evaluationContext.Arguments[1]);
                return;
            }

            evaluationContext.Result = true;
        }
        public void Evaluate(ConditionEvaluationContext evaluationContext)
        {
            if (!String.Equals(evaluationContext.FunctionName, "contenttype", StringComparison.OrdinalIgnoreCase)) {
                return;
            }

            var contentType = Convert.ToString(evaluationContext.Arguments[0]);

            evaluationContext.Result = _displayedContentItemHandler.IsDisplayed(contentType);
        }
Beispiel #7
0
        public void Evaluate(ConditionEvaluationContext evaluationContext) {
            var ruleContext = new RuleContext {
                FunctionName = evaluationContext.FunctionName,
                Arguments = evaluationContext.Arguments,
                Result = evaluationContext.Result
            };

            _ruleProviders.Process(ruleContext);
            evaluationContext.Result = ruleContext.Result;
        }
Beispiel #8
0
            public void Process(GlobalMethodContext context) {
                var ruleContext = new ConditionEvaluationContext {
                    FunctionName = context.FunctionName,
                    Arguments = context.Arguments.ToArray(),
                    Result = context.Result
                };

                _conditionManager._conditions.Evaluate(ruleContext);

                context.Result = ruleContext.Result;
            }
            public void Process(GlobalMethodContext context)
            {
                var ruleContext = new ConditionEvaluationContext {
                    FunctionName = context.FunctionName,
                    Arguments    = context.Arguments.ToArray(),
                    Result       = context.Result
                };

                _conditionManager._conditions.Evaluate(ruleContext);

                context.Result = ruleContext.Result;
            }
        public void Evaluate(ConditionEvaluationContext context)
        {
            // Example: contentitemtype("Page").
            if (!String.Equals(context.FunctionName, RuleFunctionName, StringComparison.OrdinalIgnoreCase))
                return;

            var contentTypeName = GetArgument(context, 0);
            var result = mCurrentContentAccessor.CurrentContentItem?.ContentType == contentTypeName;

            Logger.Debug("Layer rule {0}({1}) evaluated to {2}.", RuleFunctionName, contentTypeName, result);

            context.Result = result;
        }
        public void Evaluate(ConditionEvaluationContext evaluationContext)
        {
            if (!String.Equals(evaluationContext.FunctionName, "authenticated", StringComparison.OrdinalIgnoreCase)) {
                return;
            }

            if (_authenticationService.GetAuthenticatedUser() != null) {
                evaluationContext.Result = true;
                return;
            }

            evaluationContext.Result = false;
        }
        public void Evaluate(ConditionEvaluationContext context)
        {
            // Example: action("action", "controller", "area", "value1=a, value2=b")
            if (!String.Equals(context.FunctionName, RuleFunctionName, StringComparison.OrdinalIgnoreCase))
                return;

            var actionName = GetArgument(context, 0);
            var controllerName = GetArgument(context, 1);
            var areaName = GetArgument(context, 2);
            var routeValueString = GetArgument(context, 3);
            var routeValues = ParseRouteValues(routeValueString);

            SetRouteValueIfNotEmpty(routeValues, RuleFunctionName, actionName);
            SetRouteValueIfNotEmpty(routeValues, "controller", controllerName);
            SetRouteValueIfNotEmpty(routeValues, "area", areaName);

            var routeData = mWorkContextAccessor.GetContext().HttpContext.Request.RequestContext.RouteData;
            var result = NavigationHelper.RouteMatches(routeValues, routeData.Values);

            Logger.Debug("Layer rule {0}({1}, {2}, {3}, {4}) evaluated to {5}.", RuleFunctionName, actionName, controllerName, areaName, routeValueString, result);

            context.Result = result;
        }
 public void UrlForHomePageMatchesHomePagePathWithUrlPrefix()
 {
     _stubContextAccessor.Set(new StubHttpContext("~/site1"));
     _shellSettings.RequestUrlPrefix = "site1";
     var context = new ConditionEvaluationContext { FunctionName = "url", Arguments = new[] { "~/" } };
     _urlCondition.Evaluate(context);
     Assert.That(context.Result, Is.True);
 }
 private static string GetArgument(ConditionEvaluationContext context, int index)
 {
     return context.Arguments.Count() - 1 >= index ? (string)context.Arguments[index] : default(string);
 }
Beispiel #15
0
 public void Evaluate(ConditionEvaluationContext evaluationContext)
 {
     if (string.Equals(evaluationContext.FunctionName, "WorkContext", StringComparison.OrdinalIgnoreCase)) {
         evaluationContext.Result = _workContextAccessor.GetContext();
     }
 }