Пример #1
0
        public async void TestNodeQuerySearchFind()
        {
            IBranch branch = await Fixture.Repository.ReadBranchAsync("master");

            JObject nodeObj1 = new JObject(
                new JProperty("title", "Cheese burger"),
                new JProperty("meal", "lunch")
                );
            JObject nodeObj2 = new JObject(
                new JProperty("title", "Ham burger"),
                new JProperty("meal", "lunch")
                );
            JObject nodeObj3 = new JObject(
                new JProperty("title", "Turkey sandwich"),
                new JProperty("meal", "lunch")
                );
            JObject nodeObj4 = new JObject(
                new JProperty("title", "Oatmeal"),
                new JProperty("meal", "breakfast")
                );

            IBaseNode node1 = await branch.CreateNodeAsync(nodeObj1);

            IBaseNode node2 = await branch.CreateNodeAsync(nodeObj2);

            IBaseNode node3 = await branch.CreateNodeAsync(nodeObj3);

            IBaseNode node4 = await branch.CreateNodeAsync(nodeObj4);

            // Wait for nodes to index
            Thread.Sleep(5000);

            JObject query = new JObject(
                new JProperty("meal", "lunch")
                );
            List <IBaseNode> queryNodes = await branch.QueryNodesAsync(query);

            var queryNodesIds = queryNodes.Select(node => node.Id);

            Assert.Equal(3, queryNodes.Count);
            Assert.Contains(node1.Id, queryNodesIds);
            Assert.Contains(node2.Id, queryNodesIds);
            Assert.Contains(node3.Id, queryNodesIds);

            JObject find = new JObject(
                new JProperty("search", "burger")
                );
            List <IBaseNode> findNodes = await branch.FindNodesAsync(find);

            var findNodesIds = findNodes.Select(node => node.Id);

            Assert.Equal(2, findNodes.Count);
            Assert.Contains(node1.Id, findNodesIds);
            Assert.Contains(node2.Id, findNodesIds);

            // search
            List <IBaseNode> searchNodes = await branch.SearchNodesAsync("burger");

            var searchNodesIds = searchNodes.Select(node => node.Id);

            Assert.Equal(2, searchNodes.Count);
            Assert.Contains(node1.Id, searchNodesIds);
            Assert.Contains(node2.Id, searchNodesIds);

            await node1.DeleteAsync();

            await node2.DeleteAsync();

            await node3.DeleteAsync();

            await node4.DeleteAsync();
        }