Additional tests on ExpressionEvaluator for delegate functions and custom collection processors. (mostly for documentation purposes)

Messed up my environment, xcopy wasn't working, so changes to .csproj are false positives.
This commit is contained in:
markpollack
2008-07-16 18:21:42 +00:00
parent 4928371e5c
commit 325250f358
7 changed files with 75 additions and 6 deletions

View File

@@ -301,6 +301,6 @@
</PreBuildEvent>
<PostBuildEvent>echo "Copying .xml files for tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Aop.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Aop.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Aop.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -41,6 +41,7 @@ using Spring.Context.Support;
using Spring.Core;
using Spring.Core.TypeResolution;
using Spring.Expressions;
using Spring.Expressions.Processors;
using Spring.Objects;
using Spring.Objects.Factory;
using Spring.Threading;
@@ -1565,6 +1566,37 @@ namespace Spring.Expressions
Assert.AreEqual(TransactionOption.Required, webMethod.TransactionOption);
}
[Test]
public void TestDelegateFunctionExpressions()
{
//for purposes of an example in documentation
Hashtable vars = new Hashtable();
vars["sqrt"] = new DoubleFunction(Sqrt);
double result = (double)ExpressionEvaluator.GetValue(null, "#sqrt(64)", vars);
Assert.AreEqual(8, result);
vars = new Hashtable();
vars["max"] = new DoubleFunctionTwoArgs(Max);
result = (double) ExpressionEvaluator.GetValue(null, "#max(5,25)", vars);
Assert.AreEqual(25, result);
}
private delegate double DoubleFunction(double arg);
private double Sqrt(double arg)
{
return Math.Sqrt(arg);
}
private delegate double DoubleFunctionTwoArgs(double arg1, double arg2);
private double Max(double arg1, double arg2)
{
return Math.Max(arg1, arg2);
}
/// <summary>
/// Type lambda expressions.
/// </summary>
@@ -1626,6 +1658,43 @@ namespace Spring.Expressions
Assert.AreEqual(0, ExpressionEvaluator.GetValue(null, "count()"));
}
[Test]
public void TestCustomCollectionProcessor()
{
// Test for the purposes of creating documentation example.
Hashtable vars = new Hashtable();
vars["EvenSum"] = new IntEvenSumCollectionProcessor();
Assert.AreEqual(6, ExpressionEvaluator.GetValue(null, "{1, 2, 3, 4}.EvenSum()", vars));
}
private class IntEvenSumCollectionProcessor : ICollectionProcessor
{
public object Process(ICollection source, object[] args)
{
object total = 0d;
foreach (object item in source)
{
if (item != null)
{
if (NumberUtils.IsInteger(item))
{
if ((int)item % 2 == 0)
{
total = NumberUtils.Add(total, item);
}
}
else
{
throw new ArgumentException("Sum can only be calculated for a collection of numeric values.");
}
}
}
return total;
}
}
[Test]
public void TestSumAggregator()
{

View File

@@ -868,6 +868,6 @@
</PreBuildEvent>
<PostBuildEvent>echo "Copying .xml files for tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Core.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Core.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Core.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -124,6 +124,6 @@
<PropertyGroup>
<PostBuildEvent>echo "Copying .xml files for tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Data.NHibernate.Integration.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.NHibernate.Integration.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.NHibernate.Integration.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -118,6 +118,6 @@
<PropertyGroup>
<PostBuildEvent>echo "Copying .xml files for tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Data.NHibernate.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.NHibernate.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.NHibernate.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -188,6 +188,6 @@
</PreBuildEvent>
<PostBuildEvent>echo "Copying .xml files for tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Data.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -183,6 +183,6 @@
</PreBuildEvent>
<PostBuildEvent>echo "Copying .xml files for Spring.Services tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Services.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Services.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Services.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>