Ejemplo n.º 1
0
        public void AutofacContainerBuilder_WithTests_ForFactory_ThrowsException()
        {
            //Arrange
            var builder = new AutofacContainerBuilder();

            //Act
            Assert.Throws <TypeAccessException>(
                () => builder.ForFactory(x => new Foo())
                .WithResolvedParam(x => (string)null));
        }
        public void AutofacContainerBuilder_ForFactoryTests_ForFactory_RegisteredTypeComesFromDelegate()
        {
            //Arrange
            var autofacContainerBuilder = new AutofacContainerBuilder();

            //Act
            autofacContainerBuilder.ForFactory(x => new Foo());
            var resolver = autofacContainerBuilder.Build();

            //Assert
            Assert.IsNotNull(resolver.Resolve <Foo>());
        }
        public void AutofacContainerBuilder_ForFactoryTests_ForFactory_DelegateCanSetProperties()
        {
            //Arrange
            var autofacContainerBuilder = new AutofacContainerBuilder();

            //Act
            autofacContainerBuilder.ForFactory(x => new Foo()
            {
                Bar = new Bar()
            });
            var resolver = autofacContainerBuilder.Build();

            //Assert
            Assert.IsNotNull(resolver.Resolve <Foo>().Bar);
        }
Ejemplo n.º 4
0
        public void RebelAreaRegistrationReceivesMetadataFromIoC()
        {
            var codeBase     = Assembly.GetExecutingAssembly().CodeBase;
            var uri          = new Uri(codeBase);
            var path         = uri.LocalPath;
            var binFolder    = Path.GetDirectoryName(path);
            var settingsFile = new FileInfo(Path.Combine(binFolder, "web.config"));

            var autofacBuilder = new AutofacContainerBuilder();

            autofacBuilder.ForFactory(
                context => new RebelSettings(settingsFile))
            .KnownAsSelf();

            autofacBuilder.For <RebelAreaRegistration>()
            .KnownAsSelf()
            .WithResolvedParam(context => context.Resolve <IRouteHandler>("TreeRouteHandler"));

            //why is this here?

            var typeFinder         = new TypeFinder();
            var componentRegistrar = new RebelComponentRegistrar();

            componentRegistrar.RegisterEditorControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterMenuItems(autofacBuilder, typeFinder);
            //componentRegistrar.RegisterPackageActions(autofacBuilder, typeFinder);
            componentRegistrar.RegisterPropertyEditors(autofacBuilder, typeFinder);
            componentRegistrar.RegisterSurfaceControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterTreeControllers(autofacBuilder, typeFinder);

            //build the container
            var container = autofacBuilder.Build();

            var result = container.Resolve <RebelAreaRegistration>();

            Assert.IsNotNull(result);
        }
        public void UmbracoAreaRegistrationReceivesMetadataFromIoC()
        {
            var codeBase = Assembly.GetExecutingAssembly().CodeBase;
            var uri = new Uri(codeBase);
            var path = uri.LocalPath;
            var binFolder = Path.GetDirectoryName(path);
            var settingsFile = new FileInfo(Path.Combine(binFolder, "web.config"));

            var autofacBuilder = new AutofacContainerBuilder();

            autofacBuilder.ForFactory(
                context => new UmbracoSettings(settingsFile))
                .KnownAsSelf();

            autofacBuilder.For<UmbracoAreaRegistration>()
                .KnownAsSelf()
                .WithResolvedParam(context => context.Resolve<IRouteHandler>("TreeRouteHandler"));

            //why is this here? 

            var typeFinder = new TypeFinder();
            var componentRegistrar = new UmbracoComponentRegistrar();
            componentRegistrar.RegisterEditorControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterMenuItems(autofacBuilder, typeFinder);
            //componentRegistrar.RegisterPackageActions(autofacBuilder, typeFinder);
            componentRegistrar.RegisterPropertyEditors(autofacBuilder, typeFinder);
            componentRegistrar.RegisterSurfaceControllers(autofacBuilder, typeFinder);
            componentRegistrar.RegisterTreeControllers(autofacBuilder, typeFinder);

            //build the container
            var container = autofacBuilder.Build();

            var result = container.Resolve<UmbracoAreaRegistration>();

            Assert.IsNotNull(result);
        }