Skip to content

Failing test for NH3570. One test for unidirectional onetomany and one t... #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3570/BiFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using NUnit.Framework;
using SharpTestsEx;

namespace NHibernate.Test.NHSpecificTest.NH3570
{
[TestFixture]
public class BiFixture : BugTestCase
{
private Guid id;

[Test]
[KnownBug("NH-3570")]
public void ShouldNotSaveRemoveChild()
{
var parent = new BiParent();
parent.AddChild(new BiChild());
using (var s = OpenSession())
{
using (var tx = s.BeginTransaction())
{
id = (Guid)s.Save(parent);
parent.Children.Clear();
parent.AddChild(new BiChild());
tx.Commit();
}
}
using (var s = OpenSession())
{
using (s.BeginTransaction())
{
s.Get<BiParent>(id).Children.Count.Should().Be.EqualTo(1);
s.CreateCriteria<BiChild>().List().Count.Should().Be.EqualTo(1);
}
}
}

protected override void OnTearDown()
{
using (var s = OpenSession())
{
using (var tx = s.BeginTransaction())
{
s.CreateQuery("delete from BiChild").ExecuteUpdate();
s.CreateQuery("delete from BiParent").ExecuteUpdate();
tx.Commit();
}
}
}
}
}
36 changes: 36 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3570/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3570">
<class name="UniParent">
<id name="Id">
<generator class="guid.comb" />
</id>
<version name="Version"/>
<bag name="Children" cascade="all-delete-orphan">
<key column="parentId"/>
<one-to-many class="UniChild"/>
</bag>
</class>
<class name="UniChild">
<id name="Id">
<generator class="guid.comb" />
</id>
</class>

<class name="BiParent">
<id name="Id">
<generator class="guid.comb" />
</id>
<version name="Version"/>
<bag name="Children" cascade="all-delete-orphan" inverse="true">
<key column="parentId"/>
<one-to-many class="BiChild"/>
</bag>
</class>
<class name="BiChild">
<id name="Id">
<generator class="guid.comb" />
</id>
<many-to-one class="BiParent" name="Parent" column="parentId"/>
</class>
</hibernate-mapping>

46 changes: 46 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3570/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.NH3570
{
public class UniParent
{
public UniParent()
{
Children = new List<UniChild>();
}

public virtual Guid Id { get; set; }
public virtual IList<UniChild> Children { get; set; }
public virtual int Version { get; set; }
}

public class UniChild
{
public virtual Guid Id { get; set; }
}

public class BiParent
{
public BiParent()
{
Children = new List<BiChild>();
}

public virtual Guid Id { get; set; }
public virtual IList<BiChild> Children { get; set; }
public virtual int Version { get; set; }

public virtual void AddChild(BiChild child)
{
child.Parent = this;
Children.Add(child);
}
}

public class BiChild
{
public virtual Guid Id { get; set; }
public virtual BiParent Parent { get; set; }
}
}
51 changes: 51 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3570/UniFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using NUnit.Framework;
using SharpTestsEx;

namespace NHibernate.Test.NHSpecificTest.NH3570
{
[TestFixture]
public class UniFixture : BugTestCase
{
private Guid id;

[Test]
[KnownBug("NH-3570")]
public void ShouldNotSaveRemoveChild()
{
var parent = new UniParent();
parent.Children.Add(new UniChild());
using (var s = OpenSession())
{
using (var tx = s.BeginTransaction())
{
id = (Guid) s.Save(parent);
parent.Children.Clear();
parent.Children.Add(new UniChild());
tx.Commit();
}
}
using (var s = OpenSession())
{
using (s.BeginTransaction())
{
s.Get<UniParent>(id).Children.Count.Should().Be.EqualTo(1);
s.CreateCriteria<UniChild>().List().Count.Should().Be.EqualTo(1);
}
}
}

protected override void OnTearDown()
{
using (var s = OpenSession())
{
using (var tx = s.BeginTransaction())
{
s.CreateQuery("delete from UniChild").ExecuteUpdate();
s.CreateQuery("delete from UniParent").ExecuteUpdate();
tx.Commit();
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
<Compile Include="Linq\ByMethod\DistinctTests.cs" />
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
<Compile Include="NHSpecificTest\NH3570\BiFixture.cs" />
<Compile Include="NHSpecificTest\NH3570\Model.cs" />
<Compile Include="NHSpecificTest\NH3570\UniFixture.cs" />
<Compile Include="NHSpecificTest\NH3620\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3620\TwoBlobs.cs" />
<Compile Include="NHSpecificTest\NH3455\Address.cs" />
Expand Down Expand Up @@ -3054,6 +3057,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH3570\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3455\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3590\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3377\Mappings.hbm.xml" />
Expand Down