Beispiel #1
0
        public void Facet()
        {
            var search = new Search();
            var criteria = new[]
                               {
                                   new FacetSearchCriteria
                                       {
                                           InternalName = "freeTextFacet_1",
                                           DisplayName = "Test",
                                           FacetId = 1,
                                           SearchOperator = SearchOperator.StartsWith,
                                           Type = SearchFieldType.String,
                                           Value = "GiveCamp"
                                       }
                               };

            var expr = search.CompileFacetCriteria(criteria, null);

            Assert.AreEqual(SimpleExpressionType.And, expr.Type);

            var first = expr.LeftOperand as SimpleExpression;
            Assert.IsNotNull(first);
            var reference = first.LeftOperand as ObjectReference;
            Assert.IsNotNull(reference);
            Assert.AreEqual("FacetId", reference.GetName());
            Assert.AreEqual("freeTextFacet_1", reference.GetOwner().Alias);
            Assert.AreEqual(SimpleExpressionType.Equal, first.Type);
            Assert.AreEqual(1, first.RightOperand);

            var second = expr.RightOperand as SimpleExpression;
            Assert.IsNotNull(second);
            reference = second.LeftOperand as ObjectReference;
            Assert.IsNotNull(reference);
            Assert.AreEqual("FreeTextValue", reference.GetName());
            Assert.AreEqual("freeTextFacet_1", reference.GetOwner().Alias);
            var function = second.RightOperand as SimpleFunction;
            Assert.IsNotNull(function);
            Assert.AreEqual("like", function.Name.ToLowerInvariant());
            Assert.AreEqual(1, function.Args.Count);
            Assert.AreEqual("GiveCamp%", function.Args.First());
            Assert.AreEqual(SimpleExpressionType.Function, second.Type);
        }