Skip to content

Test Case for Invalid SQL with property-ref on property using a formula #3309

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
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
61 changes: 61 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH1313/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Linq;
using NUnit.Framework;
using NHibernate.Linq;

namespace NHibernate.Test.NHSpecificTest.GH1313
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
protected override void OnSetUp()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var account = new Account { Id = 1, Name = "Account_1", OldAccountNumber = 1 };
var order = new HoldClose
{
Account = account,
CloseDate = new DateTime(2023, 1, 1)
};

session.Save(account);
session.Save(order);
transaction.Commit();
}

protected override void OnTearDown()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();

session.CreateQuery("delete from System.Object").ExecuteUpdate();
transaction.Commit();
}

[Test]
[Explicit("Not fixed yet")]
public async Task ManyToOneTargettingAFormulaAsync()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var result = session.Query<HoldClose>();

Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
await (transaction.CommitAsync());
}
}
}
9 changes: 9 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1313/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NHibernate.Test.NHSpecificTest.GH1313
{
public class Account
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int OldAccountNumber { get; set; }
}
}
49 changes: 49 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1313/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH1313
{
[TestFixture]
public class Fixture : BugTestCase
{
protected override void OnSetUp()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var account = new Account { Id = 1, Name = "Account_1", OldAccountNumber = 1 };
var order = new HoldClose
{
Account = account,
CloseDate = new DateTime(2023, 1, 1)
};

session.Save(account);
session.Save(order);
transaction.Commit();
}

protected override void OnTearDown()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();

session.CreateQuery("delete from System.Object").ExecuteUpdate();
transaction.Commit();
}

[Test]
[Explicit("Not fixed yet")]
Copy link
Member

@fredericDelaporte fredericDelaporte Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not fixed yet, marking as explicit allows the test case to be ignored by the CI. This will have to be removed once the trouble is fixed.

public void ManyToOneTargettingAFormula()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();

var result = session.Query<HoldClose>();

Assert.That(result.ToList(), Has.Count.EqualTo(1));
transaction.Commit();
}
}
}
11 changes: 11 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1313/HoldClose.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace NHibernate.Test.NHSpecificTest.GH1313
{
public class HoldClose
{
public virtual int Id { get; set; }
public virtual Account Account { get; set; }
public virtual DateTime CloseDate { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1313/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH1313">

<class name="HoldClose" >
<id name="Id" generator="native"/>
<many-to-one name="Account" class="Account" column="accountnumber" property-ref="OldAccountNumber"/>
<property name="CloseDate" />
</class>
<class name="Account" >
<id name="Id" generator="assigned"/>
<property name="Name"/>
<property name="OldAccountNumber" insert="false" update="false" generated="never" >
<formula>convert(int,substring([Oldaccountnumber],3,8))</formula>
</property>
</class>

</hibernate-mapping>