public void DoesUserAgentContainValueCondition(string userAgent, string containsUserAgentValue, bool expectedResult, Db database)
    {


      SetupDb(database);


      RuleContext ruleContext = new RuleContext();

      PoorMansDeviceDetectorCondition<RuleContext> customUserAgentCondition = new PoorMansDeviceDetectorCondition<RuleContext>()
      {
        OperatorId = Constants.StringOperations.Contains.ItemID.ToString(),
        Value = containsUserAgentValue,
        UserAgent = userAgent
      };

      var ruleStack = new RuleStack();

      // act
      customUserAgentCondition.Evaluate(ruleContext, ruleStack);

      // assert
      ruleStack.Should().HaveCount(1);

      object value = ruleStack.Pop();

      value.Should().Be(expectedResult);

    }
        public void MatchesToken()
        {
            using (var db = new Db()
            {
                new DbItem("page1"), new DbItem("page2")
            })
            {
                var page1 = db.GetItem("/sitecore/content/page1");
                var page2 = db.GetItem("/sitecore/content/page2");

                var args = new GetLookupSourceItemsArgs()
                {
                    Item = page1, Source = "{Home}/page1"
                };

                var context   = new GetLookupsourceItemsRuleContext(args);
                var condition = new QueryContainsTokenCondition <GetLookupsourceItemsRuleContext>()
                {
                    Token = "Home"
                };

                var ruleStack = new RuleStack();

                condition.Evaluate(context, ruleStack);

                ruleStack.Should().HaveCount(1);
                ruleStack.Pop().Should().Be(true);
            }
        }
示例#3
0
        public void FailsButDoesNotErrorWhenCompareIdNotSet()
        {
            var sourceRenderingId = ID.NewID;
            var targetRenderingId = ID.NewID;

            using (var db = new Db {
                new DbItem("rendering", targetRenderingId)
            })
            {
                var targetRenderingItem = db.GetItem(targetRenderingId);

                var context = new ReplaceRenderingRuleContext(new RenderingDefinition()
                {
                    ItemID = sourceRenderingId.ToString()
                }, targetRenderingItem, new DeviceDefinition());

                var condition = new TargetRenderingIsAnyOfCondition <ReplaceRenderingRuleContext>();

                var ruleStack = new RuleStack();

                condition.Evaluate(context, ruleStack);

                ruleStack.Should().HaveCount(1);
                ruleStack.Pop().Should().Be(false);
            }
        }
示例#4
0
        public void MatchesTargetId()
        {
            var sourceRenderingId = ID.NewID;
            var targetRenderingId = ID.NewID;

            using (var db = new Db {
                new DbItem("rendering", targetRenderingId)
            })
            {
                var targetRenderingItem = db.GetItem(targetRenderingId);

                var context = new ReplaceRenderingRuleContext(new RenderingDefinition()
                {
                    ItemID = sourceRenderingId.ToString()
                }, targetRenderingItem, new DeviceDefinition());

                var condition = new TargetRenderingIsAnyOfCondition <ReplaceRenderingRuleContext>
                {
                    CompareRenderingItemIds = targetRenderingId.ToString()
                };

                var ruleStack = new RuleStack();

                condition.Evaluate(context, ruleStack);

                ruleStack.Should().HaveCount(1);
                ruleStack.Pop().Should().Be(true);
            }
        }
示例#5
0
        public void DetectsItemFieldTokenWithoutFieldName()
        {
            using (var db = new Db()
            {
                new DbItem("page1"), new DbItem("page2")
            })
            {
                var page1 = db.GetItem("/sitecore/content/page1");

                var args = new GetLookupSourceItemsArgs()
                {
                    Item = page1, Source = "{ItemField:FullName}"
                };

                var context   = new GetLookupsourceItemsRuleContext(args);
                var condition = new QueryContainsTokenCondition <GetLookupsourceItemsRuleContext>()
                {
                    Token = "ItemField"
                };

                var ruleStack = new RuleStack();

                condition.Evaluate(context, ruleStack);

                ruleStack.Should().HaveCount(1);
                ruleStack.Pop().Should().Be(true);
            }
        }
示例#6
0
        public void ReturnsFalseForNullQuery()
        {
            using (var db = new Db()
            {
                new DbItem("page1"), new DbItem("page2")
            })
            {
                var page1 = db.GetItem("/sitecore/content/page1");

                var args = new GetLookupSourceItemsArgs()
                {
                    Item = page1
                };

                var context   = new GetLookupsourceItemsRuleContext(args);
                var condition = new QueryContainsTokenCondition <GetLookupsourceItemsRuleContext>()
                {
                    Token = "ItemField"
                };

                var ruleStack = new RuleStack();

                condition.Evaluate(context, ruleStack);

                ruleStack.Should().HaveCount(1);
                ruleStack.Pop().Should().Be(false);
            }
        }
示例#7
0
        public void ExecCorrectlyDetectsChild(string parentPath, string childPath, bool expectedResult, string message)
        {
            using (var db = GetFakeDb())
            {
                var item    = db.GetItem(childPath);
                var root    = db.GetItem(parentPath);
                var context = new RuleContext {
                    Item = item
                };

                var condition = new IsDescendentOfCondition <RuleContext>
                {
                    PotentialParent = root
                };

                var ruleStack = new RuleStack();

                condition.Evaluate(context, ruleStack);

                ruleStack.Should().HaveCount(1);
                ruleStack.Pop().Should().Be(expectedResult, message);
            }
        }