public void ShouldRegisterWithConventionAndWithRegistration() { //Arrange var assembly = Assembly.GetAssembly(typeof(TestUnityRegistration)); A.CallTo(() => registrationHelper.GetAssemblies()) .Returns(new List <Assembly> { assembly }); A.CallTo(() => registrationHelper.GetTypesImplementing <IUnityRegistration>(assembly)) .Returns(new List <Type> { typeof(TestUnityRegistration) }); var containerExtension = new UnityExtension(registrationHelper, options); A.CallTo(() => options.AutoRegistration).Returns(true); //Act containerExtension.Run(); //Assert A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened(); A.CallTo(() => registrationHelper.GetTypesImplementing <IUnityRegistration>(assembly)).MustHaveHappened(); Assert.IsNotNull(containerExtension.Resolve <IRegistrationHelper>()); Assert.IsNotNull(containerExtension.Resolve <UnityExtension>()); Assert.IsNotNull(containerExtension.Resolve <IRegisteredByConvention>()); }
public void ShouldInvokeTheRegisterMethodOfAllIUnityRegistrationTypes() { //Arrange var assembly = Assembly.GetAssembly(typeof(TestUnityRegistration)); A.CallTo(() => registrationHelper.GetAssemblies()) .Returns(new List <Assembly> { assembly }); A.CallTo(() => registrationHelper.GetTypesImplementing <IUnityRegistration>(assembly)) .Returns(new List <Type> { typeof(TestUnityRegistration) }); var containerExtension = new UnityExtension(registrationHelper, options); //Act containerExtension.Run(); var result = containerExtension.Resolve <UnityExtension>(); //Assert A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened(); A.CallTo(() => registrationHelper.GetTypesImplementing <IUnityRegistration>(assembly)).MustHaveHappened(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(UnityExtension)); }
public void ShouldThrowNoContainerExceptionWhenResolvingSimpleTypeBeforeInitializingTheContainer() { //Arrange var containerExtension = new UnityExtension(registrationHelper, options); //Act var result = ExceptionAssert.Throws <NoContainerException>(() => containerExtension.Resolve <object>()); //Assert Assert.AreEqual(NoContainerException.DefaultMessage, result.Message); }
public void ShouldResolveASingleNamedType() { //Arrange var containerExtension = new UnityExtension(registrationHelper, options); var container = new UnityContainer(); var instance = new object(); container.RegisterInstance("Name", instance); containerExtension.InitializeContainer(container); //Act var result = containerExtension.Resolve <object>(); //Assert Assert.IsNotNull(result); Assert.AreSame(instance, result); }
public void ShouldInvokeTheRegisterMethodOfAllIBootstrapperRegistrationTypes() { //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 UnityExtension(registrationHelper, options); //Act containerExtension.Run(); //Assert A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened(); A.CallTo(() => registrationHelper.GetTypesImplementing <IBootstrapperRegistration>(assembly)).MustHaveHappened(); Assert.IsNotNull(containerExtension.Resolve <IProfileExpression>()); }
public void Run_WhenInvokedAndAutoMapperExtensionIsLoaded_ShouldRegisterMapperAsSingelton() { //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 UnityExtension(registrationHelper, options); //Act containerExtension.Run(); //Assert Assert.AreSame(Mapper.Configuration, containerExtension.Resolve <IProfileExpression>()); Assert.AreSame(Mapper.Engine, containerExtension.Resolve <IMappingEngine>()); Assert.AreSame(containerExtension.Resolve <IProfileExpression>(), containerExtension.Resolve <IProfileExpression>()); Assert.AreSame(containerExtension.Resolve <IMappingEngine>(), containerExtension.Resolve <IMappingEngine>()); }