public void GenericServices_CanBeResolved_ByServiceInterface()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(GenericInterfacedService <>));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FindServices());

            Assert.That(engine.Resolve <IGenericService <int> >(), Is.InstanceOf <GenericInterfacedService <int> >());
            Assert.That(engine.Resolve <IGenericService <string> >(), Is.InstanceOf <GenericInterfacedService <string> >());
        }
        public void Requesting_NoConfigurations_DoesntResolveServices_ThatUsesConfigurations()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(HighService), typeof(LowService));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            var services = registrator.FilterServices(registrator.FindServices());

            registrator.RegisterServices(services);

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

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FindServices());

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

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            var services = registrator.FilterServices(registrator.FindServices(), "High", "Medium", "Low");

            registrator.RegisterServices(services);

            Assert.That(engine.ResolveAll <IBarometer>().Count(), Is.EqualTo(2));
        }
        public void RequstingConfiguration_AlsoRegisterd_ServicesWithoutConfiguration()
        {
            ITypeFinder finder = new Fakes.FakeTypeFinder(typeof(SelfService), typeof(HighService), typeof(LowService));

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);

            registrator.RegisterServices(registrator.FilterServices(registrator.FindServices(), "High"));

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

            DependencyAttributeRegistrator registrator = new DependencyAttributeRegistrator(finder, engine);
            var services = registrator.FilterServices(registrator.FindServices(), "High");

            registrator.RegisterServices(services);

            Assert.That(engine.Resolve <IBarometer>(), Is.InstanceOf <HighService>());
            Assert.That(engine.ResolveAll <IBarometer>().Count(), Is.EqualTo(1));
        }
        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>());
        }
        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 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> >());
        }