Permalink
Browse files

Refinement and consolidation of tests for NH-3010

Contributed by cremor.
  • Loading branch information...
julian-maughan committed Feb 23, 2012
1 parent 39f3a7c commit 2ebf7419acdd5e5e841199057ae16a6320cab432
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
- assembly="NHibernate.Test"
- namespace="NHibernate.Test.NHSpecificTest.NH2527">
- <class name="Parent">
- <id name="Id">
- <generator class="guid" />
- </id>
- <list name="Childs" cascade="all-delete-orphan" fetch="subselect">
- <key column="parent_id" />
- <index column="pos" />
- <one-to-many class="Child" />
- </list>
- </class>
-
- <class name="Child">
- <id name="Id">
- <generator class="guid" />
- </id>
- </class>
-</hibernate-mapping>
@@ -1,17 +0,0 @@
-namespace NHibernate.Test.NHSpecificTest.NH2527 {
- using System;
- using System.Collections.Generic;
-
- public class Parent {
- public Parent() {
- Childs = new List<Child>();
- }
-
- public virtual Guid Id { get; set; }
- public virtual IList<Child> Childs { get; set; }
- }
-
- public class Child {
- public virtual Guid Id { get; set; }
- }
-}
@@ -0,0 +1,102 @@
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH3010
+{
+ public class FixtureWithBatcher : BugTestCase
+ {
+ protected override void Configure(Cfg.Configuration configuration)
+ {
+ configuration.DataBaseIntegration(x =>
+ {
+ x.BatchSize = 10;
+ });
+ }
+
+ protected override void OnSetUp()
+ {
+ base.OnSetUp();
+
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var parent = new Parent();
+ var childOne = new Child();
+ parent.Childs.Add(childOne);
+ session.Save(parent);
+
+ tx.Commit();
+ }
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ base.OnTearDown();
+
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ session.Delete("from Child");
+ session.Delete("from Parent");
+ tx.Commit();
+ }
+ }
+ }
+
+ // Test case from NH-2527
+ [Test]
+ public void DisposedCommandShouldNotBeReusedAfterRemoveAtAndInsert()
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var parent = session.CreateCriteria<Parent>().UniqueResult<Parent>();
+
+ Child childOne = parent.Childs[0];
+
+ var childTwo = new Child();
+ parent.Childs.Add(childTwo);
+
+ Child childToMove = parent.Childs[1];
+ parent.Childs.RemoveAt(1);
+ parent.Childs.Insert(0, childToMove);
+
+ Assert.DoesNotThrow(() => { tx.Commit(); });
+
+ Assert.AreEqual(childTwo.Id, parent.Childs[0].Id);
+ Assert.AreEqual(childOne.Id, parent.Childs[1].Id);
+ }
+ }
+ }
+
+ // Test case from NH-1477
+ [Test]
+ public void DisposedCommandShouldNotBeReusedAfterClearAndAdd()
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var parent = session.CreateCriteria<Parent>().UniqueResult<Parent>();
+
+ parent.Childs.Clear();
+
+ var childOne = new Child();
+ parent.Childs.Add(childOne);
+
+ var childTwo = new Child();
+ parent.Childs.Add(childTwo);
+
+ Assert.DoesNotThrow(() => { tx.Commit(); });
+
+ Assert.AreEqual(childOne.Id, parent.Childs[0].Id);
+ Assert.AreEqual(childTwo.Id, parent.Childs[1].Id);
+ }
+ }
+ }
+ }
+}
@@ -1,20 +1,18 @@
using NHibernate.AdoNet;
using NHibernate.Cfg;
-using NHibernate.Cfg.Loquacious;
using NUnit.Framework;
-namespace NHibernate.Test.NHSpecificTest.NH2527
+namespace NHibernate.Test.NHSpecificTest.NH3010
{
public class FixtureWithNoBatcher : BugTestCase
{
-
protected override void Configure(Cfg.Configuration configuration)
{
configuration.DataBaseIntegration(x =>
- {
- x.BatchSize = 0;
- x.Batcher<NonBatchingBatcherFactory>();
- });
+ {
+ x.BatchSize = 0;
+ x.Batcher<NonBatchingBatcherFactory>();
+ });
}
protected override void OnSetUp()
@@ -50,8 +48,9 @@ protected override void OnTearDown()
}
}
+ // Test case from NH-2527
[Test]
- public void DisposedCommandShouldNotBeReused()
+ public void DisposedCommandShouldNotBeReusedAfterRemoveAtAndInsert()
{
using (ISession session = OpenSession())
{
@@ -75,5 +74,31 @@ public void DisposedCommandShouldNotBeReused()
}
}
}
+
+ // Test case from NH-1477
+ [Test]
+ public void DisposedCommandShouldNotBeReusedAfterClearAndAdd()
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var parent = session.CreateCriteria<Parent>().UniqueResult<Parent>();
+
+ parent.Childs.Clear();
+
+ var childOne = new Child();
+ parent.Childs.Add(childOne);
+
+ var childTwo = new Child();
+ parent.Childs.Add(childTwo);
+
+ Assert.DoesNotThrow(() => { tx.Commit(); });
+
+ Assert.AreEqual(childOne.Id, parent.Childs[0].Id);
+ Assert.AreEqual(childTwo.Id, parent.Childs[1].Id);
+ }
+ }
+ }
}
}
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH3010">
+ <class name="Parent">
+ <id name="Id">
+ <generator class="guid" />
+ </id>
+ <list name="Childs" cascade="all-delete-orphan" fetch="subselect">
+ <key column="parent_id" />
+ <index column="pos" />
+ <one-to-many class="Child" />
+ </list>
+ </class>
+
+ <class name="Child">
+ <id name="Id">
+ <generator class="guid" />
+ </id>
+ </class>
+</hibernate-mapping>
@@ -0,0 +1,21 @@
+namespace NHibernate.Test.NHSpecificTest.NH3010
+{
+ using System;
+ using System.Collections.Generic;
+
+ public class Parent
+ {
+ public Parent()
+ {
+ Childs = new List<Child>();
+ }
+
+ public virtual Guid Id { get; set; }
+ public virtual IList<Child> Childs { get; set; }
+ }
+
+ public class Child
+ {
+ public virtual Guid Id { get; set; }
+ }
+}
@@ -865,8 +865,6 @@
<Compile Include="NHSpecificTest\NH2507\Animal.cs" />
<Compile Include="NHSpecificTest\NH2507\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2510\Fixture.cs" />
- <Compile Include="NHSpecificTest\NH2527\FixtureWithNoBatcher.cs" />
- <Compile Include="NHSpecificTest\NH2527\Model.cs" />
<Compile Include="NHSpecificTest\NH2530\Domain.cs" />
<Compile Include="NHSpecificTest\NH2530\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2546\Model.cs" />
@@ -947,6 +945,9 @@
<Compile Include="NHSpecificTest\NH2960\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2959\Entity.cs" />
<Compile Include="NHSpecificTest\NH2959\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH3010\FixtureWithBatcher.cs" />
+ <Compile Include="NHSpecificTest\NH3010\FixtureWithNoBatcher.cs" />
+ <Compile Include="NHSpecificTest\NH3010\Model.cs" />
<Compile Include="NHSpecificTest\NH2982\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2982\Model.cs" />
<Compile Include="NHSpecificTest\NH3004\Fixture.cs" />
@@ -2810,6 +2811,7 @@
<Compile Include="IdGen\Enhanced\Forcedtable\BasicForcedTableSequenceTest.cs" />
<Compile Include="IdGen\Enhanced\Forcedtable\HiLoForcedTableSequenceTest.cs" />
<Compile Include="IdGen\Enhanced\Forcedtable\PooledForcedTableSequenceTest.cs" />
+ <EmbeddedResource Include="NHSpecificTest\NH3010\Mappings.hbm.xml" />
<EmbeddedResource Include="MappingByCode\IntegrationTests\NH2825\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2880\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2982\Mappings.hbm.xml" />
@@ -2877,7 +2879,6 @@
<EmbeddedResource Include="NHSpecificTest\NH2488\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2490\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1925\Mappings.hbm.xml" />
- <EmbeddedResource Include="NHSpecificTest\NH2527\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1323\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2580\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2390\Mappings.hbm.xml" />

0 comments on commit 2ebf741

Please sign in to comment.