Esempio n. 1
0
        /// <summary>ASP.NET Core version of setting up IoC and builders.</summary>
        /// <param name="mode">Always use ReCreate to recreate the IoC container before each test.</param>
        /// <param name="factoryFactory">The factory used to create a WebApplicationFactory&lt;T&gt; instance.</param>
        /// <param name="iocContainerFactory">Creates the IoC container, such as e.g. 'provider => new IocContainer(provider)'.</param>
        /// <typeparam name="T">The Startup class of the unit under test.</typeparam>
        public static void Initialize <T>(CleanContextMode mode, Func <WebApplicationFactory <T> > factoryFactory, Func <IServiceProvider, IIocContainer> iocContainerFactory) where T : class =>
        ContextBuilderFactory.Initialize(mode, () =>
        {
            _wrapped?.DisposeAndRemove();

            var factory = new FactoryWrapper <T>(factoryFactory);
            _wrapped    = factory;
            IServiceProvider serviceProvider = factory.GetFactory()?.Services;

            return(iocContainerFactory(serviceProvider));
        });
Esempio n. 2
0
        public ObjectCloner(IFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            IFactory<object> genericFactory = factory as IFactory<object>;

            if (genericFactory == null)
            {
                genericFactory = new FactoryWrapper(factory);
            }

            this.cloner = new ObjectCloner<object>(genericFactory);
        }