예제 #1
0
        public void Search_WithNameFilter_ReturnsExpectedComponents()
        {
            // Arrange
            var name       = "the-name-we-are-looking-for";
            var components = new List <Component>
            {
                new Component("my-comp", null, null)
                {
                    Type   = "SomeType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                },
                new Component(name, null, null)
                {
                    Type   = "SomeOtherType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                }
            };

            var spec = new ComponentTypeAndFieldSearchSpecElement {
                Name = name
            };

            // Act
            var found = spec.Search(null, components);

            // Assert
            Assert.Single(found);
            Assert.Equal(name, found.Single().Name);
        }
예제 #2
0
        public void Search_WithJustTypeFilter_ReturnsExpectedComponents()
        {
            // Arrange
            var typeInFilter = "TypeInFilter";
            var components   = new List <Component>
            {
                new Component("my-comp", null, null)
                {
                    Type = typeInFilter
                },
                new Component("my-other-comp", null, null)
                {
                    Type = "SomeOtherType"
                }
            };
            var spec = new ComponentTypeAndFieldSearchSpecElement {
                ComponentType = typeInFilter
            };

            // Act
            var found = spec.Search(null, components);

            // Assert
            Assert.Single(found);
            Assert.Equal("my-comp", found.Single().Name);
        }
예제 #3
0
        public void Search_NoHits_ReturnsEmptyList()
        {
            // Arrange
            var component = new Component("my-comp", null, null)
            {
                Fields = new Dictionary <string, object>
                {
                    ["k1"] = "v1",
                    ["k2"] = new DateTime(2018, 11, 8, 11, 11, 11),
                    ["k3"] = 111,
                    ["k4"] = long.MaxValue
                }
            };

            var spec = new ComponentTypeAndFieldSearchSpecElement();

            spec.AddFieldFilter("k1", "v1");
            spec.AddFieldFilter("k2", new DateTime(2018, 11, 8, 11, 11, 11));
            spec.AddFieldFilter("k3", 111);
            spec.AddFieldFilter("k4", 90000099);

            // Act
            var found = spec.Search(null, new List <Component> {
                component
            });

            // Assert
            Assert.Empty(found);
        }
예제 #4
0
        public void Search_WithNameAndParentFilter_MultipleTargets_ReturnsExpectedComponents()
        {
            // Arrange
            var name1      = "the-name-we-are-looking-for";
            var name2      = "the-other-name-we-are-looking-for";
            var parentName = "the-parentName-we-are-looking-for";

            var parentId   = "parentId";
            var components = new List <Component>
            {
                new Component(parentName, null, null)
                {
                    Id     = parentId,
                    Type   = "SomeType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                },
                new Component(name1, null, null)
                {
                    Parent = parentId,
                    Type   = "SomeType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                },
                new Component(name2, null, null)
                {
                    Parent = parentId,
                    Type   = "SomeOtherType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                }
            };

            var spec = new ComponentTypeAndFieldSearchSpecElement
            {
                NameList = new List <string> {
                    name1, name2
                },
                ParentNameList = new List <string> {
                    parentName
                }
            };

            // Act
            var found = spec.Search(null, components).ToList();

            // Assert
            Assert.Equal(2, found.Count());
            Assert.Equal(name1, found[0].Name);
            Assert.Equal(name2, found[1].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);
        }
예제 #6
0
        public void Search_WithTypeFilterNotInSearchSpace_ReturnsEmptyLists()
        {
            // Arrange
            var typeInFilter = "TypeInFilter";
            var compId       = "my-comp-1";
            var components   = new List <Component>
            {
                new Component("my-comp", null, null)
                {
                    Id     = compId,
                    Type   = typeInFilter,
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                },
                new Component("my-other-comp", null, null)
                {
                    Type   = "SomeOtherType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                }
            };

            var spec = new ComponentTypeAndFieldSearchSpecElement {
                ComponentType = typeInFilter
            };

            spec.AddFieldFilter("k1", "v1");

            // Act
            var found = spec.Search(null, components, new List <Component> {
                new Component(null, null, null)
                {
                    Id = "some-other-component"
                }
            });

            // Assert
            Assert.Empty(found);
        }
예제 #7
0
        public void Search_WithTypeFilterAndInSearchSpace_ReturnsExpectedComponents()
        {
            // Arrange
            var       typeInFilter    = "TypeInFilter";
            var       compId          = "my-comp-1";
            Component targetComponent = new Component("my-comp", null, null)
            {
                Id     = compId,
                Type   = typeInFilter,
                Fields = new Dictionary <string, object>
                {
                    ["k1"] = "v1",
                }
            };
            Component otherComponent = new Component("my-other-comp", null, null)
            {
                Type   = "SomeOtherType",
                Fields = new Dictionary <string, object>
                {
                    ["k1"] = "v1",
                }
            };
            var components = new List <Component>
            {
                targetComponent,
                otherComponent
            };

            var spec = new ComponentTypeAndFieldSearchSpecElement {
                ComponentType = typeInFilter
            };

            spec.AddFieldFilter("k1", "v1");

            // Act
            var found = spec.Search(null, components, new List <Component> {
                targetComponent
            });

            // Assert
            Assert.Single(found);
            Assert.Equal("my-comp", found.Single().Name);
        }
        private static SearchSpec GetSearchSpecForServiceBusOrEventHubNamespace(string connectionString, string searchFolder)
        {
            var arr        = connectionString.Split(';');
            var endpoint   = arr.Single(a => a.StartsWith("Endpoint="));
            var entityPath = arr.Single(a => a.StartsWith("EntityPath="));

            var spec = new SearchSpec(searchFolder);

            var namespaceElement = new ComponentTypeAndFieldSearchSpecElement();

            namespaceElement.ComponentType = "ServiceBusNamespace";
            namespaceElement.AddFieldFilter("uri", endpoint.Split('=')[1]);
            spec.AddElement(namespaceElement);

            var entityElement = new ComponentTypeAndFieldSearchSpecElement();

            entityElement.Name = entityPath.Split('=')[1];
            spec.AddElement(entityElement);

            return(spec);
        }
예제 #9
0
        public void Search_EmptySearchSpec_ReturnsNothing()
        {
            // Arrange
            var components = new List <Component>
            {
                new Component("some name", null, null)
                {
                    Type   = "SomeOtherType",
                    Fields = new Dictionary <string, object>
                    {
                        ["k1"] = "v1",
                    }
                }
            };

            var spec = new ComponentTypeAndFieldSearchSpecElement {
            };

            // Act
            var found = spec.Search(null, components);

            // Assert
            Assert.Empty(found);
        }
        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);
        }