Example #1
0
        private void FindTypesWithAllDependencies(IEnumerable <TypeDefinition> inputTypes, IEnumerable <string> dependenciesToSearch)
        {
            // Arrange
            var search = new DependencySearch();

            // Act
            var result = search.FindTypesWithAllDependencies(inputTypes, dependenciesToSearch);

            // Assert
            Assert.Equal(inputTypes.Count(), result.Count());
        }
        public void FindTypesWithAllDependencies_PublicProperty_Found()
        {
            // Arrange
            var search   = new DependencySearch();
            var typeList = Types
                           .InAssembly(Assembly.GetAssembly(typeof(HasDependency)))
                           .That()
                           .ResideInNamespace(typeof(HasDependency).Namespace)
                           .GetTypeDefinitions();

            // Act
            var result = search.FindTypesWithAllDependencies(typeList, new List <string> {
                typeof(ExampleDependency).FullName, typeof(AnotherExampleDependency).FullName
            });

            // Assert
            Assert.Single(result);                                                   // One type found
            Assert.Equal(typeof(HasDependencies).FullName, result.First().FullName); // Correct type returned
        }
        public void FindTypesWithAllDependencies_PatternMatchedNamespaces_NotReturned()
        {
            // In this example, searching for a dependency on "NamespaceMatch" should not return classes in "NamespaceMatchToo"

            // Arrange
            var search   = new DependencySearch();
            var typeList = Types
                           .InAssembly(Assembly.GetAssembly(typeof(HasDependency)))
                           .That()
                           .HaveName("NamespaceMatchingExample")
                           .GetTypeDefinitions();

            // Act
            var result = search.FindTypesWithAllDependencies(typeList, new List <string> {
                typeof(PatternMatch).Namespace
            });

            // Assert: Before PR#36 this would have returned classes in NamespaceMatchToo in the results
            Assert.Empty(result); // No results returned
        }