Пример #1
0
        public void Constructor_WhenInvoked_ShouldNotInitializeTheContainer()
        {
            //Arrange
            var containerOptions = A.Fake <IBootstrapperContainerExtensionOptions>();

            //Act
            var result = new AutofacOptions(containerOptions);

            //Assert
            Assert.IsNull(result.Container);
        }
Пример #2
0
        public void UsingAutoRegistration_WhenInvoked_ShouldReturnTheSameAutofacOptions()
        {
            //Arrange
            var containerOptions = A.Fake <IBootstrapperContainerExtensionOptions>();
            var options          = new AutofacOptions(containerOptions);

            //Act
            var result = options.UsingAutoRegistration();

            //Assert
            Assert.AreSame(options, result);
        }
Пример #3
0
        public void UsingAutoRegistration_WhenInvoked_ShouldInvokeUsingAutoRegistrationInTheOptions()
        {
            //Arrange
            var containerOptions = A.Fake <IBootstrapperContainerExtensionOptions>();
            var options          = new AutofacOptions(containerOptions);

            //Act
            options.UsingAutoRegistration();

            //Assert
            A.CallTo(() => containerOptions.UsingAutoRegistration()).MustHaveHappened();
        }
Пример #4
0
        public void WithContainer_WhenInvoked_ShouldSetTheContainer()
        {
            //Arrange
            var container        = A.Fake <IContainer>();
            var containerOptions = A.Fake <IBootstrapperContainerExtensionOptions>();
            var options          = new AutofacOptions(containerOptions);

            //Act
            options.WithContainer(container);

            //Assert
            Assert.AreSame(container, options.Container);
        }
Пример #5
0
        public void Constructor_WhenInvoked_ShouldReturnAutofacOptions()
        {
            //Arrange
            var containerOptions = A.Fake <IBootstrapperContainerExtensionOptions>();

            //Act
            var result = new AutofacOptions(containerOptions);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(AutofacOptions));
            Assert.IsInstanceOfType(result, typeof(IBootstrapperContainerExtensionOptions));
        }
Пример #6
0
        public void AutoRegistration_WhenInvoked_ShouldReturnTheValueOfTheOptionsAutoRegistration()
        {
            //Arrange
            var containerOptions = A.Fake <IBootstrapperContainerExtensionOptions>();
            var options          = new AutofacOptions(containerOptions);

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

            //Act
            var result = options.AutoRegistration;

            //Assert
            Assert.IsTrue(result);
        }
Пример #7
0
        /// <summary>
        /// Use the KickStart extension to configure Autofac.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        /// <param name="configure">The <see langword="delegate"/> to configure Autofac options.</param>
        /// <returns>
        /// A fluent <see langword="interface" /> to configure KickStart.
        /// </returns>
        public static IConfigurationBuilder UseAutofac(this IConfigurationBuilder configurationBuilder, Action <IAutofacBuilder> configure)
        {
            var options = new AutofacOptions();
            var service = new AutofacStarter(options);

            if (configure != null)
            {
                var builder = new AutofacBuilder(options);
                configure(builder);
            }

            configurationBuilder.ExcludeName("Autofac");
            configurationBuilder.Use(service);

            return(configurationBuilder);
        }
Пример #8
0
        /// <summary>
        /// Use the KickStart extension to configure Autofac.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        /// <param name="configure">The <see langword="delegate"/> to configure Autofac options.</param>
        /// <returns>
        /// A fluent <see langword="interface" /> to configure KickStart.
        /// </returns>
        public static IConfigurationBuilder UseAutofac(this IConfigurationBuilder configurationBuilder, Action <IAutofacBuilder> configure)
        {
            var options = new AutofacOptions();
            var service = new AutofacStarter(options);

            if (configure != null)
            {
                var builder = new AutofacBuilder(options);
                configure(builder);
            }

            configurationBuilder.ExcludeAssemblyFor <AutofacStarter>();
            configurationBuilder.ExcludeAssemblyFor <global::Autofac.ContainerBuilder>();
            configurationBuilder.Use(service);

            return(configurationBuilder);
        }