Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Objects/Factory/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/test/Spring/Spring.Web.Tests/Objects/Factory/Support
Modified Files:
WebObjectFactoryTests.cs
Log Message:
SPRNET-953
SPRNET-952
SPRNET-949
SPRNET-948
SPRNET-947
Index: WebObjectFactoryTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectFactoryTests.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** WebObjectFactoryTests.cs 14 Mar 2008 12:02:45 -0000 1.5
--- WebObjectFactoryTests.cs 29 May 2008 12:13:28 -0000 1.6
***************
*** 22,25 ****
--- 22,26 ----
using System;
+ using System.Collections;
using NUnit.Framework;
using Spring.Objects.Factory.Config;
***************
*** 33,36 ****
--- 34,40 ----
/// Unit tests for the WebObjectFactory class.
/// </summary>
+ /// <remarks>
+ /// TODO: added cache cleanup tests for exceptions during object creation
+ /// </remarks>
/// <author>Rick Evans</author>
/// <version>$Id$</version>
***************
*** 38,41 ****
--- 42,210 ----
public sealed class WebObjectFactoryTests
{
+ private class TestWebObjectFactory : WebObjectFactory
+ {
+ private readonly IDictionary _requestScopeCache;
+ private readonly IDictionary _sessionScopeCache;
+
+ public TestWebObjectFactory(string contextPath, bool caseSensitive)
+ : base(contextPath, caseSensitive)
+ {
+ _requestScopeCache = base.CreateObjectDictionary();
+ _sessionScopeCache = base.CreateObjectDictionary();
+ }
+
+ public IDictionary RequestScopeCache
+ {
+ get { return _requestScopeCache; }
+ }
+
+ public IDictionary SessionScopeCache
+ {
+ get { return _sessionScopeCache; }
+ }
+
+ protected override IDictionary Request
+ {
+ get { return _requestScopeCache; }
+ }
+
+ protected override IDictionary Session
+ {
+ get { return _sessionScopeCache; }
+ }
+ }
+
+ [Test]
+ public void RequestScopeCacheSensitivity()
+ {
+ using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true))
+ {
+ object testSingletonInstance = new object();
+
+ // case sensitive case
+ TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", true);
+ wof.RequestScopeCache.Add("myName", testSingletonInstance);
+ try
+ {
+ wof.GetObject("MyNAme");
+ Assert.Fail("should throw NoSuchObjectDefinitionException");
+ }
+ catch (NoSuchObjectDefinitionException)
+ { }
+
+ Assert.AreEqual(testSingletonInstance, wof.GetObject("myName"));
+
+ // case insensitive case
+ wof = new TestWebObjectFactory("/somedir/", false);
+ wof.RequestScopeCache.Add("myName", testSingletonInstance);
+
+ Assert.AreEqual(testSingletonInstance, wof.GetObject("MyNAme"));
+ Assert.AreEqual(testSingletonInstance, wof.GetObject("myName"));
+ }
+ }
+
+ [Test]
+ public void SessionScopeCacheSensitivity()
+ {
+ using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true))
+ {
+ object testSingletonInstance = new object();
+
+ // case sensitive case
+ TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", true);
+ wof.SessionScopeCache.Add("myName", testSingletonInstance);
+ try
+ {
+ wof.GetObject("MyNAme");
+ Assert.Fail("should throw NoSuchObjectDefinitionException");
+ }
+ catch (NoSuchObjectDefinitionException)
+ { }
+
+ Assert.AreEqual(testSingletonInstance, wof.GetObject("myName"));
+
+ // case insensitive case
+ wof = new TestWebObjectFactory("/somedir/", false);
+ wof.SessionScopeCache.Add("myName", testSingletonInstance);
+
+ Assert.AreEqual(testSingletonInstance, wof.GetObject("MyNAme"));
+ Assert.AreEqual(testSingletonInstance, wof.GetObject("myName"));
+ }
+ }
+
+ [Test]
+ public void SingletonCacheLookupOrder()
+ {
+ using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true))
+ {
+ object requestObject = new object();
+ object sessionObject = new object();
+ object applicationObject = new object();
+
+ // app is last
+ TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false);
+ wof.RegisterSingleton("myName", applicationObject);
+ Assert.AreEqual(applicationObject, wof.GetObject("myName"));
+
+ // session "overrides" app
+ wof.SessionScopeCache.Add("myName", sessionObject);
+ Assert.AreEqual(sessionObject, wof.GetObject("myName"));
+
+ // request "overrides" session
+ wof.RequestScopeCache.Add("myName", requestObject);
+ Assert.AreEqual(requestObject, wof.GetObject("myName"));
+ }
+ }
+
+ [Test]
+ public void RequestScopeDependencyCycleThrowsObjectCurrentlyInCreation()
+ {
+ using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true))
+ {
+ TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false);
+
+ RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(TestObject), new ConstructorArgumentValues(), new MutablePropertyValues());
+ rwod.Scope = ObjectScope.Request;
+ rwod.PropertyValues.Add( new PropertyValue("Sibling", new RuntimeObjectReference("requestScopedObject")) );
+ wof.RegisterObjectDefinition("requestScopedObject", rwod);
+
+ TestObject to = (TestObject) wof.GetObject("requestScopedObject");
+ Assert.AreSame( to, to.Sibling );
+ }
+ }
+
+ [Test]
+ public void SessionScopeDependencyCycleThrowsObjectCurrentlyInCreation()
+ {
+ using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true))
+ {
+ TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false);
+
+ RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(TestObject), new ConstructorArgumentValues(), new MutablePropertyValues());
+ rwod.Scope = ObjectScope.Session;
+ rwod.PropertyValues.Add( new PropertyValue("Sibling", new RuntimeObjectReference("sessionScopedObject")) );
+ wof.RegisterObjectDefinition("sessionScopedObject", rwod);
+
+ TestObject to = (TestObject) wof.GetObject("sessionScopedObject");
+ Assert.AreSame( to, to.Sibling );
+ }
+ }
+
+ [Test]
+ public void ApplicationScopeDependencyCycleBehaviorFromBaseFactory()
+ {
+ using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true))
+ {
+ TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false);
+
+ RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(TestObject), new ConstructorArgumentValues(), new MutablePropertyValues());
+ rwod.Scope = ObjectScope.Application;
+ rwod.PropertyValues.Add( new PropertyValue("Sibling", new RuntimeObjectReference("scopedObject")) );
+ wof.RegisterObjectDefinition("scopedObject", rwod);
+ TestObject to = (TestObject) wof.GetObject("scopedObject");
+ Assert.AreSame( to, to.Sibling );
+ }
+ }
+
[Test]
public void CanBeUsedOnNonWebThread()
|