public void GetTypesImplementing_WhenInvokedWithATypeAsAParameter_ShouldReturnTheTypesFromTheCallingAssemblyThatImplementTheParameter()
        {
            //Act
            var result = registrationHelper.GetTypesImplementing(typeof(IGenericTest <>));

            //Assert
            result.First().ShouldBe(typeof(GenericTest <>));
        }
Example #2
0
        public void RegisterAll_WhenInvokedWithNonGenericTargetType_ShouldRegisterType()
        {
            //Arrange
            var container          = new Container();
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            containerExtension.InitializeContainer(container);
            var thisAssembly = Assembly.GetAssembly(typeof(GenericTest <>));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new[] { thisAssembly });
            A.CallTo(() => registrationHelper.GetTypesImplementing(thisAssembly, typeof(IGenericTest <>)))
            .Returns(new[] { typeof(GenericTest <>) });


            //Act
            containerExtension.RegisterAll(typeof(IGenericTest <>));
            var result1 = container.GetInstance <IGenericTest <object> >();
            var result2 = container.GetInstance <IGenericTest <string[]> >();

            //Assert
            result1.ShouldBeOfType <GenericTest <object> >();
            result2.ShouldBeOfType <GenericTest <string[]> >();
        }
Example #3
0
        public void ShouldRegisterAllTypesOfIBootstrapperRegistration()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(AutoMapperRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies())
            .Returns(new List <Assembly> {
                assembly
            });
            A.CallTo(() => registrationHelper.GetTypesImplementing <IBootstrapperRegistration>(assembly))
            .Returns(new List <Type> {
                typeof(AutoMapperRegistration)
            });
            var containerExtension = new NinjectExtension(registrationHelper, options);

            //Act
            containerExtension.Run();
            var result = containerExtension.ResolveAll <IBootstrapperRegistration>();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            A.CallTo(() => registrationHelper.GetTypesImplementing <IBootstrapperRegistration>(assembly)).MustHaveHappened();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IEnumerable <IBootstrapperRegistration>));
            Assert.IsTrue(result.Any());
            Assert.IsTrue(result[0] is AutoMapperRegistration);
        }