Skip to content

Commit 2742b57

Browse files
authored
Test Case for Invalid SQL with property-ref on property using a formula (#3309)
1 parent e65ab36 commit 2742b57

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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;
12+
using System.Linq;
13+
using NUnit.Framework;
14+
using NHibernate.Linq;
15+
16+
namespace NHibernate.Test.NHSpecificTest.GH1313
17+
{
18+
using System.Threading.Tasks;
19+
[TestFixture]
20+
public class FixtureAsync : BugTestCase
21+
{
22+
protected override void OnSetUp()
23+
{
24+
using var session = OpenSession();
25+
using var transaction = session.BeginTransaction();
26+
27+
var account = new Account { Id = 1, Name = "Account_1", OldAccountNumber = 1 };
28+
var order = new HoldClose
29+
{
30+
Account = account,
31+
CloseDate = new DateTime(2023, 1, 1)
32+
};
33+
34+
session.Save(account);
35+
session.Save(order);
36+
transaction.Commit();
37+
}
38+
39+
protected override void OnTearDown()
40+
{
41+
using var session = OpenSession();
42+
using var transaction = session.BeginTransaction();
43+
44+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
45+
transaction.Commit();
46+
}
47+
48+
[Test]
49+
[Explicit("Not fixed yet")]
50+
public async Task ManyToOneTargettingAFormulaAsync()
51+
{
52+
using var session = OpenSession();
53+
using var transaction = session.BeginTransaction();
54+
55+
var result = session.Query<HoldClose>();
56+
57+
Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
58+
await (transaction.CommitAsync());
59+
}
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH1313
2+
{
3+
public class Account
4+
{
5+
public virtual int Id { get; set; }
6+
public virtual string Name { get; set; }
7+
public virtual int OldAccountNumber { get; set; }
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.GH1313
6+
{
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
protected override void OnSetUp()
11+
{
12+
using var session = OpenSession();
13+
using var transaction = session.BeginTransaction();
14+
15+
var account = new Account { Id = 1, Name = "Account_1", OldAccountNumber = 1 };
16+
var order = new HoldClose
17+
{
18+
Account = account,
19+
CloseDate = new DateTime(2023, 1, 1)
20+
};
21+
22+
session.Save(account);
23+
session.Save(order);
24+
transaction.Commit();
25+
}
26+
27+
protected override void OnTearDown()
28+
{
29+
using var session = OpenSession();
30+
using var transaction = session.BeginTransaction();
31+
32+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
33+
transaction.Commit();
34+
}
35+
36+
[Test]
37+
[Explicit("Not fixed yet")]
38+
public void ManyToOneTargettingAFormula()
39+
{
40+
using var session = OpenSession();
41+
using var transaction = session.BeginTransaction();
42+
43+
var result = session.Query<HoldClose>();
44+
45+
Assert.That(result.ToList(), Has.Count.EqualTo(1));
46+
transaction.Commit();
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH1313
4+
{
5+
public class HoldClose
6+
{
7+
public virtual int Id { get; set; }
8+
public virtual Account Account { get; set; }
9+
public virtual DateTime CloseDate { get; set; }
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH1313">
4+
5+
<class name="HoldClose" >
6+
<id name="Id" generator="native"/>
7+
<many-to-one name="Account" class="Account" column="accountnumber" property-ref="OldAccountNumber"/>
8+
<property name="CloseDate" />
9+
</class>
10+
<class name="Account" >
11+
<id name="Id" generator="assigned"/>
12+
<property name="Name"/>
13+
<property name="OldAccountNumber" insert="false" update="false" generated="never" >
14+
<formula>convert(int,substring([Oldaccountnumber],3,8))</formula>
15+
</property>
16+
</class>
17+
18+
</hibernate-mapping>

0 commit comments

Comments
 (0)