public void Allow_Specifying_A_Custom_IAssemblyScanner()
        {
            // Arrange
            bool typeWasFound = false;

            // Act
            var configuration = new TypeScannerConfiguration();

            configuration.ScanWith( new CustomAssemblyScanner() );

            configuration.ForAllTypes()
                .Do( type =>
                {
                    if ( type == typeof( CustomAssemblyScanner ) )
                    {
                        typeWasFound = true;
                    }
                    else
                    {
                        throw new Exception( "The CustomAssemblyScanner should only return a CustomAssemblyScanner type." );
                    }
                } );

            configuration.Scan();

            // Assert
            Assert.That( typeWasFound );
        }
        public void Be_Able_To_Scan_For_All_Types()
        {
            // Arrange
            bool typeWasFound = false;

            // Act
            var configuration = new TypeScannerConfiguration();

            configuration.ForAllTypes().Do( type =>
                {
                    if ( type == typeof( ClassA ) )
                    {
                        typeWasFound = true;
                    }
                });

            configuration.Scan();

            // Assert
            Assert.That( typeWasFound );
        }
        public void Be_Able_To_Scan_For_Abstract_Types()
        {
            // Arrange
            bool typeWasFound = false;

            // Act
            var configuration = new TypeScannerConfiguration();

            configuration.For<AbstractClassAa>()
                .ScanForTypesThatInheritFromThisAbstractClass()
                .Do( type =>
                    {
                        if ( type == typeof ( ClassAa ) )
                        {
                            typeWasFound = true;
                        }
                    } );

            configuration.Scan();

            // Assert
            Assert.That( typeWasFound );
        }
        public void Throw_An_Exception_If_The_Type_Is_Not_A_Class_When_Scanning_For_Classes_That_Inherit_A_Class()
        {
            // Act
            TestDelegate action = () =>
            {
                var configuration = new TypeScannerConfiguration();

                configuration.For<IInterfaceAbc>()
                    .ScanForTypesThatInheritFromThisClass()
                    .Do( type => { } );

                configuration.Scan();
            };

            // Assert
            Assert.Throws<Exception>( action );
        }
        public void Throw_An_Exception_If_The_Type_Is_Not_An_Interface_When_Scanning_For_Implementation_Of_An_Interface()
        {
            // Act
            TestDelegate action = () =>
                {
                    var configuration = new TypeScannerConfiguration();

                    configuration.For<AttributeXyz>()
                        .ScanForTypesThatImplementThisInterface()
                        .Do( type => { } );

                    configuration.Scan();
                };

            // Assert
            Assert.Throws<Exception>( action );
        }
        public void Throw_An_Exception_If_The_Type_Is_Not_An_Attribute_When_Scanning_For_Classes_Decorated_With_An_Attribute()
        {
            // Act
            TestDelegate action = () =>
            {
                var configuration = new TypeScannerConfiguration();

                configuration.For<IInterfaceAbc>()
                    .ScanForTypesThatAreDecoratedWithThisAttribute()
                    .Do( type => { } );

                configuration.Scan();
            };

            // Assert
            Assert.Throws<Exception>( action );
        }
        public void Be_Able_To_Scan_For_Implementations_Of_Interfaces()
        {
            // Arrange
            bool typeWasFound = false;

            // Act
            var configuration = new TypeScannerConfiguration();

            configuration.For<IInterfaceAbc>()
                .ScanForTypesThatImplementThisInterface()
                .Do( type =>
                {
                    if ( type == typeof( ClassAbc ) )
                    {
                        typeWasFound = true;
                    }
                } );

            configuration.Scan();

            // Assert
            Assert.That( typeWasFound );
        }
        public void Be_Able_To_Scan_For_Deeply_Nested_Classes_Decorated_With_An_Attribute()
        {
            // Arrange
            bool typeWasFound = false;

            // Act
            var configuration = new TypeScannerConfiguration();

            configuration.For<AttributeXyz>()
                .ScanForTypesThatAreDecoratedWithThisAttribute()
                .Do( type =>
                {
                    if ( type == typeof( ClassXyzz ) )
                    {
                        typeWasFound = true;
                    }
                } );

            configuration.Scan();

            // Assert
            Assert.That( typeWasFound );
        }
Пример #9
0
        /// <summary>
        /// Convenience method for configuring a <see cref="TypeScannerConfiguration"/>. 
        /// </summary>
        /// <param name="configuration"></param>
        public static void Configure( Action<TypeScannerConfiguration> configuration )
        {
            var typeScannerConfiguration = new TypeScannerConfiguration();

            configuration( typeScannerConfiguration );
        }