Commit 5cc71a9

mo <mo@mokhan.ca>
2009-10-11 01:43:54
added specs around factory scope.
1 parent 328f67d
Changed files (7)
product/application.console/application.console/infrastructure/ComponentRegistration.cs
@@ -2,7 +2,7 @@ namespace gorilla.migrations.console.infrastructure
 {
     public interface ComponentRegistration
     {
-        void scope<T>() where T : Scope, new();
-        ComponentRegistration As<T>();
+        void scoped_as<T>() where T : Scope, new();
+        ComponentRegistration as_an<Contract>();
     }
 }
\ No newline at end of file
product/application.console/application.console/infrastructure/FactoryScope.cs → product/application.console/application.console/infrastructure/Factory.cs
@@ -2,7 +2,7 @@ using System;
 
 namespace gorilla.migrations.console.infrastructure
 {
-    public class FactoryScope : Scope
+    public class Factory : Scope
     {
         public object apply_to(Func<object> factory)
         {
product/application.console/application.console/infrastructure/GenericRegistration.cs
@@ -9,24 +9,19 @@ namespace gorilla.migrations.console.infrastructure
     {
         Func<Implementation> factory;
         ICollection<Type> contracts = new HashSet<Type>();
-        Scope contract_scope = new FactoryScope();
+        Scope contract_scope = new Factory();
 
         public GenericRegistration(Expression<Func<Implementation>> factory)
         {
             this.factory = factory.Compile();
         }
 
-        void scope(Scope scope)
+        public void scoped_as<Scope>() where Scope : infrastructure.Scope, new()
         {
-            contract_scope = scope;
+            contract_scope = new Scope();
         }
 
-        public void scope<Scope>() where Scope : infrastructure.Scope, new()
-        {
-            scope(new Scope());
-        }
-
-        public ComponentRegistration As<Contract>()
+        public ComponentRegistration as_an<Contract>()
         {
             contracts.Add(typeof (Contract));
             return this;
product/application.console/application.console/application.console.csproj
@@ -47,7 +47,7 @@
   <ItemGroup>
     <Compile Include="infrastructure\ComponentFactory.cs" />
     <Compile Include="infrastructure\Container.cs" />
-    <Compile Include="infrastructure\FactoryScope.cs" />
+    <Compile Include="infrastructure\Factory.cs" />
     <Compile Include="infrastructure\GenericRegistration.cs" />
     <Compile Include="infrastructure\ComponentRegistration.cs" />
     <Compile Include="infrastructure\Scope.cs" />
product/application.tests/console/infrastructure/FactorySpecs.cs
@@ -0,0 +1,25 @@
+using System;
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.harnesses.mbunit;
+using developwithpassion.bdddoc.core;
+using gorilla.migrations.console.infrastructure;
+
+namespace tests.console.infrastructure
+{
+    public class FactorySpecs
+    {
+        public abstract class concern : observations_for_a_sut_with_a_contract<Scope, Factory> {}
+
+        [Concern(typeof (Factory))]
+        public class when_building_a_component_using_a_factory_scope : concern
+        {
+            it should_return_a_new_instance_each_time = () =>
+            {
+                Func<object> factory = () => new object();
+                var first = controller.sut.apply_to(factory);
+                var second = controller.sut.apply_to(factory);
+                ReferenceEquals(first, second).should_be_false();
+            };
+        }
+    }
+}
\ No newline at end of file
product/application.tests/console/SimpleContainerSpecs.cs
@@ -28,7 +28,7 @@ namespace tests.console
         {
             context c = () =>
             {
-                builder.register(() => new Thingy()).As<IThingy>().scope<FactoryScope>();
+                builder.register(() => new Thingy()).as_an<IThingy>().scoped_as<Factory>();
             };
 
             because b = () =>
@@ -49,8 +49,8 @@ namespace tests.console
         {
             context c = () =>
             {
-                builder.register(() => new Thingy()).As<IThingy>();
-                builder.register(() => new AnotherThingy()).As<IThingy>();
+                builder.register(() => new Thingy()).as_an<IThingy>();
+                builder.register(() => new AnotherThingy()).as_an<IThingy>();
             };
 
             because b = () =>
product/application.tests/application.tests.csproj
@@ -69,6 +69,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="console\infrastructure\FactorySpecs.cs" />
     <Compile Include="console\SimpleContainerSpecs.cs" />
     <Compile Include="core\CommandRegistrySpecs.cs" />
     <Compile Include="core\ConsoleArgumentsSpecs.cs" />