summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mo@mokhan.ca>2009-10-10 19:43:54 -0600
committermo <mo@mokhan.ca>2009-10-10 19:43:54 -0600
commit5cc71a92c8df45e606b0c66a62fe3444c0936046 (patch)
treec4222ec9bae876f409dc7112a33325ae3d0647ee
parent328f67dfee816ef78de9e489032f1fc5cc35498b (diff)
added specs around factory scope.
-rw-r--r--product/application.console/application.console/application.console.csproj2
-rw-r--r--product/application.console/application.console/infrastructure/ComponentRegistration.cs4
-rw-r--r--product/application.console/application.console/infrastructure/Factory.cs (renamed from product/application.console/application.console/infrastructure/FactoryScope.cs)2
-rw-r--r--product/application.console/application.console/infrastructure/GenericRegistration.cs13
-rw-r--r--product/application.tests/application.tests.csproj1
-rw-r--r--product/application.tests/console/SimpleContainerSpecs.cs6
-rw-r--r--product/application.tests/console/infrastructure/FactorySpecs.cs25
7 files changed, 37 insertions, 16 deletions
diff --git a/product/application.console/application.console/application.console.csproj b/product/application.console/application.console/application.console.csproj
index 523e959..e8e69bc 100644
--- a/product/application.console/application.console/application.console.csproj
+++ b/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" />
diff --git a/product/application.console/application.console/infrastructure/ComponentRegistration.cs b/product/application.console/application.console/infrastructure/ComponentRegistration.cs
index c817c50..8606bbb 100644
--- a/product/application.console/application.console/infrastructure/ComponentRegistration.cs
+++ b/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
diff --git a/product/application.console/application.console/infrastructure/FactoryScope.cs b/product/application.console/application.console/infrastructure/Factory.cs
index 4d4b7ce..f6349a8 100644
--- a/product/application.console/application.console/infrastructure/FactoryScope.cs
+++ b/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)
{
diff --git a/product/application.console/application.console/infrastructure/GenericRegistration.cs b/product/application.console/application.console/infrastructure/GenericRegistration.cs
index 1efa510..9c1db6a 100644
--- a/product/application.console/application.console/infrastructure/GenericRegistration.cs
+++ b/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;
diff --git a/product/application.tests/application.tests.csproj b/product/application.tests/application.tests.csproj
index 1b08f65..8b8077d 100644
--- a/product/application.tests/application.tests.csproj
+++ 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" />
diff --git a/product/application.tests/console/SimpleContainerSpecs.cs b/product/application.tests/console/SimpleContainerSpecs.cs
index 5442c96..897eac4 100644
--- a/product/application.tests/console/SimpleContainerSpecs.cs
+++ b/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 = () =>
diff --git a/product/application.tests/console/infrastructure/FactorySpecs.cs b/product/application.tests/console/infrastructure/FactorySpecs.cs
new file mode 100644
index 0000000..44e5acf
--- /dev/null
+++ b/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