rework of result navigation support: sprnet-1040, sprnet-1052, sprnet-958, sprnet-567
added navigation demo to WebQuickStart
This commit is contained in:
@@ -328,6 +328,11 @@
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Web\Support\ResultFactoryRegistryTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Web\Support\ResultTests.cs"
|
||||
SubType = "Code"
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
<Compile Include="Web\Support\AbstractHandlerFactoryTests.cs" />
|
||||
<Compile Include="Web\Support\MimeMediaTypeTests.cs" />
|
||||
<Compile Include="Web\Support\PageHandlerFactoryTests.cs" />
|
||||
<Compile Include="Web\Support\ResultFactoryRegistryTests.cs" />
|
||||
<Compile Include="Web\Support\ResultTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Web.Support
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <author>Erich Eichinger</author>
|
||||
[TestFixture]
|
||||
public class ResultFactoryRegistryTests
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
ResultFactoryRegistry.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetDefaultFactory()
|
||||
{
|
||||
MockRepository mocks = new MockRepository();
|
||||
IResultFactory resultFactory = (IResultFactory)mocks.CreateMock( typeof( IResultFactory ) );
|
||||
|
||||
IResultFactory prevFactory = ResultFactoryRegistry.DefaultResultFactory;
|
||||
Assert.AreSame( prevFactory, ResultFactoryRegistry.SetDefaultFactory( resultFactory ) );
|
||||
Assert.AreSame( resultFactory, ResultFactoryRegistry.DefaultResultFactory );
|
||||
|
||||
// verify default factory is used for unknown result mode
|
||||
using (Record( mocks ))
|
||||
{
|
||||
Expect.Call( resultFactory.CreateResult( null, "resultText" ) ).Return( new Result() );
|
||||
Expect.Call( resultFactory.CreateResult( "resultMode", "resultText" ) ).Return( new Result() );
|
||||
}
|
||||
|
||||
using (Playback( mocks ))
|
||||
{
|
||||
ResultFactoryRegistry.CreateResult( "resultText" );
|
||||
ResultFactoryRegistry.CreateResult( "resultMode:resultText" );
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResultModeValuesHavePredefinedFactories()
|
||||
{
|
||||
MockRepository mocks = new MockRepository();
|
||||
IResultFactory defaultFactory = (IResultFactory)mocks.CreateMock( typeof( IResultFactory ) );
|
||||
|
||||
ResultFactoryRegistry.SetDefaultFactory( defaultFactory );
|
||||
|
||||
// verify factory registry knows all ResultModes
|
||||
using (Record( mocks ))
|
||||
{
|
||||
// defaultFactory must never be called!
|
||||
}
|
||||
|
||||
using (Playback( mocks ))
|
||||
{
|
||||
foreach (string resultMode in Enum.GetNames( typeof( ResultMode ) ))
|
||||
{
|
||||
Assert.IsNotNull( ResultFactoryRegistry.CreateResult( resultMode+":resultText" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectsFactoryByResultMode()
|
||||
{
|
||||
MockRepository mocks = new MockRepository();
|
||||
IResultFactory resultFactory = (IResultFactory)mocks.CreateMock( typeof( IResultFactory ) );
|
||||
|
||||
ResultFactoryRegistry.RegisterResultMode( "resultMode", resultFactory );
|
||||
|
||||
Result result = new Result();
|
||||
|
||||
// verify factory registry does not allow nulls to be returned
|
||||
using (Record( mocks ))
|
||||
{
|
||||
Expect.Call( resultFactory.CreateResult( "resultMode", "resultText" ) ).Return( result );
|
||||
}
|
||||
|
||||
using (Playback( mocks ))
|
||||
{
|
||||
Assert.AreSame( result, ResultFactoryRegistry.CreateResult( "resultMode:resultText" ) );
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException( typeof( ArgumentNullException ) )]
|
||||
public void BailsOnNullReturnedFromFactory()
|
||||
{
|
||||
MockRepository mocks = new MockRepository();
|
||||
IResultFactory resultFactory = (IResultFactory)mocks.CreateMock( typeof( IResultFactory ) );
|
||||
|
||||
ResultFactoryRegistry.RegisterResultMode( "resultMode", resultFactory );
|
||||
|
||||
// verify factory registry does not allow nulls to be returned
|
||||
using (Record( mocks ))
|
||||
{
|
||||
Expect.Call( resultFactory.CreateResult( "resultMode", "resultText" ) ).Return( null );
|
||||
}
|
||||
|
||||
using (Playback( mocks ))
|
||||
{
|
||||
ResultFactoryRegistry.CreateResult( "resultMode:resultText" );
|
||||
}
|
||||
}
|
||||
|
||||
#region Rhino.Mocks Compatibility Adapter
|
||||
|
||||
private static IDisposable Record( MockRepository mocks )
|
||||
{
|
||||
#if !NET_1_1
|
||||
return mocks.Record();
|
||||
#else
|
||||
return new RecordModeChanger(mocks);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static IDisposable Playback( MockRepository mocks )
|
||||
{
|
||||
#if !NET_1_1
|
||||
return mocks.Playback();
|
||||
#else
|
||||
return new PlaybackModeChanger(mocks);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NET_1_1
|
||||
private class RecordModeChanger : IDisposable
|
||||
{
|
||||
private MockRepository _mocks;
|
||||
|
||||
public RecordModeChanger(MockRepository mocks)
|
||||
{
|
||||
_mocks = mocks;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mocks.ReplayAll();
|
||||
}
|
||||
}
|
||||
|
||||
private class PlaybackModeChanger : IDisposable
|
||||
{
|
||||
private MockRepository _mocks;
|
||||
|
||||
public PlaybackModeChanger(MockRepository mocks)
|
||||
{
|
||||
_mocks = mocks;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mocks.VerifyAll();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion Rhino.Mocks Compatibility Adapter
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -333,5 +335,32 @@ namespace Spring.Web.Support
|
||||
"The TargetPage property is not being correctly extracted " +
|
||||
"from the result string passed into the ctor.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TargetPageMayBeRuntimeExpression()
|
||||
{
|
||||
Result result = new Result("%{['var1']}");
|
||||
string resultUri = result.GetRedirectUri( MakeDictionary("var1", "val1") );
|
||||
Assert.AreEqual( "val1", resultUri );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParameterKeysAndValuesMayBeRuntimeExpression()
|
||||
{
|
||||
Result result = new Result("redirect:%{['var1']}?%{['var2']}=%{['var3']}");
|
||||
string resultUri = result.GetRedirectUri( MakeDictionary("var1", "val1", "var2", "val2", "var3", "val3") );
|
||||
Assert.AreEqual( "val1?val2=val3", resultUri );
|
||||
}
|
||||
|
||||
private IDictionary MakeDictionary( params object[] args)
|
||||
{
|
||||
AssertUtils.IsTrue(args.Length % 2 == 0);
|
||||
Hashtable ht= new Hashtable();
|
||||
for(int i=0;i<args.Length;i+=2)
|
||||
{
|
||||
ht[args[i]] = args[i+1];
|
||||
}
|
||||
return ht;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace Spring.Web.UI
|
||||
}
|
||||
catch(ArgumentException ae)
|
||||
{
|
||||
string expected = string.Format("No URL mapping found for the specified result '{0}'.", RESULTNAME);
|
||||
string expected = string.Format("No result mapping found for the specified name '{0}'.", RESULTNAME);
|
||||
string msg = ae.Message.Substring(0, expected.Length);
|
||||
Assert.AreEqual(expected, msg);
|
||||
}
|
||||
|
||||
@@ -41,19 +41,39 @@ namespace Spring.Web.UI
|
||||
{
|
||||
public class TestUserControl : UserControl
|
||||
{
|
||||
private static int instanceCount = 0;
|
||||
|
||||
public TestUserControl()
|
||||
:this(string.Format("_ctl_{0}", instanceCount++), null)
|
||||
{
|
||||
}
|
||||
|
||||
public TestUserControl(string id)
|
||||
:this(id, null)
|
||||
{
|
||||
}
|
||||
|
||||
public TestUserControl(Control parent)
|
||||
:this(null, parent)
|
||||
{
|
||||
parent.Controls.Add(this);
|
||||
}
|
||||
|
||||
public TestUserControl(string id, Control parent)
|
||||
{
|
||||
this.ID = id;
|
||||
if (parent != null) parent.Controls.Add(this);
|
||||
}
|
||||
|
||||
public new void SetResult(string name)
|
||||
{
|
||||
base.SetResult(name);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}[{1}]", base.ToString(), this.ClientID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -85,7 +105,8 @@ namespace Spring.Web.UI
|
||||
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
theResult.Navigate(c1);
|
||||
// context is the control, that SetResult() was called on
|
||||
theResult.Navigate(c111);
|
||||
}
|
||||
mocks.ReplayAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user