Permalink
Browse files

Updated tests and lifetimes

  • Loading branch information...
1 parent 648a2cd commit c6946814362b01f5f56a89498ce1c6ea50d17d16 @grumpydev grumpydev committed Jul 25, 2011
View
2 .gitmodules
@@ -1,3 +1,3 @@
[submodule "dependencies/Nancy"]
path = dependencies/Nancy
- url = https://github.com/nancyfx/Nancy.git
+ url = https://github.com/NancyFx/Nancy.git
View
6 src/Nancy.Bootstrappers.Unity.Tests/FakeUnityNancyBootstrapper.cs
@@ -25,6 +25,12 @@ protected override void InitialiseInternal(IUnityContainer container)
container.RegisterType<IDependency, Dependency>(new ContainerControlledLifetimeManager());
}
+ protected override IUnityContainer CreateRequestContainer()
+ {
+ this.RequestContainerConfigured = true;
+ return base.CreateRequestContainer();
+ }
+
protected override void ConfigureApplicationContainer(IUnityContainer existingContainer)
{
ApplicationContainerConfigured = true;
View
7 src/Nancy.Bootstrappers.Unity.Tests/Nancy.Bootstrappers.Unity.Tests.csproj
@@ -61,9 +61,6 @@
<Compile Include="..\..\dependencies\Nancy\src\Nancy.Tests\ShouldExtensions.cs">
<Link>ShouldExtensions.cs</Link>
</Compile>
- <Compile Include="..\SharedAssemblyInfo.cs">
- <Link>Properties\SharedAssemblyInfo.cs</Link>
- </Compile>
<Compile Include="FakeUnityNancyBootstrapper.cs" />
<Compile Include="UnityNancyBootstrapperFixture.cs" />
</ItemGroup>
@@ -80,7 +77,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <Folder Include="Properties\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
73 src/Nancy.Bootstrappers.Unity.Tests/UnityNancyBootstrapperFixture.cs
@@ -30,7 +30,7 @@ public void GetEngine_ReturnsEngine()
}
[Fact]
- public void GetAllModules_Returns_As_MultiInstance()
+ public void GetAllModules_Returns_Same_Instance_With_Same_Context()
{
// Given
this.bootstrapper.GetEngine();
@@ -43,11 +43,29 @@ public void GetAllModules_Returns_As_MultiInstance()
// Then
output1.ShouldNotBeNull();
output2.ShouldNotBeNull();
+ output1.ShouldBeSameAs(output2);
+ }
+
+ [Fact]
+ public void GetAllModules_With_Different_Contexts_Returns_Different_Instances()
+ {
+ // Given
+ this.bootstrapper.GetEngine();
+ var context = new NancyContext();
+ var context2 = new NancyContext();
+
+ // When
+ var output1 = this.bootstrapper.GetAllModules(context).Where(nm => nm.GetType() == typeof(FakeNancyModuleWithBasePath)).FirstOrDefault();
+ var output2 = this.bootstrapper.GetAllModules(context2).Where(nm => nm.GetType() == typeof(FakeNancyModuleWithBasePath)).FirstOrDefault();
+
+ // Then
+ output1.ShouldNotBeNull();
+ output2.ShouldNotBeNull();
output1.ShouldNotBeSameAs(output2);
}
[Fact]
- public void GetModuleByKey_Returns_As_MultiInstance()
+ public void GetModuleByKey_Returns_Same_Instance_With_Same_Context()
{
// Given
this.bootstrapper.GetEngine();
@@ -60,7 +78,25 @@ public void GetModuleByKey_Returns_As_MultiInstance()
// Then
output1.ShouldNotBeNull();
output2.ShouldNotBeNull();
- output1.ShouldNotBeSameAs(output2);
+ output1.ShouldBeSameAs(output2);
+ }
+
+ [Fact]
+ public void Get_Module_By_Key_With_Different_Contexts_Returns_Different_Instances()
+ {
+ // Given
+ this.bootstrapper.GetEngine();
+ var context = new NancyContext();
+ var context2 = new NancyContext();
+
+ // When
+ var result = this.bootstrapper.GetModuleByKey(new DefaultModuleKeyGenerator().GetKeyForModuleType(typeof(FakeNancyModuleWithDependency)), context) as FakeNancyModuleWithDependency;
+ var result2 = this.bootstrapper.GetModuleByKey(new DefaultModuleKeyGenerator().GetKeyForModuleType(typeof(FakeNancyModuleWithDependency)), context2) as FakeNancyModuleWithDependency;
+
+ // Then
+ result.FooDependency.ShouldNotBeNull();
+ result2.FooDependency.ShouldNotBeNull();
+ result.ShouldNotBeSameAs(result2);
}
[Fact]
@@ -114,36 +150,5 @@ public void GetEngine_Defaults_Registered_In_Container()
this.bootstrapper.Container.Resolve<IRouteCache>();
this.bootstrapper.Container.Resolve<IRouteCacheProvider>();
}
-
- [Fact]
- public void Get_Module_By_Key_Gives_Same_Request_Lifetime_Instance_To_Each_Dependency()
- {
- // Given
- this.bootstrapper.GetEngine();
-
- // When
- var result = this.bootstrapper.GetModuleByKey(new DefaultModuleKeyGenerator().GetKeyForModuleType(typeof(FakeNancyModuleWithDependency)), new NancyContext()) as FakeNancyModuleWithDependency;
-
- // Then
- result.FooDependency.ShouldNotBeNull();
- result.FooDependency.ShouldBeSameAs(result.Dependency.FooDependency);
- }
-
- [Fact]
- public void Get_Module_By_Key_Gives_Different_Request_Lifetime_Instance_To_Each_Call()
- {
- // Given
- this.bootstrapper.GetEngine();
- var context = new NancyContext();
-
- // When
- var result = this.bootstrapper.GetModuleByKey(new DefaultModuleKeyGenerator().GetKeyForModuleType(typeof(FakeNancyModuleWithDependency)), context) as FakeNancyModuleWithDependency;
- var result2 = this.bootstrapper.GetModuleByKey(new DefaultModuleKeyGenerator().GetKeyForModuleType(typeof(FakeNancyModuleWithDependency)), context) as FakeNancyModuleWithDependency;
-
- // Then
- result.FooDependency.ShouldNotBeNull();
- result2.FooDependency.ShouldNotBeNull();
- result.FooDependency.ShouldNotBeSameAs(result2.FooDependency);
- }
}
}
View
3 src/Nancy.Bootstrappers.Unity/Nancy.Bootstrappers.Unity.csproj
@@ -49,7 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="..\SharedAssemblyInfo.cs">
+ <Compile Include="..\..\dependencies\Nancy\src\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="UnityEnumerableShim.cs" />
@@ -64,6 +64,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
3 src/Nancy.Bootstrappers.Unity/UnityNancyBootstrapper.cs
@@ -138,7 +138,8 @@ protected override void RegisterRequestContainerModules(IUnityContainer containe
container.RegisterType(
typeof(NancyModule),
moduleRegistrationType.ModuleType,
- moduleRegistrationType.ModuleKey);
+ moduleRegistrationType.ModuleKey,
+ new ContainerControlledLifetimeManager());
}
}

0 comments on commit c694681

Please sign in to comment.