From: <fab...@us...> - 2009-02-03 22:32:24
|
Revision: 4026 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4026&view=rev Author: fabiomaulo Date: 2009-02-03 22:32:20 +0000 (Tue, 03 Feb 2009) Log Message: ----------- Simple Pagination test Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Pagination/ trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.cs trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.hbm.xml trunk/nhibernate/src/NHibernate.Test/Pagination/PaginationFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-03 20:14:58 UTC (rev 4025) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-03 22:32:20 UTC (rev 4026) @@ -855,6 +855,8 @@ <Compile Include="Operations\PersonalDetails.cs" /> <Compile Include="Operations\TimestampedEntity.cs" /> <Compile Include="Operations\VersionedEntity.cs" /> + <Compile Include="Pagination\DataPoint.cs" /> + <Compile Include="Pagination\PaginationFixture.cs" /> <Compile Include="ProjectionFixtures\Key.cs" /> <Compile Include="ProjectionFixtures\Fixture.cs" /> <Compile Include="ProjectionFixtures\NodeType.cs" /> @@ -1614,6 +1616,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="Pagination\DataPoint.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\DateTime2AndDateTimeOffSet\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\Futures\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1643\Mappings.hbm.xml" /> Added: trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.cs 2009-02-03 22:32:20 UTC (rev 4026) @@ -0,0 +1,10 @@ +namespace NHibernate.Test.Pagination +{ + public class DataPoint + { + public virtual long Id { get; set; } + public virtual double X { get; set; } + public virtual double Y { get; set; } + public virtual string Description { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Pagination/DataPoint.hbm.xml 2009-02-03 22:32:20 UTC (rev 4026) @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.Pagination"> + + <class name="DataPoint" dynamic-update="true"> + <!--rowid="rowid"--> + <!-- remove this if not oracle --> + <id name="Id"> + <generator class="increment"/> + </id> + <property name="X"> + <column name="xval" not-null="true" precision="4" unique-key="xy"/> + </property> + <property name="Y"> + <column name="yval" not-null="true" precision="4" unique-key="xy"/> + </property> + <property name="Description"/> + </class> + +</hibernate-mapping> + Added: trunk/nhibernate/src/NHibernate.Test/Pagination/PaginationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Pagination/PaginationFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Pagination/PaginationFixture.cs 2009-02-03 22:32:20 UTC (rev 4026) @@ -0,0 +1,73 @@ +using System; +using System.Collections; +using NHibernate.Cfg; +using NHibernate.Criterion; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; +using Environment=NHibernate.Cfg.Environment; + +namespace NHibernate.Test.Pagination +{ + [TestFixture] + public class PaginationFixture : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override IList Mappings + { + get { return new[] {"Pagination.DataPoint.hbm.xml"}; } + } + + protected override void Configure(Configuration configuration) + { + cfg.SetProperty(Environment.DefaultBatchFetchSize, "20"); + } + + protected override string CacheConcurrencyStrategy + { + get { return null; } + } + + [Test] + public void PagTest() + { + using(ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + for (int i = 0; i < 10; i++) + { + var dp = new DataPoint {X = (i * 0.1d)}; + dp.Y = Math.Cos(dp.X); + s.Persist(dp); + } + t.Commit(); + } + + using(ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + int size = + s.CreateSQLQuery("select Id, xval, yval, Description from DataPoint order by xval, yval").AddEntity( + typeof (DataPoint)).SetMaxResults(5).List().Count; + Assert.That(size, Is.EqualTo(5)); + size = s.CreateQuery("from DataPoint dp order by dp.X, dp.Y").SetFirstResult(5).SetMaxResults(2).List().Count; + Assert.That(size, Is.EqualTo(2)); + size = + s.CreateCriteria(typeof (DataPoint)).AddOrder(Order.Asc("X")).AddOrder(Order.Asc("Y")).SetFirstResult(8).List(). + Count; + Assert.That(size, Is.EqualTo(2)); + t.Commit(); + } + + using(ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from DataPoint"); + t.Commit(); + } + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |