misc updates to cleanup VS2010 projects and tests

This commit is contained in:
sbohlen
2010-08-17 18:41:44 +00:00
parent 11bb25277b
commit dfc45053fb
4 changed files with 408 additions and 407 deletions

View File

@@ -1,62 +1,62 @@
#if NET_2_0
#region License
/*
* Copyright <20> 2002-2007 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
using System;
#if NET_2_0
#region License
/*
* Copyright <20> 2002-2007 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
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using Spring.Util;
namespace Spring.Objects.Factory.Config
{
/// <summary>
/// Implementation of <see cref="IVariableSource"/> that
/// resolves variable name connection strings defined in
/// the standard .NET configuration file.
/// </summary>
/// <remarks>
/// <p>
/// When the &lt;connectionStrings&gt; configuration section is processed by this class,
/// two variables are defined for each connection string: one for connection string and
/// the second one for the provider name.</p>
/// <p>
/// Variable names are generated by appending '.connectionString' and '.providerName'
/// literals to the value of the <c>name</c> attribute of the connection string element.
/// For example:</p>
/// <pre>
/// <connectionStrings>
/// <add name="myConn" connectionString="..." providerName="..." />
/// </connectionStrings>
/// </pre>
/// <p>
/// will result in two variables being created: <b>myConn.connectionString</b> and <b>myConn.providerName</b>.
/// You can reference these variables within your object definitions, just like any other variable.</p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
[Serializable]
public class ConnectionStringsVariableSource : IVariableSource
{
private Hashtable variables;
using System.Collections.Specialized;
using System.Configuration;
using Spring.Util;
namespace Spring.Objects.Factory.Config
{
/// <summary>
/// Implementation of <see cref="IVariableSource"/> that
/// resolves variable name connection strings defined in
/// the standard .NET configuration file.
/// </summary>
/// <remarks>
/// <p>
/// When the &lt;connectionStrings&gt; configuration section is processed by this class,
/// two variables are defined for each connection string: one for connection string and
/// the second one for the provider name.</p>
/// <p>
/// Variable names are generated by appending '.connectionString' and '.providerName'
/// literals to the value of the <c>name</c> attribute of the connection string element.
/// For example:</p>
/// <pre>
/// <connectionStrings>
/// <add name="myConn" connectionString="..." providerName="..." />
/// </connectionStrings>
/// </pre>
/// <p>
/// will result in two variables being created: <b>myConn.connectionString</b> and <b>myConn.providerName</b>.
/// You can reference these variables within your object definitions, just like any other variable.</p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
[Serializable]
public class ConnectionStringsVariableSource : IVariableSource
{
private Hashtable variables;
/// <summary>
/// Before requesting a variable resolution, a client should
/// ask, whether the source can resolve a particular variable name.
@@ -68,45 +68,45 @@ namespace Spring.Objects.Factory.Config
if (variables == null)
{
InitVariables();
}
return variables.Contains(name);
}
return variables.Contains(name);
}
/// <summary>
/// Resolves variable value for the specified variable name.
/// </summary>
/// <param name="name">
/// The name of the variable to resolve.
/// </param>
/// <returns>
/// The variable value if able to resolve, <c>null</c> otherwise.
/// </returns>
public string ResolveVariable(string name)
{
if (variables == null)
{
InitVariables();
}
return (string) variables[name];
}
/// <summary>
/// Initializes properties based on the specified
/// property file locations.
/// </summary>
private void InitVariables()
{
variables = CollectionsUtil.CreateCaseInsensitiveHashtable();
ConnectionStringSettingsCollection settings = ConfigurationManager.ConnectionStrings;
foreach (ConnectionStringSettings setting in settings)
{
string providerName = setting.ProviderName;
variables.Add(setting.Name + ".connectionString", setting.ConnectionString);
variables.Add(setting.Name + ".providerName",
StringUtils.HasText(providerName) ? providerName : "System.Data.SqlClient");
}
}
}
}
/// <summary>
/// Resolves variable value for the specified variable name.
/// </summary>
/// <param name="name">
/// The name of the variable to resolve.
/// </param>
/// <returns>
/// The variable value if able to resolve, <c>null</c> otherwise.
/// </returns>
public string ResolveVariable(string name)
{
if (variables == null)
{
InitVariables();
}
return (string) variables[name];
}
/// <summary>
/// Initializes properties based on the specified
/// property file locations.
/// </summary>
private void InitVariables()
{
variables = CollectionsUtil.CreateCaseInsensitiveHashtable();
ConnectionStringSettingsCollection settings = ConfigurationManager.ConnectionStrings;
foreach (ConnectionStringSettings setting in settings)
{
string providerName = setting.ProviderName;
variables.Add(setting.Name + ".connectionString", setting.ConnectionString);
variables.Add(setting.Name + ".providerName",
StringUtils.HasText(providerName) ? providerName : "System.Data.SqlClient");
}
}
}
}
#endif

View File

@@ -34,7 +34,7 @@
</object>
<object id='testremotequeue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'>
<property name='Path' value='FormatName:Direct=OS:CCORSELLO-PC\Private$\testqueue'/>
<property name='Path' value='FormatName:Direct=OS:RAVEN\Private$\testqueue'/>
<property name='RemoteQueue' value="true"/>
</object>

View File

@@ -134,6 +134,7 @@
<Compile Include="Web\Support\ControlInterceptionTests.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Web\Support\HandlerMapTests.cs" />
<Compile Include="Web\Support\LocalResourceManagerTests.cs" />
<Compile Include="Web\Support\MimeMediaTypeTests.cs" />
<Compile Include="Web\Support\PageHandlerFactoryTests.cs" />

View File

@@ -29,138 +29,138 @@ using Spring.Util;
namespace Spring.Web.Support
{
/// <summary>
/// Unit tests for the Result class.
/// </summary>
/// <author>Rick Evans</author>
[TestFixture]
public sealed class ResultTests
{
private const string ExpectedTargetPageName = "Foo.aspx";
/// <summary>
/// Unit tests for the Result class.
/// </summary>
/// <author>Rick Evans</author>
[TestFixture]
public sealed class ResultTests
{
private const string ExpectedTargetPageName = "Foo.aspx";
[Test]
public void DoesItDefaultToTheDefaultResultMode()
{
Result result = new Result();
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
}
[Test]
public void DoesItDefaultToTheDefaultResultMode()
{
Result result = new Result();
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
}
[Test]
public void DefaultsToTransferMode()
{
Assert.AreEqual(ResultMode.Transfer, Result.DefaultResultMode,
"Hey! Be sure to change the documentation since you've " +
"obviously gone and changed the default transfer mode.");
}
[Test]
public void DefaultsToTransferMode()
{
Assert.AreEqual(ResultMode.Transfer, Result.DefaultResultMode,
"Hey! Be sure to change the documentation since you've " +
"obviously gone and changed the default transfer mode.");
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationBailsWithNullResultString()
{
new Result(null);
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationBailsWithNullResultString()
{
new Result(null);
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationBailsWithEmptyResultString()
{
new Result(string.Empty);
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationBailsWithEmptyResultString()
{
new Result(string.Empty);
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationBailsWithAllWhitespaceResultString()
{
new Result(" \n\t ");
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationBailsWithAllWhitespaceResultString()
{
new Result(" \n\t ");
}
[Test]
public void WithNoResultModeAndNoParameters()
{
Result result = new Result(ExpectedTargetPageName);
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithNoResultModeAndNoParameters()
{
Result result = new Result(ExpectedTargetPageName);
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacePageAndNoResultModeAndNoParameters()
{
Result result = new Result(" " + ExpectedTargetPageName + "\n");
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacePageAndNoResultModeAndNoParameters()
{
Result result = new Result(" " + ExpectedTargetPageName + "\n");
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithTransferResultModeButNoParameters()
{
Result result = new Result("transfer:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.AreEqual(true, result.PreserveForm, "ResultMode.Transfer must result in PreserveForm being 'true'");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithTransferResultModeButNoParameters()
{
Result result = new Result("transfer:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.AreEqual(true, result.PreserveForm, "ResultMode.Transfer must result in PreserveForm being 'true'");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithTransferNoPreserveResultMode()
{
Result result = new Result( "transfernopreserve:" + ExpectedTargetPageName );
Assert.AreEqual( ResultMode.TransferNoPreserve,result.Mode,"Not extracting the correct ResultMode " +
"from the result string passed into the ctor." );
Assert.AreEqual( false,result.PreserveForm,"ResultMode.TransferNoPreserver must result in PreserveForm being 'false'" );
}
[Test]
public void WithTransferNoPreserveResultMode()
{
Result result = new Result( "transfernopreserve:" + ExpectedTargetPageName );
Assert.AreEqual( ResultMode.TransferNoPreserve,result.Mode,"Not extracting the correct ResultMode " +
"from the result string passed into the ctor." );
Assert.AreEqual( false,result.PreserveForm,"ResultMode.TransferNoPreserver must result in PreserveForm being 'false'" );
}
[Test]
public void WithWhitespacedRedirectResultMode()
{
Result result = new Result(" redirect:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.Redirect, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacedRedirectResultMode()
{
Result result = new Result(" redirect:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.Redirect, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithRedirectResultMode()
{
Result result = new Result("redirect:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.Redirect, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsTrue(result.EndResponse);
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithRedirectResultMode()
{
Result result = new Result("redirect:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.Redirect, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsTrue(result.EndResponse);
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithRedirectNoAbortResultMode()
{
Result result = new Result("redirectnoabort:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.RedirectNoAbort, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsFalse(result.EndResponse);
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithRedirectNoAbortResultMode()
{
Result result = new Result("redirectnoabort:" + ExpectedTargetPageName);
Assert.AreEqual(ResultMode.RedirectNoAbort, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsFalse(result.EndResponse);
Assert.IsNull(result.Parameters,
"No parameters were passed but the Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
@@ -170,96 +170,96 @@ namespace Spring.Web.Support
new Result("redirct:" + ExpectedTargetPageName);
}
[Test]
public void WithResultModeAndEmptyParameterDelimiterOnly()
{
Result result = new Result("transfer:" + ExpectedTargetPageName + "?");
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNull(result.Parameters,
"No parameters were passed (just the parameter delimiter) but the " +
"Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithResultModeAndEmptyParameterDelimiterOnly()
{
Result result = new Result("transfer:" + ExpectedTargetPageName + "?");
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNull(result.Parameters,
"No parameters were passed (just the parameter delimiter) but the " +
"Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithResultModeAndWhitespaceParameterDelimiterOnly()
{
Result result = new Result("redirect:" + ExpectedTargetPageName + "? ");
Assert.AreEqual(ResultMode.Redirect, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNull(result.Parameters,
"No parameters were passed (just the parameter delimiter) but the " +
"Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithResultModeAndWhitespaceParameterDelimiterOnly()
{
Result result = new Result("redirect:" + ExpectedTargetPageName + "? ");
Assert.AreEqual(ResultMode.Redirect, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNull(result.Parameters,
"No parameters were passed (just the parameter delimiter) but the " +
"Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithNoResultModeAndWhitespaceParameterDelimiterOnly()
{
Result result = new Result(ExpectedTargetPageName + "? ");
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNull(result.Parameters,
"No parameters were passed (just the parameter delimiter) but the " +
"Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithNoResultModeAndWhitespaceParameterDelimiterOnly()
{
Result result = new Result(ExpectedTargetPageName + "? ");
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNull(result.Parameters,
"No parameters were passed (just the parameter delimiter) but the " +
"Parameters property appears to be set to a non-null value anyway.");
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithNoResultModeAndOneParameter()
{
const string key = "id";
const string value = "Nina Persson";
Result result = new Result(ExpectedTargetPageName + "?" + key + "=" + value);
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(1, result.Parameters.Count,
"Wrong number of query parameters parsed (only supplied one key-value pair).");
Assert.IsTrue(result.Parameters.Contains(key), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(value, result.Parameters[key]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithNoResultModeAndOneParameter()
{
const string key = "id";
const string value = "Nina Persson";
Result result = new Result(ExpectedTargetPageName + "?" + key + "=" + value);
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(1, result.Parameters.Count,
"Wrong number of query parameters parsed (only supplied one key-value pair).");
Assert.IsTrue(result.Parameters.Contains(key), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(value, result.Parameters[key]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithTransferResultModeAndOneParameter()
{
const string key = "id";
const string value = "Nina Persson";
Result result = new Result("transfer:" + ExpectedTargetPageName + "?" + key + "=" + value);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(1, result.Parameters.Count,
"Wrong number of query parameters parsed (only supplied one key-value pair).");
Assert.IsTrue(result.Parameters.Contains(key), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(value, result.Parameters[key]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithTransferResultModeAndOneParameter()
{
const string key = "id";
const string value = "Nina Persson";
Result result = new Result("transfer:" + ExpectedTargetPageName + "?" + key + "=" + value);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(1, result.Parameters.Count,
"Wrong number of query parameters parsed (only supplied one key-value pair).");
Assert.IsTrue(result.Parameters.Contains(key), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(value, result.Parameters[key]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
[Ignore("How does one escape ampersands then?")]
public void ParametersHavingEmbeddedCharactersThatHaveToBeEscaped()
{
const string key = "id";
const string value = "Nina Persson & The Cardigans"; // notice the use of the embedded '&'...
Result result = new Result(ExpectedTargetPageName + "?" + key + "=" + value);
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
[Test]
[Ignore("How does one escape ampersands then?")]
public void ParametersHavingEmbeddedCharactersThatHaveToBeEscaped()
{
const string key = "id";
const string value = "Nina Persson & The Cardigans"; // notice the use of the embedded '&'...
Result result = new Result(ExpectedTargetPageName + "?" + key + "=" + value);
Assert.AreEqual(Result.DefaultResultMode, result.Mode, "Not defaulting to the default ResultMode.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
// Assert.AreEqual(1, result.Parameters.Count,
// "Wrong number of query parameters parsed (only supplied one key-value pair).");
// Assert.IsTrue(result.Parameters.Contains(key), "The 'id' parameter is not being correctly extracted " +
@@ -268,114 +268,114 @@ namespace Spring.Web.Support
// Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
// "The TargetPage property is not being correctly extracted " +
// "from the result string passed into the ctor.");
}
}
[Test]
public void WithTransferResultModeAndTwoParametersSplitUsingAmpersand()
{
const string pKey1 = "id";
const string pValue1 = "Nina Persson";
const string pKey2 = "verdict";
const string pValue2 = "schwing";
Result result =
new Result(ExpectedTargetPageName + "?" + pKey1 + "=" + pValue1 + "&" + pKey2 + "=" + pValue2);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(2, result.Parameters.Count,
"Wrong number of query parameters parsed (supplied two key-value pairs).");
Assert.IsTrue(result.Parameters.Contains(pKey1), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue1, result.Parameters[pKey1]);
Assert.IsTrue(result.Parameters.Contains(pKey2),
"The 'verdict' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue2, result.Parameters[pKey2]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithTransferResultModeAndTwoParametersSplitUsingAmpersand()
{
const string pKey1 = "id";
const string pValue1 = "Nina Persson";
const string pKey2 = "verdict";
const string pValue2 = "schwing";
Result result =
new Result(ExpectedTargetPageName + "?" + pKey1 + "=" + pValue1 + "&" + pKey2 + "=" + pValue2);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(2, result.Parameters.Count,
"Wrong number of query parameters parsed (supplied two key-value pairs).");
Assert.IsTrue(result.Parameters.Contains(pKey1), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue1, result.Parameters[pKey1]);
Assert.IsTrue(result.Parameters.Contains(pKey2),
"The 'verdict' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue2, result.Parameters[pKey2]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacedPageAndTransferResultModeAndTwoParametersUsingAmpersands()
{
const string pKey1 = "id";
const string pValue1 = "Nina Persson";
const string pKey2 = "verdict";
const string pValue2 = "schwing";
Result result =
new Result("\n" + ExpectedTargetPageName + " ?" + pKey1 + "=" + pValue1 + "&" + pKey2 + "=" + pValue2);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(2, result.Parameters.Count,
"Wrong number of query parameters parsed (supplied two key-value pairs).");
Assert.IsTrue(result.Parameters.Contains(pKey1), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue1, result.Parameters[pKey1]);
Assert.IsTrue(result.Parameters.Contains(pKey2),
"The 'verdict' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue2, result.Parameters[pKey2]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacedPageAndTransferResultModeAndTwoParametersUsingAmpersands()
{
const string pKey1 = "id";
const string pValue1 = "Nina Persson";
const string pKey2 = "verdict";
const string pValue2 = "schwing";
Result result =
new Result("\n" + ExpectedTargetPageName + " ?" + pKey1 + "=" + pValue1 + "&" + pKey2 + "=" + pValue2);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(2, result.Parameters.Count,
"Wrong number of query parameters parsed (supplied two key-value pairs).");
Assert.IsTrue(result.Parameters.Contains(pKey1), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue1, result.Parameters[pKey1]);
Assert.IsTrue(result.Parameters.Contains(pKey2),
"The 'verdict' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue2, result.Parameters[pKey2]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacedPageAndTransferResultModeAndTwoParametersUsingCommas()
{
const string pKey1 = "id";
const string pValue1 = "Nina Persson";
const string pKey2 = "verdict";
const string pValue2 = "schwing";
Result result =
new Result("\n" + ExpectedTargetPageName + " ?" + pKey1 + "=" + pValue1 + "," + pKey2 + "=" + pValue2);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(2, result.Parameters.Count,
"Wrong number of query parameters parsed (supplied two key-value pairs).");
Assert.IsTrue(result.Parameters.Contains(pKey1), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue1, result.Parameters[pKey1]);
Assert.IsTrue(result.Parameters.Contains(pKey2),
"The 'verdict' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue2, result.Parameters[pKey2]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"The TargetPage property is not being correctly extracted " +
"from the result string passed into the ctor.");
}
[Test]
public void WithWhitespacedPageAndTransferResultModeAndTwoParametersUsingCommas()
{
const string pKey1 = "id";
const string pValue1 = "Nina Persson";
const string pKey2 = "verdict";
const string pValue2 = "schwing";
Result result =
new Result("\n" + ExpectedTargetPageName + " ?" + pKey1 + "=" + pValue1 + "," + pKey2 + "=" + pValue2);
Assert.AreEqual(ResultMode.Transfer, result.Mode, "Not extracting the correct ResultMode " +
"from the result string passed into the ctor.");
Assert.IsNotNull(result.Parameters,
"Parameters were passed but the Parameters property appears to be null (incorrectly).");
Assert.AreEqual(2, result.Parameters.Count,
"Wrong number of query parameters parsed (supplied two key-value pairs).");
Assert.IsTrue(result.Parameters.Contains(pKey1), "The 'id' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue1, result.Parameters[pKey1]);
Assert.IsTrue(result.Parameters.Contains(pKey2),
"The 'verdict' parameter is not being correctly extracted " +
"from the result string passed into the ctor.");
Assert.AreEqual(pValue2, result.Parameters[pKey2]);
Assert.AreEqual(ExpectedTargetPageName, result.TargetPage,
"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 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 );
}
[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;
}
}
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;
}
}
}