public void ConfigureScopesFromAttributesThrowsIfServiceHasMultipleScopes()
        {
            var types = new[] { typeof(ServiceWithMultipleScopes) };
            var generatorMock = new Mock<IBindingGenerator>();
            var bindingMocks = new[] { CreateBindingMock(), CreateBindingMock() };

            this.SetupTypeFilterGetTypes(types);
            generatorMock.Setup(g => g.CreateBindings(typeof(ServiceWithMultipleScopes), this.bindingRoot)).Returns(bindingMocks.Select(b => b.Object));

            this.testee.SelectAllTypesFrom(new Assembly[0]);
            this.testee.BindWith(generatorMock.Object);


            Assert.Throws<InvalidOperationException>(() => this.testee.ConfigureScopesFromAttributes());
        }
        public void ConfigureForWithService()
        {
            var types = new[] { typeof(int), typeof(object) };
            var generatorMock = new Mock<IBindingGenerator>();
            var intBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() };
            var objectBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() };

            this.SetupTypeFilterGetTypes(types);
            generatorMock.Setup(g => g.CreateBindings(typeof(int), this.bindingRoot)).Returns(intBindingMocks.Select(b => b.Object));
            generatorMock.Setup(g => g.CreateBindings(typeof(object), this.bindingRoot)).Returns(objectBindingMocks.Select(b => b.Object));

            this.testee.SelectAllTypesFrom(new Assembly[0]);
            this.testee.BindWith(generatorMock.Object);
            this.testee.ConfigureFor<int>((c, s) => c.InSingletonScope());

            foreach (var bindingMock in intBindingMocks)
            {
                bindingMock.Verify(b => b.InSingletonScope());
            }

            foreach (var bindingMock in objectBindingMocks)
            {
                bindingMock.Verify(b => b.InSingletonScope(), Times.Never());
            }
        }
        public void ConfigureScopesFromAttributes()
        {
            var types = new[] { typeof(SingletonScopedService), typeof(ThreadScopedService), typeof(TransientScopedService) };
            var generatorMock = new Mock<IBindingGenerator>();
            var singletonScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() };
            var threadScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() };
            var transientScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() };

            this.SetupTypeFilterGetTypes(types);
            generatorMock.Setup(g => g.CreateBindings(typeof(SingletonScopedService), this.bindingRoot)).Returns(singletonScopedBindingMocks.Select(b => b.Object));
            generatorMock.Setup(g => g.CreateBindings(typeof(ThreadScopedService), this.bindingRoot)).Returns(threadScopedBindingMocks.Select(b => b.Object));
            generatorMock.Setup(g => g.CreateBindings(typeof(TransientScopedService), this.bindingRoot)).Returns(transientScopedBindingMocks.Select(b => b.Object));

            this.testee.SelectAllTypesFrom(new Assembly[0]);
            this.testee.BindWith(generatorMock.Object);
            this.testee.ConfigureScopesFromAttributes();

            foreach (var bindingMock in singletonScopedBindingMocks)
            {
                bindingMock.Verify(b => b.InSingletonScope());
            }

            foreach (var bindingMock in threadScopedBindingMocks)
            {
                bindingMock.Verify(b => b.InThreadScope());
            }

            foreach (var bindingMock in transientScopedBindingMocks)
            {
                bindingMock.Verify(b => b.InTransientScope());
            }
        }