public void ShouldRegisterWithTargetType()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(RegistrationHelper));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var container          = new WindsorContainer();
            var containerExtension = new WindsorExtension(registrationHelper, options);

            containerExtension.InitializeContainer(container);

            //Act
            containerExtension.RegisterAll <IBootstrapperAssemblyProvider>();
            var result = container.ResolveAll <IBootstrapperAssemblyProvider>();

            //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 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 WindsorExtension(registrationHelper, options);

            //Act
            containerExtension.Run();

            //Assert
            Assert.AreSame(AutoMapperExtension.ConfigurationProvider, containerExtension.Resolve <IConfigurationProvider>());
            Assert.AreSame(AutoMapperExtension.ProfileExpression, containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(AutoMapperExtension.Mapper, containerExtension.Resolve <IMapper>());
            Assert.AreSame(AutoMapperExtension.Engine, containerExtension.Resolve <IMappingEngine>());
            Assert.AreSame(containerExtension.Resolve <IConfigurationProvider>(), containerExtension.Resolve <IConfigurationProvider>());
            Assert.AreSame(containerExtension.Resolve <IProfileExpression>(), containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(containerExtension.Resolve <IMapper>(), containerExtension.Resolve <IMapper>());
            Assert.AreSame(containerExtension.Resolve <IMappingEngine>(), containerExtension.Resolve <IMappingEngine>());
            Assert.AreSame(containerExtension.Resolve <IExpressionBuilder>(), containerExtension.Resolve <IExpressionBuilder>());
        }
        public void Run_WhenTheContainerInOptionsIsSet_ShouldUseTheExistingContainer()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(TestWindsorRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies())
            .Returns(new List <Assembly> {
                assembly
            });
            A.CallTo(() => registrationHelper.GetTypesImplementing <IWindsorRegistration>(assembly))
            .Returns(new List <Type> {
                typeof(TestWindsorRegistration)
            });
            var container          = new WindsorContainer();
            var containerExtension = new WindsorExtension(registrationHelper, options)
            {
                Options = { Container = container }
            };


            //Act
            containerExtension.Run();

            //Assert
            Assert.AreSame(container, containerExtension.Container);
        }
 /// <summary>
 /// The pluggable windsor.
 /// </summary>
 /// <param name="extensions">
 /// The extensions.
 /// </param>
 /// <param name="helper">
 /// The helper.
 /// </param>
 /// <param name="facilities">
 /// The facilities.
 /// </param>
 /// <returns>
 /// The <see cref="WindsorOptions"/>.
 /// </returns>
 public static WindsorOptions PluggableWindsor(
     this BootstrapperExtensions extensions, IRegistrationHelper helper, params IFacility[] facilities)
 {
     var windsorExtension = new WindsorExtension(helper, new BootstrapperContainerExtensionOptions());
     facilities.ForEach(windsorExtension.AddFacility);
     extensions.Extension(windsorExtension);
     return windsorExtension.Options;
 }
        public void ShouldCreateAWindsorContainerExtension()
        {
            //Act
            var result = new WindsorExtension(registrationHelper, options);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(WindsorExtension));
        }
        public void ShouldAddCastleToExcludedAssemblies()
        {
            //Act
            var result = new WindsorExtension(registrationHelper, options);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Bootstrapper.Excluding.Assemblies.Contains("Castle"));
            Assert.IsTrue(Bootstrapper.Excluding.Assemblies.Contains("Castle.Facilities.FactorySupport"));
        }
        public void ShouldThrowNoContainerExceptionWhenSettingServiceLocatorBeforeInitializingTheContainer()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            var result = ExceptionAssert.Throws <NoContainerException>(containerExtension.SetServiceLocator);

            //Assert
            Assert.AreEqual(NoContainerException.DefaultMessage, result.Message);
        }
        public void ShouldThrowNoContainerExceptionWhenResolvingMultipleTypesBeforeInitializingTheContainer()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            var result = ExceptionAssert.Throws <NoContainerException>(() => containerExtension.ResolveAll <object>());

            //Assert
            Assert.AreEqual(NoContainerException.DefaultMessage, result.Message);
        }
        public void Register_WhenInvokedWithNonGenericTargetAndContainerIsNotInitialized_ShouldThrowException()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            var result = ExceptionAssert.Throws <NoContainerException>(() => containerExtension.RegisterAll(typeof(IGenericTest <>)));

            //Assert
            Assert.AreEqual(NoContainerException.DefaultMessage, result.Message);
        }
        public void ShouldThrowNoContainerExceptionWhenRegisteringWithTargetTypeBeforeInitializingTheContainer()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            var result = ExceptionAssert.Throws <NoContainerException>(containerExtension.RegisterAll <IBootstrapperContainerExtension>);

            //Assert
            Assert.AreEqual(NoContainerException.DefaultMessage, result.Message);
        }
        public void ShouldReturnANullContainer()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            var result = containerExtension.Container;

            //Assert
            Assert.IsNull(result);
        }
        public void ShouldResetTheContainer()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            containerExtension.Run();

            //Act
            containerExtension.Reset();

            //Assert
            Assert.IsNull(Bootstrapper.ContainerExtension);
        }
        public void ShouldReturnABootstrapperContainerExtensionOptions()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            var result = containerExtension.Options;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IBootstrapperContainerExtensionOptions));
            Assert.IsInstanceOfType(result, typeof(WindsorOptions));
        }
        public void ShouldReturnAnIWindsorContainer()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            containerExtension.Run();
            var result = containerExtension.Container;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IWindsorContainer));
        }
        public void ShouldResetTheServiceLocator()
        {
            //Arrange
            ServiceLocator.SetLocatorProvider(A.Fake <IServiceLocator>);
            var containerExtension = new WindsorExtension(registrationHelper, options);

            containerExtension.Run();

            //Act
            containerExtension.ResetServiceLocator();

            //Assert
            Assert.IsNull(ServiceLocator.Current);
        }
        public void ShouldAddFacility()
        {
            // Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);
            var facility           = A.Fake <IFacility>();
            var container          = new WindsorContainer();

            // Act
            containerExtension.AddFacility(facility);
            containerExtension.InitializeContainer(container);

            // Assert
            Assert.IsTrue(container.Kernel.GetFacilities().Contains(facility));
        }
        public void ShouldSetTheServiceLocator()
        {
            //Arrange
            ServiceLocator.SetLocatorProvider(() => null);
            var containerExtension = new WindsorExtension(registrationHelper, options);

            containerExtension.Run();

            //Act
            containerExtension.SetServiceLocator();
            var result = ServiceLocator.Current;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(WindsorServiceLocator));
        }
        public void ShouldRegisterWithTargetAndImplementationType()
        {
            //Arrange
            var container          = new WindsorContainer();
            var containerExtension = new WindsorExtension(registrationHelper, options);

            containerExtension.InitializeContainer(container);

            //Act
            containerExtension.Register <IBootstrapperAssemblyProvider, LoadedAssemblyProvider>();
            var result = container.Resolve <IBootstrapperAssemblyProvider>();

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(LoadedAssemblyProvider));
        }
        public void ShouldInitializeTheContainerToTheValuePassed()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);
            var container          = A.Fake <IWindsorContainer>();

            A.CallTo(() => container.AddFacility <FactorySupportFacility>()).Returns(container);

            //Act
            containerExtension.InitializeContainer(container);
            var result = containerExtension.Container;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IWindsorContainer));
            Assert.AreSame(result, container);
        }
        public void ShouldInvokeTheRegisterMethodOfAllIBootstrapperRegistrationTypes()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(AutoMapperRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            containerExtension.Run();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(containerExtension.Resolve <IProfileExpression>());
        }
        public void ShouldInvokeTheInstallMethodOfAllIWindsorInstallerTypes()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(TestWindsorInstaller));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var containerExtension = new WindsorExtension(registrationHelper, options);

            //Act
            containerExtension.Run();
            var result = containerExtension.Resolve <ITestInterface>();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ITestInterface));
        }
        public void ShouldResolveMultipleTypes()
        {
            //Arrange
            var containerExtension = new WindsorExtension(registrationHelper, options);
            var container          = A.Fake <IWindsorContainer>();
            var instances          = new[] { new object(), new object() };

            A.CallTo(() => container.AddFacility <FactorySupportFacility>()).Returns(container);
            A.CallTo(() => container.ResolveAll <object>()).Returns(instances);
            containerExtension.InitializeContainer(container);

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

            //Assert
            A.CallTo(() => container.ResolveAll <object>()).MustHaveHappened();
            Assert.IsNotNull(result);
            Assert.AreSame(instances, result);
        }
        public void ShouldRegisterAllTypesOfIBootstrapperRegistration()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(AutoMapperRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var containerExtension = new WindsorExtension(registrationHelper, options);

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

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsInstanceOfType(result, typeof(IEnumerable <IBootstrapperRegistration>));
            Assert.IsTrue(result.Any());
            Assert.IsTrue(result[0] is AutoMapperRegistration);
        }
        public void ShouldRegisterWithConventionAndWithRegistration()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(TestWindsorRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var containerExtension = new WindsorExtension(registrationHelper, options);

            A.CallTo(() => options.AutoRegistration).Returns(true);

            //Act
            containerExtension.Run();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(containerExtension.Resolve <WindsorExtension>());
            Assert.IsNotNull(containerExtension.Resolve <IRegisteredByConvention>());
        }
        public void RegisterAll_WhenInvokedWithNonGenericTargetType_ShouldRegisterType()
        {
            //Arrange
            var container          = new WindsorContainer();
            var containerExtension = new WindsorExtension(registrationHelper, options);

            containerExtension.AddFacility(new TypedFactoryFacility());
            containerExtension.InitializeContainer(container);
            var thisAssembly = Assembly.GetCallingAssembly();

            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.Resolve <IGenericTest <object> >();
            var result2 = container.Resolve <IGenericTest <string[]> >();

            //Assert
            result1.ShouldBeOfType <GenericTest <object> >();
            result2.ShouldBeOfType <GenericTest <string[]> >();
        }
 public static IBootstrapperContainerExtensionOptions Windsor(this BootstrapperExtensions extensions)
 {
     var extension = new WindsorExtension();
     extensions.Extension(extension);
     return extension.Options;
 }
 public static IBootstrapperContainerExtensionOptions Windsor(this BootstrapperExtensions extensions, IResolveAssemblies resolveAssemblies, BootstrapEnvironment bootstrapEnvironment)
 {
     var extension = new WindsorExtension(resolveAssemblies, bootstrapEnvironment);
     extensions.Extension(extension);
     return extension.Options;
 }