Пример #1
0
        public void QueryNode_ConvertTokenIntoNodes_DefaultField()
        {
            // Arrange
            QueryToken token = Create("a");

            // Act
            QueryNode node = QueryNodeExtensions.ConvertTokensIntoNodes(token);

            // Assert
            Assert.True(node.IsActionNode());
            Assert.Equal(QueryNode.Empty, node.Left);
            Assert.Equal(QueryNode.Empty, node.Right);
        }
Пример #2
0
        public void QueryNode_ConvertTokensIntoNodes_SingleRotation()
        {
            // Arrange
            QueryToken token = Create("a", Create("and", Create("b")));

            // Act
            QueryNode node = QueryNodeExtensions.ConvertTokensIntoNodes(token);

            // Assert
            Assert.True(node.IsConjunctionNode());

            Assert.NotEqual(QueryNode.Empty, node.Left);
            Assert.True(node.Left.IsActionNode());

            Assert.NotEqual(QueryNode.Empty, node.Right);
            Assert.True(node.Right.IsActionNode());
        }
Пример #3
0
        public void QueryNode_ConvertTokensIntoNodes_MultipleQueryResults()
        {
            // Arrange
            string indexPropertyToSearchOn = "term";
            string searchValue             = "searchValue";
            int    numToFind = 5;

            Action <Index>[] elementInspectors = new Action <Index> [numToFind];
            void ElementInspectorFunction(Index e)
            {
                Assert.Equal(indexPropertyToSearchOn, e.Field);
                Assert.Equal(searchValue, e.Term);
            }

            List <Index> indices = new List <Index>();

            for (int i = 0; i < numToFind; i++)
            {
                indices.AddRange(GetTestIQueryable(indexPropertyToSearchOn, searchValue));

                elementInspectors[i] = ElementInspectorFunction;
            }

            IQueryable <Index> queryable = indices.AsQueryable();

            QueryToken queryToken = new QueryToken()
            {
                Value = indexPropertyToSearchOn + QueryNodeExtensions.FieldTermDelimeter + searchValue,
                Next  = QueryToken.Empty,
            };

            // Act
            QueryNode node = QueryNodeExtensions.ConvertTokensIntoNodes(queryToken);

            // Assert
            Assert.True(node.IsActionNode());
            Assert.Collection(node.Apply(queryable), elementInspectors);
        }
Пример #4
0
        public void QueryNode_ConvertTokensIntoNodes_SingleQueryToken()
        {
            // Arrange
            string             indexPropertyToSearchOn = "term";
            string             searchValue             = "searchValue";
            IQueryable <Index> queryable = GetTestIQueryable(indexPropertyToSearchOn, searchValue);

            QueryToken queryToken = new QueryToken()
            {
                Value = indexPropertyToSearchOn + QueryNodeExtensions.FieldTermDelimeter + searchValue,
                Next  = QueryToken.Empty,
            };

            // Act
            QueryNode node = QueryNodeExtensions.ConvertTokensIntoNodes(queryToken);

            // Assert
            Assert.True(node.IsActionNode());
            Index indexFound = Assert.Single(node.Apply(queryable));

            Assert.Equal(indexPropertyToSearchOn, indexFound.Field);
            Assert.Equal(searchValue, indexFound.Term);
        }