Skip to content

Commit e7a6d6b

Browse files
Add test case for deletion of component with null property
Demonstrate #1170 - Incorrect query when items removed from a collection of components contain null values
1 parent 87893ab commit e7a6d6b

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System.Linq;
12+
using NUnit.Framework;
13+
using NHibernate.Linq;
14+
15+
namespace NHibernate.Test.NHSpecificTest.GH1170
16+
{
17+
using System.Threading.Tasks;
18+
[TestFixture]
19+
public class FixtureAsync : BugTestCase
20+
{
21+
[Test, KnownBug("GH1170")]
22+
public async Task DeleteComponentWithNullAsync()
23+
{
24+
using (var session = OpenSession())
25+
using (var tx = session.BeginTransaction())
26+
{
27+
var parent = await (session.Query<Parent>().SingleAsync());
28+
Assert.That(
29+
parent.ChildComponents,
30+
Has.Count.EqualTo(2).And.One.Property(nameof(ChildComponent.SomeString)).Null);
31+
parent.ChildComponents.Remove(parent.ChildComponents.Single(c => c.SomeString == null));
32+
await (tx.CommitAsync());
33+
}
34+
35+
using (var session = OpenSession())
36+
using (var tx = session.BeginTransaction())
37+
{
38+
var parent = await (session.Query<Parent>().SingleAsync());
39+
Assert.That(
40+
parent.ChildComponents,
41+
Has.Count.EqualTo(1).And.None.Property(nameof(ChildComponent.SomeString)).Null);
42+
await (tx.CommitAsync());
43+
}
44+
}
45+
46+
protected override void OnSetUp()
47+
{
48+
using (var session = OpenSession())
49+
using (var tx = session.BeginTransaction())
50+
{
51+
var parent = new Parent();
52+
parent.ChildComponents.Add(new ChildComponent { SomeBool = true, SomeString = "something" });
53+
parent.ChildComponents.Add(new ChildComponent { SomeBool = false, SomeString = null });
54+
session.Save(parent);
55+
56+
tx.Commit();
57+
}
58+
}
59+
60+
protected override void OnTearDown()
61+
{
62+
using (var session = OpenSession())
63+
using (var tx = session.BeginTransaction())
64+
{
65+
session.Delete("from Parent");
66+
tx.Commit();
67+
}
68+
}
69+
}
70+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Linq;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH1170
5+
{
6+
[TestFixture]
7+
public class Fixture : BugTestCase
8+
{
9+
[Test, KnownBug("GH1170")]
10+
public void DeleteComponentWithNull()
11+
{
12+
using (var session = OpenSession())
13+
using (var tx = session.BeginTransaction())
14+
{
15+
var parent = session.Query<Parent>().Single();
16+
Assert.That(
17+
parent.ChildComponents,
18+
Has.Count.EqualTo(2).And.One.Property(nameof(ChildComponent.SomeString)).Null);
19+
parent.ChildComponents.Remove(parent.ChildComponents.Single(c => c.SomeString == null));
20+
tx.Commit();
21+
}
22+
23+
using (var session = OpenSession())
24+
using (var tx = session.BeginTransaction())
25+
{
26+
var parent = session.Query<Parent>().Single();
27+
Assert.That(
28+
parent.ChildComponents,
29+
Has.Count.EqualTo(1).And.None.Property(nameof(ChildComponent.SomeString)).Null);
30+
tx.Commit();
31+
}
32+
}
33+
34+
protected override void OnSetUp()
35+
{
36+
using (var session = OpenSession())
37+
using (var tx = session.BeginTransaction())
38+
{
39+
var parent = new Parent();
40+
parent.ChildComponents.Add(new ChildComponent { SomeBool = true, SomeString = "something" });
41+
parent.ChildComponents.Add(new ChildComponent { SomeBool = false, SomeString = null });
42+
session.Save(parent);
43+
44+
tx.Commit();
45+
}
46+
}
47+
48+
protected override void OnTearDown()
49+
{
50+
using (var session = OpenSession())
51+
using (var tx = session.BeginTransaction())
52+
{
53+
session.Delete("from Parent");
54+
tx.Commit();
55+
}
56+
}
57+
}
58+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.GH1170">
5+
<class name="Parent">
6+
<id name="Id" column="id_column_of_parent">
7+
<generator class="guid" />
8+
</id>
9+
<set name="ChildComponents">
10+
<key column="key_column_of_child" />
11+
<composite-element class="ChildComponent">
12+
<property name="SomeBool" />
13+
<property name="SomeString" />
14+
</composite-element>
15+
</set>
16+
</class>
17+
</hibernate-mapping>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH1170
5+
{
6+
public class Parent
7+
{
8+
public Parent()
9+
{
10+
ChildComponents = new List<ChildComponent>();
11+
}
12+
13+
public virtual ICollection<ChildComponent> ChildComponents { get; set; }
14+
public virtual Guid Id { get; set; }
15+
}
16+
17+
public class ChildComponent
18+
{
19+
public virtual bool SomeBool { get; set; }
20+
public virtual string SomeString { get; set; }
21+
}
22+
}

0 commit comments

Comments
 (0)