public void RegisterAll_WhenInvokedWithAGenericType_ShouldRegisterAllTypesThatImplementTheGenericType() { //Arrange var assembly = Assembly.GetAssembly(typeof(RegistrationHelper)); A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> { assembly }); A.CallTo(() => registrationHelper.GetTypesImplementing <IBootstrapperAssemblyProvider>(assembly)) .Returns(new List <Type> { typeof(LoadedAssemblyProvider), typeof(ReferencedAssemblyProvider) }); var container = new Container(); var containerExtension = new SimpleInjectorExtension(registrationHelper, options); containerExtension.InitializeContainer(container); //Act containerExtension.RegisterAll <IBootstrapperAssemblyProvider>(); var result = container.GetAllInstances <IBootstrapperAssemblyProvider>().ToList(); //Assert A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IEnumerable <IBootstrapperAssemblyProvider>)); Assert.IsTrue(result.Any()); Assert.IsTrue(result.Any(c => c is LoadedAssemblyProvider)); Assert.IsTrue(result.Any(c => c is ReferencedAssemblyProvider)); }
public void Register_WhenInvokedWithNonGenericTargetAndContainerIsNotInitialized_ShouldThrowException() { //Arrange var containerExtension = new SimpleInjectorExtension(registrationHelper, options); //Act var result = ExceptionAssert.Throws <NoContainerException>(() => containerExtension.RegisterAll(typeof(IGenericTest <>))); //Assert Assert.AreEqual(NoContainerException.DefaultMessage, result.Message); }
public void RegisterAll_WhenInvokedWithNonGenericTargetType_ShouldRegisterType() { //Arrange var container = new Container(); var containerExtension = new SimpleInjectorExtension(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[]> >(); }