public void CanResolve_MultipleServices()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            var services = container.ResolveAll<IBarometer>();
            Assert.That(services.Count(), Is.EqualTo(2));
        }
        public void Plugin_WithoutInitializerDefinition_IsNotInvoked()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(PlugIn3) });

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);
            invoker.InitializePlugins(null, invoker.GetPluginDefinitions());

            Assert.That(PlugIn3.WasInitialized, Is.False);
        }
        public void GenericServices_CanBeResolved()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericSelfService<>));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            registrator.RegisterServices(registrator.FindServices());

            Assert.That(engine.Resolve<GenericSelfService<int>>(), Is.InstanceOf<GenericSelfService<int>>());
            Assert.That(engine.Resolve<GenericSelfService<string>>(), Is.InstanceOf<GenericSelfService<string>>());
        }
        public void AutoInitializePlugin_IsInvoked()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(PlugIn2) });

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);
            PlugIn2.WasInitialized = false;
            invoker.InitializePlugins(null, invoker.GetPluginDefinitions());

            Assert.That(PlugIn2.WasInitialized, Is.True);
        }
        public void CanDependOn_MultipleServices()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());
            container.AddComponent("bw", typeof(BarometerWatcher), typeof(BarometerWatcher));

            var watcher = container.Resolve<BarometerWatcher>();
            Assert.That(watcher.Barometers.Count(), Is.EqualTo(2));
        }
示例#6
0
        public void GenericServices_CanBeResolved_ByServiceInterface()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericInterfacedService<>));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            Assert.That(container.Resolve<IGenericService<int>>(), Is.InstanceOf<GenericInterfacedService<int>>());
            Assert.That(container.Resolve<IGenericService<string>>(), Is.InstanceOf<GenericInterfacedService<string>>());
        }
        public void Services_AreAdded_ToTheContainer()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService), typeof(NonAttributed));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            Assert.That(container.Resolve<SelfService>(), Is.InstanceOf<SelfService>());
            Assert.That(new TestDelegate(() => container.Resolve<NonAttributed>()), Throws.Exception);
        }
        public void Services_CanDepend_OnEachOther()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService), typeof(DependingService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            var service = container.Resolve<DependingService>();
            Assert.That(service, Is.InstanceOf<DependingService>());
            Assert.That(service.service, Is.InstanceOf<SelfService>());
        }
        public void CanResolve_ServiceWithDependency_OnComponentInstance()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(DependingServiceWithMissingDependency).Assembly.GetTypes());
            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            registrator.RegisterServices(registrator.FindServices());

            engine.ContainerManager.AddComponentInstance<UnregisteredDependency>(new UnregisteredDependency(), "ud");

            var service = engine.Resolve<DependingServiceWithMissingDependency>();
            Assert.That(service, Is.InstanceOf<DependingServiceWithMissingDependency>());
        }
        public void GenericServices_CanDepend_OnEachOther()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericSelfService<>), typeof(GenericDependingService));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            registrator.RegisterServices(registrator.FindServices());

            var service = engine.Resolve<GenericDependingService>();
            Assert.That(service, Is.InstanceOf<GenericDependingService>());
            Assert.That(service.service, Is.InstanceOf<GenericSelfService<int>>());
        }
        public void CanResolve_ServiceWithDependency_OnComponentInstance()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(DependingServiceWithMissingDependency).Assembly.GetTypes());
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            container.AddComponentInstance("ud", typeof(UnregisteredDependency), new UnregisteredDependency());

            var service = container.Resolve<DependingServiceWithMissingDependency>();
            Assert.That(service, Is.InstanceOf<DependingServiceWithMissingDependency>());
        }
        public void Services_AreAdded_ToTheContainer_WithServiceType()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(InterfacedService), typeof(NonAttributed));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            registrator.RegisterServices(registrator.FindServices());

            Assert.That(engine.Resolve<IService>(), Is.Not.Null);
            Assert.That(engine.Resolve<IService>(), Is.InstanceOf<InterfacedService>());
            Assert.That(new TestDelegate(() => engine.Resolve<NonAttributed>()), Throws.Exception);
        }
        public void Services_AreSingletons()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            var one = container.Resolve<SelfService>();
            var two = container.Resolve<SelfService>();
            
            Assert.That(object.ReferenceEquals(one, two));
        }
        public void Services_AreSingletons()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            registrator.RegisterServices(registrator.FindServices());

            var one = engine.Resolve<SelfService>();
            var two = engine.Resolve<SelfService>();

            Assert.That(object.ReferenceEquals(one, two));
        }
示例#15
0
        public void Service_CanDecorate_ServiceOfSameType()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(DecoratingService), typeof(InterfacedService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);

            registrator.RegisterServices(registrator.FindServices());

            var service = container.Resolve <IService>();

            Assert.That(service, Is.InstanceOf <DecoratingService>());
            Assert.That(((DecoratingService)service).decorated, Is.InstanceOf <InterfacedService>());
        }
        public void CanResolve_ServiceWithDependency_OnComponentInstance()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(DependingServiceWithMissingDependency).Assembly.GetTypes());
            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FindServices());

            engine.ContainerManager.AddComponentInstance <UnregisteredDependency>(new UnregisteredDependency(), "ud");

            var service = engine.Resolve <DependingServiceWithMissingDependency>();

            Assert.That(service, Is.InstanceOf <DependingServiceWithMissingDependency>());
        }
示例#17
0
        public void CanResolve_ServiceWithDependency_OnComponentInstance()
        {
            ITypeFinder        finder      = new Fakes.FakeTypeFinder(typeof(DependingServiceWithMissingDependency).Assembly.GetTypes());
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);

            registrator.RegisterServices(registrator.FindServices());

            container.AddComponentInstance("ud", typeof(UnregisteredDependency), new UnregisteredDependency());

            var service = container.Resolve <DependingServiceWithMissingDependency>();

            Assert.That(service, Is.InstanceOf <DependingServiceWithMissingDependency>());
        }
示例#18
0
        public void Services_AreSingletons()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);

            registrator.RegisterServices(registrator.FindServices());

            var one = container.Resolve <SelfService>();
            var two = container.Resolve <SelfService>();

            Assert.That(object.ReferenceEquals(one, two));
        }
        public void Services_AreSingletons()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FindServices());

            var one = engine.Resolve <SelfService>();
            var two = engine.Resolve <SelfService>();

            Assert.That(object.ReferenceEquals(one, two));
        }
        public void Services_CanDepend_OnEachOther()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService), typeof(DependingService));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FindServices());

            var service = engine.Resolve <DependingService>();

            Assert.That(service, Is.InstanceOf <DependingService>());
            Assert.That(service.service, Is.InstanceOf <SelfService>());
        }
示例#21
0
        public void AutoInitialized_PluginInitializers_CanBeRemoved_UsingConfiguration_ByType()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(typeof(PlugIn1).Assembly, new[] { typeof(PlugIn2) });

            EngineSection config = CreateConfiguration(null, new[]
            {
                new PluginInitializerElement { Name = "ignored", Type = typeof(PlugIn2).AssemblyQualifiedName }
            });
            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder, config);
            invoker.InitializePlugins(null, invoker.GetPluginDefinitions());

            Assert.That(PlugIn2.WasInitialized, Is.False);
        }
示例#22
0
        public void GenericServices_CanDepend_OnEachOther()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericSelfService <>), typeof(GenericDependingService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);

            registrator.RegisterServices(registrator.FindServices());

            var service = container.Resolve <GenericDependingService>();

            Assert.That(service, Is.InstanceOf <GenericDependingService>());
            Assert.That(service.service, Is.InstanceOf <GenericSelfService <int> >());
        }
        public void Services_CanDepend_OnGenericServiceInterface()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericInterfaceDependingService), typeof(GenericInterfacedService <>));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FindServices());

            var service = engine.Resolve <GenericInterfaceDependingService>();

            Assert.That(service, Is.InstanceOf <GenericInterfaceDependingService>());
            Assert.That(service.service, Is.InstanceOf <GenericInterfacedService <int> >());
        }
        public void CanRegister_MultipleServices_DependingOnSame_ServiceArray()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());
            container.AddComponent("bw", typeof(BarometerWatcher), typeof(BarometerWatcher));
            container.AddComponent("ac", typeof(AltitudeComparer), typeof(AltitudeComparer));

            var watcher = container.Resolve<BarometerWatcher>();
            var comparer = container.Resolve<AltitudeComparer>();

            Assert.That(watcher.Barometers[0], Is.SameAs(comparer.Barometers[0]));
            Assert.That(watcher.Barometers[1], Is.SameAs(comparer.Barometers[1]));
        }
示例#25
0
        public void CanRegister_MultipleServices_DependingOnSame_ServiceArray()
        {
            ITypeFinder        finder      = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);

            registrator.RegisterServices(registrator.FindServices());
            container.AddComponent("bw", typeof(BarometerWatcher), typeof(BarometerWatcher));
            container.AddComponent("ac", typeof(AltitudeComparer), typeof(AltitudeComparer));

            var watcher  = container.Resolve <BarometerWatcher>();
            var comparer = container.Resolve <AltitudeComparer>();

            Assert.That(watcher.Barometers[0], Is.SameAs(comparer.Barometers[0]));
            Assert.That(watcher.Barometers[1], Is.SameAs(comparer.Barometers[1]));
        }
示例#26
0
        public void AutoInitialized_PluginInitializers_CanBeRemoved_UsingConfiguration_ByType()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(typeof(PlugIn1).Assembly, new[] { typeof(PlugIn2) });

            EngineSection config = CreateConfiguration(null, new[]
            {
                new PluginInitializerElement {
                    Name = "ignored", Type = typeof(PlugIn2).AssemblyQualifiedName
                }
            });
            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder, config);

            invoker.InitializePlugins(null, invoker.GetPluginDefinitions());

            Assert.That(PlugIn2.WasInitialized, Is.False);
        }
示例#27
0
        public void Plugins_CanBeInitialized_FromConfiguration()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(typeof(PlugIn1).Assembly, new[] { typeof(PlugIn3) });

            EngineSection config = CreateConfiguration(new[]
            {
                new PluginInitializerElement {
                    Name = "ignored", Type = typeof(PlugIn3).AssemblyQualifiedName
                }
            }, null);
            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder, config);

            invoker.InitializePlugins(null, invoker.GetPluginDefinitions());

            Assert.That(PlugIn3.WasInitialized, Is.True);
        }
        public void Initializers_AreExecuted_AfterException()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) });

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);
            PlugIn2.WasInitialized = false;

            ThrowingPlugin1.Throw = true;
            PluginInitializationException ex = ExceptionAssert.Throws<PluginInitializationException>(delegate
            {
                invoker.InitializePlugins(null, invoker.GetPluginDefinitions());
            });
            ThrowingPlugin1.Throw = false;

            Assert.That(PlugIn2.WasInitialized, Is.True);
        }
示例#29
0
        public void Initializers_AreExecuted_AfterException()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) });

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);

            PlugIn2.WasInitialized = false;

            ThrowingPlugin1.Throw = true;
            PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate
            {
                invoker.InitializePlugins(null, invoker.GetPluginDefinitions());
            });

            ThrowingPlugin1.Throw = false;

            Assert.That(PlugIn2.WasInitialized, Is.True);
        }
        public void InnerException_IsInnerException_OfInitializationException()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) });

            mocks.ReplayAll();

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);
            PlugIn2.WasInitialized = false;

            ThrowingPlugin1.Throw = true;
            PluginInitializationException ex = ExceptionAssert.Throws<PluginInitializationException>(delegate
            {
                invoker.InitializePlugins(null, invoker.GetPluginDefinitions());
            });
            ThrowingPlugin1.Throw = false;

            Assert.That(ex.InnerException, Is.TypeOf(typeof(SomeException)));
            Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy."));
        }
示例#31
0
        public void Services_AreAdded_ToTheContainer_WithServiceType()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(InterfacedService), typeof(NonAttributed));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);

            registrator.RegisterServices(registrator.FindServices());

            Assert.That(container.Resolve <IService>(), Is.Not.Null);
            Assert.That(container.Resolve <IService>(), Is.InstanceOf <InterfacedService>());
            try
            {
                var instance = container.Resolve <NonAttributed>();
                Assert.Fail();
            }
            catch (Exception)
            {
                // expected
            }
        }
示例#32
0
        public void InnerException_IsInnerException_OfInitializationException()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) });

            mocks.ReplayAll();

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);

            PlugIn2.WasInitialized = false;

            ThrowingPlugin1.Throw = true;
            PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate
            {
                invoker.InitializePlugins(null, invoker.GetPluginDefinitions());
            });

            ThrowingPlugin1.Throw = false;

            Assert.That(ex.InnerException, Is.TypeOf(typeof(SomeException)));
            Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy."));
        }
示例#33
0
        public void InnerExceptions_AreAdded_ToInitializationException()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2), typeof(ThrowingPlugin2) });

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);

            PlugIn2.WasInitialized = false;

            ThrowingPlugin1.Throw = true;
            ThrowingPlugin2.Throw = true;
            PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate
            {
                invoker.InitializePlugins(null, invoker.GetPluginDefinitions());
            });

            ThrowingPlugin1.Throw = false;
            ThrowingPlugin2.Throw = false;

            Assert.That(ex.InnerExceptions.Length, Is.EqualTo(2));
            Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy."));
            Assert.That(ex.Message.Contains("ThrowingPlugin2 is really mad."));
        }
        public void Services_DependingOn_MultipleServices_CanBeSingletons()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));
            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());
            container.AddComponent("bw", typeof(BarometerWatcher), typeof(BarometerWatcher));

            var watcher = container.Resolve<BarometerWatcher>();
            var watcher2 = container.Resolve<BarometerWatcher>();
            Assert.That(watcher, Is.SameAs(watcher));
        }
        public void Plugins_CanBeInitialized_FromConfiguration()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(typeof(PlugIn1).Assembly, new[] { typeof(PlugIn3) });

            EngineSection config = CreateConfiguration(new[]
            {
                new PluginInitializerElement { Name = "ignored", Type = typeof(PlugIn3).AssemblyQualifiedName }
            }, null);
            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder, config);
            invoker.InitializePlugins(null, invoker.GetPluginDefinitions());

            Assert.That(PlugIn3.WasInitialized, Is.True);
        }
        public void Requesting_MultipleConfigurations_GivesAllMatchingServices()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            var services = registrator.FilterServices(registrator.FindServices(), "High", "Medium", "Low");
            registrator.RegisterServices(services);

            Assert.That(container.ResolveAll<IBarometer>().Count(), Is.EqualTo(2));
        }
        public void Services_CanDepend_OnGenericServiceInterface()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericInterfaceDependingService), typeof(GenericInterfacedService<>));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            var service = container.Resolve<GenericInterfaceDependingService>();
            Assert.That(service, Is.InstanceOf<GenericInterfaceDependingService>());
            Assert.That(service.service, Is.InstanceOf<GenericInterfacedService<int>>());
        }
        public void Service_CanDecorate_ServiceOfSameType()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(DecoratingService), typeof(InterfacedService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            var service = container.Resolve<IService>();

            Assert.That(service, Is.InstanceOf<DecoratingService>());
            Assert.That(((DecoratingService)service).decorated, Is.InstanceOf<InterfacedService>());
        }
 private void FindAndRegister(params Type[] types)
 {
     ITypeFinder finder = new Fakes.FakeTypeFinder(types);
     ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
     registrator.RegisterServices(registrator.FindServices());
 }
        public void Services_CanOverride_OtherServices_ByServiceType()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(ReplacedService), typeof(ReplacingReplacedService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FilterServices(registrator.FindServices()));

            Assert.That(container.Resolve<IReplacedInterface>(), Is.InstanceOf<ReplacingReplacedService>());
            Assert.That(container.ResolveAll<IReplacedInterface>().Count(), Is.EqualTo(1));
        }
        public void RequstingConfiguration_AlsoRegisterd_ServicesWithoutConfiguration()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService), typeof(HighService), typeof(LowService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FilterServices(registrator.FindServices(), "High"));

            Assert.That(container.Resolve<SelfService>(), Is.InstanceOf<SelfService>());
            Assert.That(container.Resolve<IBarometer>(), Is.InstanceOf<HighService>());
            Assert.That(container.ResolveAll<IBarometer>().Count(), Is.EqualTo(1));
        }
        public void Requesting_NoConfigurations_DoesntResolveServices_ThatUsesConfigurations()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            var services = registrator.FilterServices(registrator.FindServices());
            registrator.RegisterServices(services);

            Assert.That(container.ResolveAll<IBarometer>().Count(), Is.EqualTo(0));
        }
        public void Services_AreAdded_ToTheContainer_WithServiceType()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(InterfacedService), typeof(NonAttributed));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            registrator.RegisterServices(registrator.FindServices());

            Assert.That(container.Resolve<IService>(), Is.Not.Null);
            Assert.That(container.Resolve<IService>(), Is.InstanceOf<InterfacedService>());
            try
            {
                var instance = container.Resolve<NonAttributed>();
                Assert.Fail();
            }
            catch (Exception)
            {
                // expected
            }
        }
        public void InnerExceptions_AreAdded_ToInitializationException()
        {
            ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2), typeof(ThrowingPlugin2)});

            PluginBootstrapper invoker = new PluginBootstrapper(typeFinder);
            PlugIn2.WasInitialized = false;

            ThrowingPlugin1.Throw = true;
            ThrowingPlugin2.Throw = true;
            PluginInitializationException ex = ExceptionAssert.Throws<PluginInitializationException>(delegate
            {
                invoker.InitializePlugins(null, invoker.GetPluginDefinitions());
            });
            ThrowingPlugin1.Throw = false; 
            ThrowingPlugin2.Throw = false; 

            Assert.That(ex.InnerExceptions.Length, Is.EqualTo(2));
            Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy."));
            Assert.That(ex.Message.Contains("ThrowingPlugin2 is really mad."));
        }
        public void Resolves_OnlyRequestedConfiguration()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));

            ServiceRegistrator registrator = new ServiceRegistrator(finder, container);
            var services = registrator.FilterServices(registrator.FindServices(), "High");
            registrator.RegisterServices(services);

            Assert.That(container.Resolve<IBarometer>(), Is.InstanceOf<HighService>());
            Assert.That(container.ResolveAll<IBarometer>().Count(), Is.EqualTo(1));
        }