Commits

Anonymous committed 24485c9

Split ContainerBuilderFixture into fixtures according to the new builder structure.

Comments (0)

Files changed (11)

src/Autofac.Tests/Autofac.Tests.csproj

     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Builder\ActivatingHandlerFixture.cs" />
+    <Compile Include="Builder\ConcreteRegistrarFixture.cs" />
+    <Compile Include="Builder\ContainerRegistrationBuilderFixture.cs" />
+    <Compile Include="Builder\DelegateRegistrationBuilderFixture.cs" />
+    <Compile Include="Builder\FactoryRegistrationBuilderFixture.cs" />
+    <Compile Include="Builder\GenericRegistrationBuilderFixture.cs" />
+    <Compile Include="Builder\ProvidedInstanceRegistrationBuilderFixture.cs" />
+    <Compile Include="Builder\ReflectiveRegistrationBuilderFixture.cs" />
     <Compile Include="DisposerFixture.cs" />
     <Compile Include="Component\Registration\GenericRegistrationHandlerFixture.cs" />
     <Compile Include="Component\Scope\BaseContextScopeFixture.cs" />

src/Autofac.Tests/Builder/ActivatingHandlerFixture.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using Autofac.Builder;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class ActivatingHandlerFixture
+    {
+        class HasSetter
+        {
+            string _val;
+
+            public string Val
+            {
+                get
+                {
+                    return _val;
+                }
+                set
+                {
+                    _val = value;
+                }
+            }
+        }
+
+        [Test]
+        public void SetterInjection()
+        {
+            var val = "Value";
+
+            var builder = new ContainerBuilder();
+            builder.Register(val);
+            builder.Register<HasSetter>()
+                .OnActivating(ActivatingHandler.InjectProperties);
+
+            var container = builder.Build();
+
+            var instance = container.Resolve<HasSetter>();
+
+            Assert.IsNotNull(instance);
+            Assert.AreEqual(val, instance.Val);
+        }
+
+        class HasSetterWithValue
+        {
+            string _val = "Default";
+
+            public string Val
+            {
+                get
+                {
+                    return _val;
+                }
+                set
+                {
+                    _val = value;
+                }
+            }
+        }
+
+        [Test]
+        public void SetterInjectionWithValue()
+        {
+            var val = "Value";
+
+            var builder = new ContainerBuilder();
+            builder.Register(val);
+            builder.Register<HasSetterWithValue>()
+                .OnActivating(ActivatingHandler.InjectUnsetProperties);
+
+            var container = builder.Build();
+
+            var instance = container.Resolve<HasSetterWithValue>();
+
+            Assert.IsNotNull(instance);
+            Assert.AreEqual("Default", instance.Val);
+        }
+
+        class HasPropReadOnly
+        {
+            string _val = "Default";
+
+            public string Val
+            {
+                get
+                {
+                    return _val;
+                }
+                protected set
+                {
+                    _val = value;
+                }
+            }
+        }
+
+        [Test]
+        public void SetterInjectionReadOnly()
+        {
+            var val = "Value";
+
+            var builder = new ContainerBuilder();
+            builder.Register(val);
+            builder.Register<HasPropReadOnly>()
+                .OnActivating(ActivatingHandler.InjectProperties);
+
+            var container = builder.Build();
+
+            var instance = container.Resolve<HasPropReadOnly>();
+
+            Assert.IsNotNull(instance);
+            Assert.AreEqual(val, instance.Val);
+        }
+
+        [Test]
+        public void SetterInjectionUnsetReadOnly()
+        {
+            var val = "Value";
+
+            var builder = new ContainerBuilder();
+            builder.Register(val);
+            builder.Register<HasPropReadOnly>()
+                .OnActivating(ActivatingHandler.InjectUnsetProperties);
+
+            var container = builder.Build();
+
+            var instance = container.Resolve<HasPropReadOnly>();
+
+            Assert.IsNotNull(instance);
+            Assert.AreEqual("Default", instance.Val);
+        }
+
+        class HasPropWriteOnly
+        {
+            string _val;
+
+            public string Val
+            {
+                set
+                {
+                    _val = value;
+                }
+            }
+
+            public string GetVal()
+            {
+                return _val;
+            }
+        }
+
+        [Test]
+        public void SetterInjectionWriteOnly()
+        {
+            var val = "Value";
+
+            var builder = new ContainerBuilder();
+            builder.Register(val);
+            builder.Register<HasPropWriteOnly>()
+                .OnActivating(ActivatingHandler.InjectProperties);
+
+            var container = builder.Build();
+            var instance = container.Resolve<HasPropWriteOnly>();
+
+            Assert.IsNotNull(instance);
+            Assert.AreEqual(val, instance.GetVal());
+        }
+
+        [Test]
+        public void SetterInjectionUnsetWriteOnly()
+        {
+            var val = "Value";
+
+            var builder = new ContainerBuilder();
+            builder.Register(val);
+            builder.Register<HasPropWriteOnly>()
+                .OnActivating(ActivatingHandler.InjectUnsetProperties);
+
+            var container = builder.Build();
+            var instance = container.Resolve<HasPropWriteOnly>();
+
+            Assert.IsNotNull(instance);
+            Assert.AreEqual(val, instance.GetVal());
+        }
+
+    }
+}

src/Autofac.Tests/Builder/ConcreteRegistrarFixture.cs

+using System;
+using Autofac.Builder;
+using NUnit.Framework;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class ConcreteRegistrarFixture
+    {
+        interface IA { }
+        interface IB { }
+        interface IC { }
+
+        class Abc : DisposeTracker, IA, IB, IC { }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void RegisterTypeAsUnsupportedService()
+        {
+            new ContainerBuilder().Register<object>().As<string>();
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void RegisterTypeAsSupportedAndUnsupportedService()
+        {
+            new ContainerBuilder().Register<object>().As<object, string>();
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void RegisterInstanceAsUnsupportedService()
+        {
+            new ContainerBuilder().Register(new object()).As<string>();
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void RegisterDelegateAsUnsupportedService()
+        {
+            new ContainerBuilder().Register(c => new object()).As<string>();
+        }
+
+        [Test]
+        public void RegisterThreeServices()
+        {
+            var target = new ContainerBuilder();
+            target.Register<Abc>()
+                .As<IA, IB, IC>()
+                .WithScope(InstanceScope.Singleton);
+            var container = target.Build();
+            var a = container.Resolve<IA>();
+            var b = container.Resolve<IB>();
+            var c = container.Resolve<IC>();
+            Assert.IsNotNull(a);
+            Assert.AreSame(a, b);
+            Assert.AreSame(b, c);
+        }
+    }
+}

src/Autofac.Tests/Builder/ContainerBuilderFixture.cs

 		}
 
 		[Test]
-		[ExpectedException(typeof(ArgumentNullException))]
-		public void RegisterInstanceNull()
-		{
-			var builder = new ContainerBuilder();
-			builder.Register((object)null);
-		}
-
-		[Test]
-		[ExpectedException(typeof(ArgumentNullException))]
-		public void RegisterDelegateNull()
-		{
-			var target = new ContainerBuilder();
-			target.Register((ComponentActivator<object>)null);
-		}
-
-		[Test]
 		public void RegistrationOrderingPreserved()
 		{
 			var target = new ContainerBuilder();
 			Assert.AreSame(inst2, target.Build().Resolve<object>());
 		}
 
-		[Test]
-		[ExpectedException(typeof(ArgumentException))]
-		public void RegisterTypeAsUnsupportedService()
-		{
-			new ContainerBuilder().Register<object>().As<string>();
-		}
-
-		[Test]
-		[ExpectedException(typeof(ArgumentException))]
-		public void RegisterTypeAsSupportedAndUnsupportedService()
-		{
-			new ContainerBuilder().Register<object>().As<object, string>();
-		}
-
-		[Test]
-		[ExpectedException(typeof(ArgumentException))]
-		public void RegisterInstanceAsUnsupportedService()
-		{
-			new ContainerBuilder().Register(new object()).As<string>();
-		}
-
-		[Test]
-		[ExpectedException(typeof(ArgumentException))]
-		public void RegisterDelegateAsUnsupportedService()
-		{
-			new ContainerBuilder().Register(c => new object()).As<string>();
-		}
-
-		[Test]
-		public void RegisterThreeServices()
-		{
-			var target = new ContainerBuilder();
-			target.Register<Abc>()
-                .As<IA, IB, IC>()
-                .WithScope(InstanceScope.Singleton);
-			var container = target.Build();
-			var a = container.Resolve<IA>();
-			var b = container.Resolve<IB>();
-			var c = container.Resolve<IC>();
-			Assert.IsNotNull(a);
-			Assert.AreSame(a, b);
-			Assert.AreSame(b, c);
-		}
-
 		class ObjectModule : IModule
 		{
 			public bool ConfigureCalled { get; private set; }
 			target.Build();
 		}
 
-		[Test]
-		public void BuildGenericRegistration()
-		{
-			var cb = new ContainerBuilder();
-			cb.RegisterGeneric(typeof(List<>)).As(typeof(ICollection<>)).WithScope(InstanceScope.Factory);
-			var c = cb.Build();
-
-			ICollection<int> coll = c.Resolve<ICollection<int>>();
-			ICollection<int> coll2 = c.Resolve<ICollection<int>>();
-
-			Assert.IsNotNull(coll);
-			Assert.IsNotNull(coll2);
-			Assert.AreNotSame(coll, coll2);
-			Assert.IsTrue(coll.GetType().GetGenericTypeDefinition() == typeof(List<>));
-		}
-
-        class Parameterised
-        {
-            public string A { get; private set; }
-            public int B { get; private set; }
-
-            public Parameterised(string a, int b)
-            {
-                A = a;
-                B = b;
-            }
-        }
-
-        [Test]
-        public void RegisterParameterisedWithDelegate()
-        {
-            var cb = new ContainerBuilder();
-            cb.Register((c, p) => new Parameterised(p.Get<string>("a"), p.Get<int>("b")));
-            var container = cb.Build();
-            var aVal = "Hello";
-            var bVal = 42;
-            var result = container.Resolve<Parameterised>(
-                new Parameter("a", aVal),
-                new Parameter("b", bVal));
-            Assert.IsNotNull(result);
-            Assert.AreEqual(aVal, result.A);
-            Assert.AreEqual(bVal, result.B);
-        }
-
-        [Test]
-        public void RegisterParameterisedWithReflection()
-        {
-            var cb = new ContainerBuilder();
-            cb.Register<Parameterised>();
-            var container = cb.Build();
-            var aVal = "Hello";
-            var bVal = 42;
-            var result = container.Resolve<Parameterised>(
-                new Parameter("a", aVal),
-                new Parameter("b", bVal));
-            Assert.IsNotNull(result);
-            Assert.AreEqual(aVal, result.A);
-            Assert.AreEqual(bVal, result.B);
-        }
-        class HasSetter
-        {
-            string _val;
-
-            public string Val
-            {
-                get
-                {
-                    return _val;
-                }
-                set
-                {
-                    _val = value;
-                }
-            }
-        }
-
-        [Test]
-        public void SetterInjection()
-        {
-            var val = "Value";
-
-            var builder = new ContainerBuilder();
-            builder.Register(val);
-            builder.Register<HasSetter>()
-                .OnActivating(ActivatingHandler.InjectProperties);
-            
-            var container = builder.Build();
-
-            var instance = container.Resolve<HasSetter>();
-
-            Assert.IsNotNull(instance);
-            Assert.AreEqual(val, instance.Val);
-        }
-
-        class HasSetterWithValue
-        {
-            string _val = "Default";
-
-            public string Val
-            {
-                get
-                {
-                    return _val;
-                }
-                set
-                {
-                    _val = value;
-                }
-            }
-        }
-
-        [Test]
-        public void SetterInjectionWithValue()
-        {
-            var val = "Value";
-
-            var builder = new ContainerBuilder();
-            builder.Register(val);
-            builder.Register<HasSetterWithValue>()
-                .OnActivating(ActivatingHandler.InjectUnsetProperties);
-            
-            var container = builder.Build();
-            
-            var instance = container.Resolve<HasSetterWithValue>();
-
-            Assert.IsNotNull(instance);
-            Assert.AreEqual("Default", instance.Val);
-        }
-
-        class HasPropReadOnly
-        {
-            string _val = "Default";
-
-            public string Val
-            {
-                get
-                {
-                    return _val;
-                }
-                protected set
-                {
-                    _val = value;
-                }
-            }
-        }
-
-        [Test]
-        public void SetterInjectionReadOnly()
-        {
-            var val = "Value";
-
-            var builder = new ContainerBuilder();
-            builder.Register(val);
-            builder.Register<HasPropReadOnly>()
-                .OnActivating(ActivatingHandler.InjectProperties);
-
-            var container = builder.Build();
-
-            var instance = container.Resolve<HasPropReadOnly>();
-
-            Assert.IsNotNull(instance);
-            Assert.AreEqual(val, instance.Val);
-        }
-
-        [Test]
-        public void SetterInjectionUnsetReadOnly()
-        {
-            var val = "Value";
-
-            var builder = new ContainerBuilder();
-            builder.Register(val);
-            builder.Register<HasPropReadOnly>()
-                .OnActivating(ActivatingHandler.InjectUnsetProperties);
-
-            var container = builder.Build();
-
-            var instance = container.Resolve<HasPropReadOnly>();
-
-            Assert.IsNotNull(instance);
-            Assert.AreEqual("Default", instance.Val);
-        }
-
-        class HasPropWriteOnly
-        {
-            string _val;
-
-            public string Val
-            {
-                set
-                {
-                    _val = value;
-                }
-            }
-
-            public string GetVal()
-            {
-                return _val;
-            }
-        }
-
-        [Test]
-        public void SetterInjectionWriteOnly()
-        {
-            var val = "Value";
-
-            var builder = new ContainerBuilder();
-            builder.Register(val);
-            builder.Register<HasPropWriteOnly>()
-                .OnActivating(ActivatingHandler.InjectProperties);
-
-            var container = builder.Build();
-            var instance = container.Resolve<HasPropWriteOnly>();
-
-            Assert.IsNotNull(instance);
-            Assert.AreEqual(val, instance.GetVal());
-        }
-
-        [Test]
-        public void SetterInjectionUnsetWriteOnly()
-        {
-            var val = "Value";
-
-            var builder = new ContainerBuilder();
-            builder.Register(val);
-            builder.Register<HasPropWriteOnly>()
-                .OnActivating(ActivatingHandler.InjectUnsetProperties);
-
-            var container = builder.Build();
-            var instance = container.Resolve<HasPropWriteOnly>();
-
-            Assert.IsNotNull(instance);
-            Assert.AreEqual(val, instance.GetVal());
-        }
-
         class A1 { }
         class A2 { }
 
-        class TwoCtors
-        {
-            public Type[] CalledCtor { get; private set; }
-
-            public TwoCtors(A1 a1)
-            {
-                CalledCtor = new[] { typeof(A1) };
-            }
-
-            public TwoCtors(A1 a1, A2 a2)
-            {
-                CalledCtor = new[] { typeof(A1), typeof(A2) };
-            }
-        }
-
-        [Test]
-        public void ExplicitCtorCalled()
-        {
-            var cb = new ContainerBuilder();
-            cb.Register<A1>();
-            cb.Register<A2>();
-
-            var selected = new[]{ typeof(A1), typeof(A2) };
-
-            cb.Register<TwoCtors>()
-                .UsingConstructor(selected);
-
-            var c = cb.Build();
-            var result = c.Resolve<TwoCtors>();
-            Assert.IsNotNull(result);
-            Assert.AreEqual(typeof(TwoCtors).GetConstructor(selected),
-                typeof(TwoCtors).GetConstructor(result.CalledCtor));
-        }
-
-        [Test]
-        [ExpectedException(typeof(ArgumentException))]
-        public void ExplicitCtorNotPresent()
-        {
-            var cb = new ContainerBuilder();
-            cb.Register<TwoCtors>()
-                .UsingConstructor(typeof(A2));
-        }
-
-        [Test]
-        [ExpectedException(typeof(ArgumentNullException))]
-        public void ExplicitCtorNull()
-        {
-            var cb = new ContainerBuilder();
-            cb.Register<TwoCtors>()
-                .UsingConstructor(null);
-        }
-
-        class WithParam
-        {
-            public int I { get; private set; }
-            public WithParam(int i) { I = i; }
-        }
-
-        [Test]
-        public void ParametersProvided()
-        {
-            var ival = 10;
-
-            var cb = new ContainerBuilder();
-            cb.Register<WithParam>().
-                WithArguments(new Parameter("i", ival));
-
-            var c = cb.Build();
-            var result = c.Resolve<WithParam>();
-            Assert.IsNotNull(result);
-            Assert.AreEqual(ival, result.I);
-        }
-
-        class WithProp
-        {
-            public string Prop { get; set; }
-        }
-
-        [Test]
-        public void PropertyProvided()
-        {
-            var pval = "Hello";
-
-            var cb = new ContainerBuilder();
-            cb.Register<WithProp>()
-                .WithProperties(new Parameter("Prop", pval));
-
-            var c = cb.Build();
-
-            var result = c.Resolve<WithProp>();
-            Assert.IsNotNull(result);
-            Assert.AreEqual(pval, result.Prop);
-        }
-
         [Test]
         public void DefaultScopeChanged()
         {
         }
 
         [Test]
-        public void RegisterFactory()
-        {
-            var cb = new ContainerBuilder();
-            cb.Register<object>();
-            cb.RegisterFactory<Named.Factory>((c, p) =>
-                new Named(
-                    p.Get<string>("name"),
-                    c.Resolve<object>()));
-
-            var container = cb.Build();
-            Named.Factory factory = container.Resolve<Named.Factory>();
-            Assert.IsNotNull(factory);
-
-            string name = "Fred";
-            var fred = factory.Invoke(name);
-            Assert.IsNotNull(fred);
-            Assert.AreEqual(name, fred.Name);
-        }
-
-        [Test]
-        public void RegisterThroughFactory()
-        {
-            var cb = new ContainerBuilder();
-
-            cb.Register<object>();
-            cb.Register<Named>().ThroughFactory<Named.Factory>();
-
-            var container = cb.Build();
-       
-            Named.Factory factory = container.Resolve<Named.Factory>();
-            
-            Assert.IsNotNull(factory);
-            Assert.IsFalse(container.IsRegistered<Named>());
-            
-            string name = "Fred";
-            var fred = factory.Invoke(name);
-            Assert.IsNotNull(fred);
-            Assert.AreEqual(name, fred.Name);
-        }
-
-        [Test]
         public void RegisterWithName()
         {
             var name = "object.registration";
 
             object o2;
             Assert.IsFalse(c.TryResolve(typeof(object), out o2));
-            //Assert.IsNotNull(o2);
-        }
-
-        [Test]
-        public void RegisterCollection()
-        {
-            var builder = new ContainerBuilder();
-
-            builder.RegisterCollection<string>()
-                .As<IEnumerable<string>>()
-                .Named("my bag of string");
-
-            var s1 = "hello";
-            var s2 = "world";
-
-            builder.Register(s1)
-                .Named("my stringy string")
-                .MemberOf(typeof(IEnumerable<string>));
-
-            builder.Register(s2)
-                .Named("my slick string")
-                .MemberOf(typeof(IEnumerable<string>));
-
-            var container = builder.Build();
-
-            var strings = container.Resolve<IEnumerable<string>>();
-
-            Assert.AreEqual(2, strings.Count());
-            Assert.IsTrue(strings.Contains(s1));
-            Assert.IsTrue(strings.Contains(s2));
-        }
-
-        [Test]
-        public void NewCollectionInNewContext()
-        {
-            var builder = new ContainerBuilder();
-
-            builder.RegisterCollection<string>()
-                .As<IEnumerable<string>>()
-                .WithScope(InstanceScope.Container);
-
-            var outer = builder.Build();
-
-            var coll = outer.Resolve<IEnumerable<string>>();
-
-            Assert.IsNotNull(coll);
-            Assert.AreSame(coll, outer.Resolve<IEnumerable<string>>());
-
-            var inner = outer.CreateInnerContainer();
-
-            Assert.AreNotSame(coll, inner.Resolve<IEnumerable<string>>());
         }
     }
 }

src/Autofac.Tests/Builder/ContainerRegistrationBuilderFixture.cs

+using System.Collections.Generic;
+using System.Linq;
+using Autofac.Builder;
+using NUnit.Framework;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class ContainerRegistrationBuilderFixture
+    {
+        [Test]
+        public void RegisterCollection()
+        {
+            var builder = new ContainerBuilder();
+
+            builder.RegisterCollection<string>()
+                .As<IEnumerable<string>>()
+                .Named("my bag of string");
+
+            var s1 = "hello";
+            var s2 = "world";
+
+            builder.Register(s1)
+                .Named("my stringy string")
+                .MemberOf(typeof(IEnumerable<string>));
+
+            builder.Register(s2)
+                .Named("my slick string")
+                .MemberOf(typeof(IEnumerable<string>));
+
+            var container = builder.Build();
+
+            var strings = container.Resolve<IEnumerable<string>>();
+
+            Assert.AreEqual(2, strings.Count());
+            Assert.IsTrue(strings.Contains(s1));
+            Assert.IsTrue(strings.Contains(s2));
+        }
+
+        [Test]
+        public void NewCollectionInNewContext()
+        {
+            var builder = new ContainerBuilder();
+
+            builder.RegisterCollection<string>()
+                .As<IEnumerable<string>>()
+                .WithScope(InstanceScope.Container);
+
+            var outer = builder.Build();
+
+            var coll = outer.Resolve<IEnumerable<string>>();
+
+            Assert.IsNotNull(coll);
+            Assert.AreSame(coll, outer.Resolve<IEnumerable<string>>());
+
+            var inner = outer.CreateInnerContainer();
+
+            Assert.AreNotSame(coll, inner.Resolve<IEnumerable<string>>());
+        }
+    }
+}

src/Autofac.Tests/Builder/DelegateRegistrationBuilderFixture.cs

+using System;
+using Autofac.Builder;
+using NUnit.Framework;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class DelegateRegistrationBuilderFixture
+    {
+        [Test]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void RegisterDelegateNull()
+        {
+            var target = new ContainerBuilder();
+            target.Register((ComponentActivator<object>)null);
+        }
+    }
+}

src/Autofac.Tests/Builder/FactoryRegistrationBuilderFixture.cs

+using Autofac.Builder;
+using NUnit.Framework;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class FactoryRegistrationBuilderFixture
+    {
+        public class Named
+        {
+            public delegate Named Factory(string name);
+
+            public string Name { get; set; }
+
+            public Named(string name, object o)
+            {
+                Name = name;
+            }
+        }
+
+        [Test]
+        public void RegisterFactory()
+        {
+            var cb = new ContainerBuilder();
+            cb.Register<object>();
+            cb.RegisterFactory<Named.Factory>((c, p) =>
+                new Named(
+                    p.Get<string>("name"),
+                    c.Resolve<object>()));
+
+            var container = cb.Build();
+            Named.Factory factory = container.Resolve<Named.Factory>();
+            Assert.IsNotNull(factory);
+
+            string name = "Fred";
+            var fred = factory.Invoke(name);
+            Assert.IsNotNull(fred);
+            Assert.AreEqual(name, fred.Name);
+        }
+
+        [Test]
+        public void RegisterThroughFactory()
+        {
+            var cb = new ContainerBuilder();
+
+            cb.Register<object>();
+            cb.Register<Named>().ThroughFactory<Named.Factory>();
+
+            var container = cb.Build();
+
+            Named.Factory factory = container.Resolve<Named.Factory>();
+
+            Assert.IsNotNull(factory);
+            Assert.IsFalse(container.IsRegistered<Named>());
+
+            string name = "Fred";
+            var fred = factory.Invoke(name);
+            Assert.IsNotNull(fred);
+            Assert.AreEqual(name, fred.Name);
+        }
+
+    }
+}

src/Autofac.Tests/Builder/GenericRegistrationBuilderFixture.cs

+using System.Collections.Generic;
+using Autofac.Builder;
+using NUnit.Framework;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class GenericRegistrationBuilderFixture
+    {
+        [Test]
+        public void BuildGenericRegistration()
+        {
+            var cb = new ContainerBuilder();
+            cb.RegisterGeneric(typeof(List<>)).As(typeof(ICollection<>)).WithScope(InstanceScope.Factory);
+            var c = cb.Build();
+
+            ICollection<int> coll = c.Resolve<ICollection<int>>();
+            ICollection<int> coll2 = c.Resolve<ICollection<int>>();
+
+            Assert.IsNotNull(coll);
+            Assert.IsNotNull(coll2);
+            Assert.AreNotSame(coll, coll2);
+            Assert.IsTrue(coll.GetType().GetGenericTypeDefinition() == typeof(List<>));
+        }
+    }
+}

src/Autofac.Tests/Builder/ProvidedInstanceRegistrationBuilderFixture.cs

+using System;
+using Autofac.Builder;
+using NUnit.Framework;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class ProvidedInstanceRegistrationBuilderFixture
+    {
+        [Test]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void RegisterInstanceNull()
+        {
+            var builder = new ContainerBuilder();
+            builder.Register((object)null);
+        }
+    }
+}

src/Autofac.Tests/Builder/ReflectiveRegistrationBuilderFixture.cs

+using Autofac.Builder;
+using NUnit.Framework;
+using System;
+
+namespace Autofac.Tests.Builder
+{
+    [TestFixture]
+    public class ReflectiveRegistrationBuilderFixture
+    {
+        class A1 { }
+        class A2 { }
+
+        class TwoCtors
+        {
+            public Type[] CalledCtor { get; private set; }
+
+            public TwoCtors(A1 a1)
+            {
+                CalledCtor = new[] { typeof(A1) };
+            }
+
+            public TwoCtors(A1 a1, A2 a2)
+            {
+                CalledCtor = new[] { typeof(A1), typeof(A2) };
+            }
+        }
+
+        [Test]
+        public void ExplicitCtorCalled()
+        {
+            var cb = new ContainerBuilder();
+            cb.Register<A1>();
+            cb.Register<A2>();
+
+            var selected = new[] { typeof(A1), typeof(A2) };
+
+            cb.Register<TwoCtors>()
+                .UsingConstructor(selected);
+
+            var c = cb.Build();
+            var result = c.Resolve<TwoCtors>();
+            Assert.IsNotNull(result);
+            Assert.AreEqual(typeof(TwoCtors).GetConstructor(selected),
+                typeof(TwoCtors).GetConstructor(result.CalledCtor));
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentException))]
+        public void ExplicitCtorNotPresent()
+        {
+            var cb = new ContainerBuilder();
+            cb.Register<TwoCtors>()
+                .UsingConstructor(typeof(A2));
+        }
+
+        [Test]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void ExplicitCtorNull()
+        {
+            var cb = new ContainerBuilder();
+            cb.Register<TwoCtors>()
+                .UsingConstructor(null);
+        }
+
+        class WithParam
+        {
+            public int I { get; private set; }
+            public WithParam(int i) { I = i; }
+        }
+
+        [Test]
+        public void ParametersProvided()
+        {
+            var ival = 10;
+
+            var cb = new ContainerBuilder();
+            cb.Register<WithParam>().
+                WithArguments(new Parameter("i", ival));
+
+            var c = cb.Build();
+            var result = c.Resolve<WithParam>();
+            Assert.IsNotNull(result);
+            Assert.AreEqual(ival, result.I);
+        }
+
+        class WithProp
+        {
+            public string Prop { get; set; }
+        }
+
+        [Test]
+        public void PropertyProvided()
+        {
+            var pval = "Hello";
+
+            var cb = new ContainerBuilder();
+            cb.Register<WithProp>()
+                .WithProperties(new Parameter("Prop", pval));
+
+            var c = cb.Build();
+
+            var result = c.Resolve<WithProp>();
+            Assert.IsNotNull(result);
+            Assert.AreEqual(pval, result.Prop);
+        }
+    }
+}

src/Autofac.Tests/ContainerFixture.cs

             var c = cb.Build();
             var dbc = c.Resolve<DependsByCtor>();
         }
+
+        class Parameterised
+        {
+            public string A { get; private set; }
+            public int B { get; private set; }
+
+            public Parameterised(string a, int b)
+            {
+                A = a;
+                B = b;
+            }
+        }
+
+        [Test]
+        public void RegisterParameterisedWithDelegate()
+        {
+            var cb = new ContainerBuilder();
+            cb.Register((c, p) => new Parameterised(p.Get<string>("a"), p.Get<int>("b")));
+            var container = cb.Build();
+            var aVal = "Hello";
+            var bVal = 42;
+            var result = container.Resolve<Parameterised>(
+                new Parameter("a", aVal),
+                new Parameter("b", bVal));
+            Assert.IsNotNull(result);
+            Assert.AreEqual(aVal, result.A);
+            Assert.AreEqual(bVal, result.B);
+        }
+
+        [Test]
+        public void RegisterParameterisedWithReflection()
+        {
+            var cb = new ContainerBuilder();
+            cb.Register<Parameterised>();
+            var container = cb.Build();
+            var aVal = "Hello";
+            var bVal = 42;
+            var result = container.Resolve<Parameterised>(
+                new Parameter("a", aVal),
+                new Parameter("b", bVal));
+            Assert.IsNotNull(result);
+            Assert.AreEqual(aVal, result.A);
+            Assert.AreEqual(bVal, result.B);
+        }
     }
 }