SPRNET-1343
Added initial support for ASP.NET MVC (v2)
This commit is contained in:
@@ -29,12 +29,14 @@ using NUnit.Framework;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Data.Common;
|
||||
using Spring.Data.Support;
|
||||
using Spring.Transaction;
|
||||
using Spring.Transaction.Support;
|
||||
using Spring.Transaction.Interceptor;
|
||||
using System.Transactions;
|
||||
using System.Collections.Generic;
|
||||
using Spring.Core.IO;
|
||||
using NHibernate.Cfg;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -202,5 +204,135 @@ namespace Spring.Data.NHibernate
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test2()
|
||||
{
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
//DaoOperationsViaProxyFactoryWithTxAttributes();
|
||||
try
|
||||
{
|
||||
zzzExecuteDaoOperations();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void zzzExecuteDaoOperations()
|
||||
{
|
||||
ITestObjectDao dao = (ITestObjectDao)ctx["SimpleTestDao"];
|
||||
|
||||
TestObject toGeorge = new TestObject();
|
||||
toGeorge.Name = "George";
|
||||
toGeorge.Age = 33;
|
||||
dao.Create(toGeorge);
|
||||
}
|
||||
|
||||
|
||||
//private void MethodForThread()
|
||||
//{
|
||||
//
|
||||
// MethodForThread((0));
|
||||
//}
|
||||
|
||||
private void MethodForThread(object taskCounter)
|
||||
{
|
||||
int counter = (int)taskCounter;
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.WriteLine(String.Format("Task: {0} | Loop Count: {1}", counter, i));
|
||||
zzzExecuteDaoOperations();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine(String.Format("\n---------\nCompleting Task Number {0}\n---------\n", taskCounter));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
BasicConfigurator.Configure();
|
||||
string assemblyName = GetType().Assembly.GetName().Name;
|
||||
ctx = new XmlApplicationContext("assembly://" + assemblyName + "/Spring.Data.NHibernate/txScopeBugTests.xml");
|
||||
|
||||
dbProvider = ctx["DbProvider"] as IDbProvider;
|
||||
transactionManager = ctx["TransactionManager"] as IPlatformTransactionManager;
|
||||
CleanupDatabase(dbProvider.CreateConnection());
|
||||
|
||||
List<Thread> threads = new List<Thread>();
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
int taskCounter = i;
|
||||
Debug.WriteLine(String.Format("\n---------\nSpawning Task Number {0}\n---------\n", taskCounter));
|
||||
|
||||
Thread t = new Thread(MethodForThread);
|
||||
threads.Add(t);
|
||||
t.Start(taskCounter);
|
||||
|
||||
}
|
||||
|
||||
foreach (Thread thread in threads)
|
||||
{
|
||||
thread.Join();
|
||||
}
|
||||
}
|
||||
|
||||
public void DoNothing()
|
||||
{
|
||||
ConfigurableResourceLoader loader = new ConfigurableResourceLoader();
|
||||
Configuration c = new Configuration();
|
||||
String resourceName =
|
||||
"assembly://Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate/TestObject.hbm.xml";
|
||||
c.AddInputStream(loader.GetResource(resourceName).InputStream);
|
||||
ISessionFactory sf = c.BuildSessionFactory();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void LeaksConnectionSampleCodeFromBlogPost()
|
||||
{
|
||||
|
||||
int counter = 200;
|
||||
|
||||
for (int i = 0; i < counter; i++)
|
||||
{
|
||||
|
||||
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
|
||||
{
|
||||
using (ISession session = ((ISessionFactory)ctx["SessionFactory"]).OpenSession())
|
||||
{
|
||||
/*
|
||||
IQuery q = session.CreateQuery("from Spring.Data.NHibernate.TestObject");
|
||||
q.List();
|
||||
*/
|
||||
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
IQuery q = session.CreateQuery("from Spring.Data.NHibernate.TestObject");
|
||||
q.List();
|
||||
//transaction.Rollback();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using NHibernate;
|
||||
using Spring.Transaction.Interceptor;
|
||||
using System.Threading;
|
||||
|
||||
namespace Spring.Data.NHibernate
|
||||
{
|
||||
[Transaction]
|
||||
public class SimpleTestDao : ITestObjectDao
|
||||
{
|
||||
|
||||
private int _secondsToSleepBeforeException;
|
||||
public int SecondsToSleepBeforeException
|
||||
{
|
||||
get { return _secondsToSleepBeforeException; }
|
||||
set
|
||||
{
|
||||
_secondsToSleepBeforeException = value * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ISessionFactory SessionFactory
|
||||
{
|
||||
get { return sessionFactory; }
|
||||
set { sessionFactory = value; }
|
||||
}
|
||||
|
||||
private ISessionFactory sessionFactory;
|
||||
|
||||
[Transaction]
|
||||
public void Create(TestObject to)
|
||||
{
|
||||
sessionFactory.GetCurrentSession().FlushMode = FlushMode.Always;
|
||||
sessionFactory.GetCurrentSession().Save(to);
|
||||
Thread.Sleep(_secondsToSleepBeforeException);
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public void Update(TestObject to)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Delete(TestObject to)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public TestObject FindByName(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CreateUpdateRollback(TestObject to)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns='http://www.springframework.net'
|
||||
xmlns:db="http://www.springframework.net/database"
|
||||
xmlns:tx="http://www.springframework.net/tx">
|
||||
|
||||
|
||||
<!--<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=(local);Initial Catalog=rewards;Integrated Security=True;Max Pool Size=10"/>-->
|
||||
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=(local)\sql2005;Initial Catalog=rewards;user id=sa;password=password"/>
|
||||
|
||||
<!--<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARK6500\NR2007;Initial Catalog=spring;user id=springqa;password=springqa;Max Pool Size=10"/>-->
|
||||
|
||||
<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate21">
|
||||
<property name="DbProvider" ref="DbProvider"/>
|
||||
<property name="ExposeTransactionAwareSessionFactory" value="true" />
|
||||
|
||||
<property name="MappingResources">
|
||||
<list>
|
||||
<value>assembly://Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate/TestObject.hbm.xml</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="HibernateProperties">
|
||||
<dictionary>
|
||||
<entry key="dialect"
|
||||
value="NHibernate.Dialect.MsSql2000Dialect"/>
|
||||
|
||||
<entry key="connection.driver_class"
|
||||
value="NHibernate.Driver.SqlClientDriver"/>
|
||||
|
||||
</dictionary>
|
||||
</property>
|
||||
</object>
|
||||
|
||||
<object id="SimpleTestDao" type="Spring.Data.NHibernate.SimpleTestDao, Spring.Data.NHibernate21.Integration.Tests">
|
||||
<property name="SessionFactory" ref="SessionFactory"/>
|
||||
<property name="SecondsToSleepBeforeException" value="0" />
|
||||
</object>
|
||||
|
||||
|
||||
<!--<object id="TransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate21">
|
||||
<property name="DbProvider" ref="DbProvider"/>
|
||||
<property name="sessionFactory" ref="SessionFactory"/>
|
||||
</object>-->
|
||||
|
||||
<!--<object id="TransactionManager" type="Spring.Data.Core.TxScopeTransactionManager, Spring.Data" />-->
|
||||
|
||||
|
||||
|
||||
<object id="TransactionManager" type="Spring.Data.NHibernate.HibernateTxScopeTransactionManager, Spring.Data.NHibernate21">
|
||||
<property name="DbProvider" ref="DbProvider"/>
|
||||
<property name="sessionFactory" ref="SessionFactory"/>
|
||||
</object>
|
||||
|
||||
|
||||
<tx:attribute-driven transaction-manager="TransactionManager"/>
|
||||
|
||||
</objects>
|
||||
@@ -147,6 +147,7 @@
|
||||
<Compile Include="Data\NHibernate\AccountController.cs" />
|
||||
<Compile Include="Data\NHibernate\HibernateTxScopeTransactionManagerTests.cs" />
|
||||
<Compile Include="Data\NHibernate\IAccountController.cs" />
|
||||
<Compile Include="Data\NHibernate\SimpleTestDao.cs" />
|
||||
<Compile Include="Setup.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -205,6 +206,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Data\NHibernate\Bytecode\Foo.Spechbm.xml" />
|
||||
<EmbeddedResource Include="Data\NHibernate\HibernateTxScopeTransactionManagerTests.xml" />
|
||||
<EmbeddedResource Include="Data\NHibernate\txScopeBugTests.xml" />
|
||||
<Content Include="TestEnbeddedConfig.cfg.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using System.Web.Mvc;
|
||||
using Spring.Web.Mvc.Tests.Controllers;
|
||||
using Spring.Context.Support;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Spring.Web.Mvc.Tests
|
||||
{
|
||||
public static class ControllerFactoryTestExtension
|
||||
{
|
||||
private static readonly PropertyInfo _typeCacheProperty;
|
||||
private static readonly FieldInfo _cacheField;
|
||||
|
||||
static ControllerFactoryTestExtension()
|
||||
{
|
||||
_typeCacheProperty = typeof(DefaultControllerFactory).GetProperty("ControllerTypeCache", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
_cacheField = _typeCacheProperty.PropertyType.GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the cache field of a the DefaultControllerFactory's ControllerTypeCache.
|
||||
/// This ensures that only the specified controller types will be searched when instantiating a controller.
|
||||
/// As the ControllerTypeCache is internal, this uses some reflection hackery.
|
||||
/// </summary>
|
||||
public static void InitializeWithControllerTypes(this IControllerFactory factory, params Type[] controllerTypes)
|
||||
{
|
||||
var cache = controllerTypes
|
||||
.GroupBy(t => t.Name.Substring(0, t.Name.Length - "Controller".Length), StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(g => g.Key, g => g.ToLookup(t => t.Namespace ?? string.Empty, StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var buildManager = _typeCacheProperty.GetValue(factory, null);
|
||||
_cacheField.SetValue(buildManager, cache);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Spring.Web.Mvc.Tests.Controllers
|
||||
{
|
||||
public class FirstContainerRegisteredController : Controller
|
||||
{
|
||||
public string TestValue { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Spring.Web.Mvc.Tests.Controllers
|
||||
{
|
||||
public class NamedContextController : Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Spring.Web.Mvc.Tests.Controllers
|
||||
{
|
||||
public class NotInContainerController : Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Spring.Web.Mvc.Tests.Controllers
|
||||
{
|
||||
public class SecondContainerRegisteredController : Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
36
test/Spring/Spring.Web.Mvc.Tests/Properties/AssemblyInfo.cs
Normal file
36
test/Spring/Spring.Web.Mvc.Tests/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spring.Web.Mvc.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("Spring.Web.Mvc.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("3f96ac7b-cd25-4d07-8b1c-ee2eb77cf5eb")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{D4032434-D9A8-437B-95E8-9D4DE0AD9932}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.Web.Mvc.Tests</RootNamespace>
|
||||
<AssemblyName>Spring.Web.Mvc.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web.Abstractions" />
|
||||
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="System.Web.Routing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ControllerFactoryTestExtension.cs" />
|
||||
<Compile Include="Controllers\NamedContextController.cs" />
|
||||
<Compile Include="Controllers\SecondContainerRegisteredController.cs" />
|
||||
<Compile Include="Controllers\NotInContainerController.cs" />
|
||||
<Compile Include="Controllers\FirstContainerRegisteredController.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SpringControllerFactoryTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Core\Spring.Core.2010.csproj">
|
||||
<Project>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</Project>
|
||||
<Name>Spring.Core.2010</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Web.Mvc\Spring.Web.Mvc.2010.csproj">
|
||||
<Project>{5166CE3A-14BE-478A-88DA-729A39DE1E29}</Project>
|
||||
<Name>Spring.Web.Mvc.2010</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="objects.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="namedContextObjects.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="objectsMatchByType.xml" />
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
71
test/Spring/Spring.Web.Mvc.Tests/Spring.Web.Mvc.Tests.build
Normal file
71
test/Spring/Spring.Web.Mvc.Tests/Spring.Web.Mvc.Tests.build
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" ?>
|
||||
<project name="Spring.Web.Tests" default="test" xmlns="http://nant.sf.net/schemas/nant.xsd">
|
||||
|
||||
<include buildfile="${spring.basedir}/common-project.include" />
|
||||
<!--
|
||||
Required properties:
|
||||
* current.bin.dir - (path) root level to build to
|
||||
* build.debug - (true|false) debug build?
|
||||
* current.build.defines.csc - framework-specific build defines
|
||||
* lib.dir - framework-specific assembly references
|
||||
-->
|
||||
<target name="build">
|
||||
<!-- build Spring.Web.Mvc -->
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
optimize="${build.optimize}"
|
||||
debug="${current.build.debug}"
|
||||
output="${current.bin.dir}/${project::get-name()}.dll"
|
||||
doc="${current.bin.dir}/${project::get-name()}.xml">
|
||||
<nowarn>
|
||||
<warning number="${nowarn.numbers.test}" /> <!-- 1701 -->
|
||||
<warning number="${nowarn.numbers.test},1587" if="${nant.settings.currentframework=='mono-2.0'}"/>
|
||||
</nowarn>
|
||||
<sources failonempty="true">
|
||||
<include name="**/*.cs" />
|
||||
<include name="../CommonAssemblyInfo.cs" />
|
||||
</sources>
|
||||
<resources prefix="Spring" dynamicprefix="true" failonempty="true">
|
||||
<include name="**/*.resx" />
|
||||
<include name="**/*.xsd" />
|
||||
<include name="**/*.txt" />
|
||||
<include name="**/*.xml" />
|
||||
<exclude name="Data/**/*" />
|
||||
<exclude name="obj/**/*" />
|
||||
</resources>
|
||||
<references basedir="${current.bin.dir}">
|
||||
<include name="*.dll" />
|
||||
<include name="System.Configuration.dll" if="${nant.settings.currentframework=='mono-2.0'}" />
|
||||
<include name="System.Drawing.dll" if="${nant.settings.currentframework=='mono-2.0'}" />
|
||||
<include name="System.Xml.dll" if="${nant.settings.currentframework=='mono-2.0'}" />
|
||||
<include name="System.Web.dll" if="${nant.settings.currentframework=='mono-2.0'}" />
|
||||
<include name="System.Web.Services.dll" if="${nant.settings.currentframework=='mono-2.0'}" />
|
||||
<include name="System.Data.dll" if="${nant.settings.currentframework=='mono-2.0'}" />
|
||||
<exclude name="${project::get-name()}.dll" />
|
||||
<exclude name="CloverRuntime.dll" />
|
||||
<include name="${lib.dir}/nunit.core.interfaces.dll" />
|
||||
<exclude if="${net-4.0}" name="System.Web.Extensions.dll" />
|
||||
</references>
|
||||
</csc>
|
||||
<copy todir="${current.bin.dir}">
|
||||
<fileset basedir="${project::get-base-directory()}/Data">
|
||||
<include name="**/*.*" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="test" depends="build">
|
||||
<!-- property name="test.assemblyname" value="${project::get-name()}" / -->
|
||||
<call target="common.run-tests" />
|
||||
</target>
|
||||
<!--
|
||||
<target name="test" depends="build">
|
||||
<nunit2outproc>
|
||||
<formatter type="Plain" />
|
||||
<formatter type="Xml" usefile="true" extension=".xml" outputdir="${current.bin.dir}/results" />
|
||||
<test assemblyname="${current.bin.dir}/${project::get-name()}.dll" />
|
||||
</nunit2outproc>
|
||||
</target>
|
||||
-->
|
||||
</project>
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using System.Web.Mvc;
|
||||
using Spring.Web.Mvc.Tests.Controllers;
|
||||
using Spring.Context.Support;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Spring.Web.Mvc.Tests
|
||||
{
|
||||
internal class MockContext : HttpContextBase { }
|
||||
|
||||
[TestFixture]
|
||||
public class SpringControllerFactoryTests
|
||||
{
|
||||
private MvcApplicationContext _context;
|
||||
private MvcApplicationContext _mvcNamedContext;
|
||||
private SpringControllerFactory _factory;
|
||||
|
||||
[SetUp]
|
||||
public void _TestSetup()
|
||||
{
|
||||
ContextRegistry.Clear();
|
||||
_context = new MvcApplicationContext("assembly://Spring.Web.Mvc.Tests/Spring.Web.Mvc.Tests/objects.xml");
|
||||
_mvcNamedContext = new MvcApplicationContext("named", false, "assembly://Spring.Web.Mvc.Tests/Spring.Web.Mvc.Tests/namedContextObjects.xml");
|
||||
|
||||
ContextRegistry.RegisterContext(_context);
|
||||
ContextRegistry.RegisterContext(_mvcNamedContext);
|
||||
|
||||
_factory = new SpringControllerFactory();
|
||||
|
||||
//due to ridiculous internal methods in DefaultControllerFactory, have to set the ControllerTypeCache using this extension method
|
||||
// see http://stackoverflow.com/questions/727181/asp-net-mvc-system-web-compilation-compilationlock for more info
|
||||
_factory.InitializeWithControllerTypes(new[]
|
||||
{
|
||||
typeof(FirstContainerRegisteredController),
|
||||
typeof(SecondContainerRegisteredController),
|
||||
typeof(NotInContainerController),
|
||||
typeof(NamedContextController),
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProperlyResolvesCaseInsensitiveControllerNames()
|
||||
{
|
||||
IController pascalcaseController = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "FirstContainerRegistered");
|
||||
IController lowercaseController = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "firstcontainerregistered");
|
||||
|
||||
Assert.AreEqual(typeof(FirstContainerRegisteredController), pascalcaseController.GetType());
|
||||
Assert.AreEqual(typeof(FirstContainerRegisteredController), lowercaseController.GetType());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanPreferIdMatchOverTypeMatch()
|
||||
{
|
||||
IController controller = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "FirstContainerRegistered");
|
||||
Assert.AreEqual("Should_Be_Matched_By_Id", ((FirstContainerRegisteredController)controller).TestValue);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CanRevertToTypeMatchIfIdMatchUnsuccessful()
|
||||
{
|
||||
MvcApplicationContext context = new MvcApplicationContext("assembly://Spring.Web.Mvc.Tests/Spring.Web.Mvc.Tests/objectsMatchByType.xml");
|
||||
|
||||
ContextRegistry.Clear();
|
||||
ContextRegistry.RegisterContext(context);
|
||||
|
||||
IController controller = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "FirstContainerRegistered");
|
||||
|
||||
Assert.AreEqual("Should_Be_Matched_By_Type", ((FirstContainerRegisteredController)controller).TestValue);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CanRetrieveControllersNotRegisteredWithContainer()
|
||||
{
|
||||
_factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "NotInContainer");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CanUseNamedContextToResolveController()
|
||||
{
|
||||
SpringControllerFactory.ApplicationContextName = "named";
|
||||
IController controller = _factory.CreateController(new RequestContext(new MockContext(), new RouteData()), "NamedContext");
|
||||
|
||||
Assert.NotNull(controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
test/Spring/Spring.Web.Mvc.Tests/namedContextObjects.xml
Normal file
7
test/Spring/Spring.Web.Mvc.Tests/namedContextObjects.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
|
||||
<object id="NamedContextController" singleton="false" type="Spring.Web.Mvc.Tests.Controllers.NamedContextController, Spring.Web.Mvc.Tests"/>
|
||||
</objects>
|
||||
|
||||
19
test/Spring/Spring.Web.Mvc.Tests/objects.xml
Normal file
19
test/Spring/Spring.Web.Mvc.Tests/objects.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
|
||||
|
||||
<!--id/name intentionally excluded from this definition so that we can ensure retrieve-by-type-match works-->
|
||||
<object singleton="false" type="Spring.Web.Mvc.Tests.Controllers.FirstContainerRegisteredController, Spring.Web.Mvc.Tests">
|
||||
<property name="TestValue" value="Should_Be_Matched_By_Type" />
|
||||
</object>
|
||||
|
||||
<!--this object defintion matches the controller name that would be retrieved based on the actual request-->
|
||||
<object id="FirstContainerRegistered" singleton="false" type="Spring.Web.Mvc.Tests.Controllers.FirstContainerRegisteredController, Spring.Web.Mvc.Tests">
|
||||
<property name="TestValue" value="Should_Be_Matched_By_Id" />
|
||||
</object>
|
||||
|
||||
<object id="SecondContainerRegisteredController" singleton="false" type="Spring.Web.Mvc.Tests.Controllers.SecondContainerRegisteredController, Spring.Web.Mvc.Tests"/>
|
||||
|
||||
</objects>
|
||||
|
||||
12
test/Spring/Spring.Web.Mvc.Tests/objectsMatchByType.xml
Normal file
12
test/Spring/Spring.Web.Mvc.Tests/objectsMatchByType.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
|
||||
|
||||
<!--id/name intentionally excluded from this definition so that we can ensure retrieve-by-type-match works-->
|
||||
<object singleton="false" type="Spring.Web.Mvc.Tests.Controllers.FirstContainerRegisteredController, Spring.Web.Mvc.Tests">
|
||||
<property name="TestValue" value="Should_Be_Matched_By_Type" />
|
||||
</object>
|
||||
|
||||
</objects>
|
||||
|
||||
Reference in New Issue
Block a user