示例#1
0
        public void Search_NoHits_ReturnsEmptyList()
        {
            // Assert
            var searchTag   = "tag1";
            var componentId = "comp1";
            var tags        = new List <Tag>
            {
                new Tag(searchTag, null, null)
                {
                    Components = new List <string> {
                        componentId
                    }
                }
            };

            var components = new List <Component> {
                new Component("n1", null, null)
                {
                    Id = componentId
                }
            };

            var tagSearch = new TagSearchSpecElement();

            tagSearch.AddTags(new List <string> {
                "some-other-tag"
            });

            // Act
            var found = tagSearch.Search(tags, components);

            // Assert
            Assert.Empty(found);
        }
示例#2
0
        public void Search_HasHits_ReturnsExpectedComponents()
        {
            // Assert
            var searchTag   = "tag1";
            var componentId = "comp1";
            var tags        = new List <Tag>
            {
                new Tag(searchTag, null, null)
                {
                    Components = new List <string> {
                        componentId
                    }
                }
            };

            var components = new List <Component> {
                new Component("n1", null, null)
                {
                    Id = componentId
                }
            };

            var tagSearch = new TagSearchSpecElement();

            tagSearch.AddTags(new List <string> {
                searchTag
            });

            // Act
            var found = tagSearch.Search(tags, components);

            // Assert
            Assert.Single(found);
            Assert.Equal("n1", found.First().Name);
        }
        public void Search_Hierarchy_FindsExpectedComponents()
        {
            // Arrange
            var parentId  = "parent-1";
            var component = new Component("myName", null, null)
            {
                Id     = parentId,
                Type   = "myType",
                Fields = new Dictionary <string, object> {
                    ["k1"] = 99
                }
            };


            _tagServiceMock.Setup(ts => ts.GetAllTags(null))
            .Returns(Task.FromResult(new List <Tag> {
                new Tag("tag1", null, null)
                {
                    Components = new List <string> {
                        parentId
                    }
                }
            }));
            _componentServiceMock.Setup(cs => cs.GetAllComponents(null))
            .Returns(Task.FromResult(new List <Component> {
                component
            }));

            var spec      = new SearchSpec(null);
            var tagSearch = new TagSearchSpecElement();

            tagSearch.AddTags(new List <string> {
                "tag1"
            });
            spec.AddElement(tagSearch);

            var typeAndFieldSearchSpec = new ComponentTypeAndFieldSearchSpecElement {
                ComponentType = "myType"
            };

            typeAndFieldSearchSpec.AddFieldFilter("k1", 99);

            spec.AddElement(typeAndFieldSearchSpec);
            var searcher = GetSearcher();

            // Act
            var found = searcher.Search(spec).Result;

            // Assert
            Assert.Single(found);
            Assert.Equal("myName", found.Single().Name);
        }
示例#4
0
        public void Search_HasHitsButNotInSearchSpace_ReturnsExpectedComponents()
        {
            // Assert
            var searchTag   = "tag1";
            var componentId = "comp1";
            var tags        = new List <Tag>
            {
                new Tag(searchTag, null, null)
                {
                    Components = new List <string> {
                        componentId
                    }
                }
            };

            var components = new List <Component> {
                new Component("n1", null, null)
                {
                    Id = componentId
                }
            };
            var searchSpace = new List <Component> {
                new Component("n1", null, null)
                {
                    Id = "some-other-component-id"
                }
            };

            var tagSearch = new TagSearchSpecElement();

            tagSearch.AddTags(new List <string> {
                searchTag
            });

            // Act
            var found = tagSearch.Search(tags, components, searchSpace);

            // Assert
            Assert.Empty(found);
        }
        private void Search_IntegrationTest()
        {
            // Arrange
            var url          = "";
            var token        = "";
            var organization = "";
            var client       = new ArdoqClient(new HttpClient(), url, token, organization);

            var searcher = new ArdoqSearcher(client, new ConsoleLogger());

            var tag = "integration-test";

            var spec       = new SearchSpec(null);
            var tagElement = new TagSearchSpecElement();

            tagElement.AddTags(new List <string> {
                tag
            });
            spec.AddElement(tagElement);

            // Act
            var results = searcher.Search(spec).Result;
        }
示例#6
0
        public void Search_SeveralTagsHasHits_ReturnsExpectedComponents()
        {
            // Assert
            var searchTag      = "tag1";
            var componentId    = "comp1";
            var otherComponent = "other-comp";
            var c2             = "c-2";
            var c3             = "c-3";
            var c4             = "c-4";

            var tags = new List <Tag>
            {
                new Tag(searchTag, null, null)
                {
                    Components = new List <string> {
                        componentId, c2, c3, c4, otherComponent
                    }
                },
                new Tag("tag2", null, null)
                {
                    Components = new List <string> {
                        componentId, c2, c3, otherComponent
                    }
                },
                new Tag("tag3", null, null)
                {
                    Components = new List <string> {
                        componentId, c2, c4, otherComponent
                    }
                },
                new Tag("tag4", null, null)
                {
                    Components = new List <string> {
                        componentId, c3, c4, otherComponent
                    }
                }
            };

            var components = new List <Component>
            {
                new Component("n1", null, null)
                {
                    Id = componentId
                },
                new Component("n2", null, null)
                {
                    Id = c2
                },
                new Component("n3", null, null)
                {
                    Id = c3
                },
                new Component("n4", null, null)
                {
                    Id = c4
                },
                new Component("other", null, null)
                {
                    Id = otherComponent
                },
            };


            var tagSearch = new TagSearchSpecElement();

            tagSearch.AddTags(new List <string> {
                searchTag, "tag2", "tag3", "tag4"
            });

            // Act
            var found = tagSearch.Search(tags, components);

            // Assert
            Assert.Equal(2, found.Count());
            Assert.Contains(found, c => c.Id == componentId);
            Assert.Contains(found, c => c.Id == otherComponent);
        }
        public void Search_HierarchyNoHits_ReturnsEmptyList()
        {
            // Arrange
            var parentId        = "parent-1";
            var childId         = "child-1";
            var parentComponent = new Component("parent", null, null)
            {
                Id       = parentId,
                Type     = "ParentType",
                Children = new List <string> {
                    childId
                }
            };

            var childComponent = new Component("child", null, null)
            {
                Id     = childId,
                Type   = "ChildType",
                Fields = new Dictionary <string, object> {
                    ["k1"] = 66
                }
            };


            _tagServiceMock.Setup(ts => ts.GetAllTags(null))
            .Returns(Task.FromResult(new List <Tag> {
                new Tag("tag1", null, null)
                {
                    Components = new List <string> {
                        parentId
                    }
                }
            }));
            _componentServiceMock.Setup(cs => cs.GetAllComponents(null))
            .Returns(Task.FromResult(new List <Component> {
                parentComponent, childComponent
            }));

            var spec    = new SearchSpec(null);
            var tagSpec = new TagSearchSpecElement();

            tagSpec.AddTags(new List <string> {
                "tag1"
            });
            spec.AddElement(tagSpec);

            var typeAndFieldSearchSpec = new ComponentTypeAndFieldSearchSpecElement {
                ComponentType = "ChildType"
            };

            typeAndFieldSearchSpec.AddFieldFilter("k1", 99);

            spec.AddElement(typeAndFieldSearchSpec);
            var searcher = GetSearcher();

            // Act
            var found = searcher.Search(spec).Result;

            // Assert
            Assert.Empty(found);
        }