|
| 1 | +using NUnit.Framework; |
| 2 | + |
| 3 | +namespace NHibernate.Test.NHSpecificTest.GH1228 |
| 4 | +{ |
| 5 | + public class Fixture : BugTestCase |
| 6 | + { |
| 7 | + [Test] |
| 8 | + public void TestOk() |
| 9 | + { |
| 10 | + using (ISession s = OpenSession()) |
| 11 | + { |
| 12 | + using (ITransaction t = s.BeginTransaction()) |
| 13 | + { |
| 14 | + try |
| 15 | + { |
| 16 | + { |
| 17 | + var queryThatWorks = s.CreateQuery(@" |
| 18 | + SELECT ROOT FROM NHibernate.Test.NHSpecificTest.GH1228.Sheet AS ROOT |
| 19 | + WHERE (EXISTS (FROM NHibernate.Test.NHSpecificTest.GH1228.Shelf AS inv |
| 20 | + , ROOT.Folder AS ROOT_Folder |
| 21 | + WHERE ROOT_Folder.Shelf = inv AND inv.Id = 1 |
| 22 | + ) ) |
| 23 | + AND ROOT.Name = 'SomeName'"); |
| 24 | + queryThatWorks.List(); |
| 25 | + } |
| 26 | + { |
| 27 | + var queryThatWorks = s.CreateQuery(@" |
| 28 | + SELECT ROOT FROM NHibernate.Test.NHSpecificTest.GH1228.Shelf AS ROOT |
| 29 | + WHERE (EXISTS (FROM NHibernate.Test.NHSpecificTest.GH1228.Sheet AS sheet |
| 30 | + , ROOT.Folders AS ROOT_Folder |
| 31 | + WHERE ROOT_Folder = sheet.Folder AND sheet.Name = 'SomeName' |
| 32 | + ) ) |
| 33 | + AND ROOT.Id = 1"); |
| 34 | + queryThatWorks.List(); |
| 35 | + } |
| 36 | + } |
| 37 | + finally |
| 38 | + { |
| 39 | + s.Delete("from Sheet"); |
| 40 | + s.Delete("from Folder"); |
| 41 | + s.Delete("from Shelf"); |
| 42 | + t.Commit(); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + [Test] |
| 49 | + public void TestWrongSql() |
| 50 | + { |
| 51 | + using (ISession s = OpenSession()) |
| 52 | + { |
| 53 | + using (ITransaction t = s.BeginTransaction()) |
| 54 | + { |
| 55 | + try |
| 56 | + { |
| 57 | + { |
| 58 | + var queryThatCreatesWrongSQL = s.CreateQuery(@" |
| 59 | + SELECT ROOT FROM NHibernate.Test.NHSpecificTest.GH1228.Sheet AS ROOT |
| 60 | + WHERE (EXISTS (FROM NHibernate.Test.NHSpecificTest.GH1228.Shelf AS inv |
| 61 | + JOIN ROOT.Folder AS ROOT_Folder |
| 62 | + WHERE ROOT_Folder.Shelf = inv AND inv.Id = 1 |
| 63 | + ) ) |
| 64 | + AND ROOT.Name = 'SomeName'"); |
| 65 | + queryThatCreatesWrongSQL.List(); |
| 66 | + } |
| 67 | + { |
| 68 | + // The only assertion here is that the generated SQL is valid and can be executed. |
| 69 | + // Right now, the generated SQL is missing the JOIN inside the subselect (EXISTS) to Folder. |
| 70 | + var queryThatCreatesWrongSQL = s.CreateQuery(@" |
| 71 | + SELECT ROOT FROM NHibernate.Test.NHSpecificTest.GH1228.Shelf AS ROOT |
| 72 | + WHERE (EXISTS (FROM NHibernate.Test.NHSpecificTest.GH1228.Sheet AS sheet |
| 73 | + JOIN ROOT.Folders AS ROOT_Folder |
| 74 | + WHERE ROOT_Folder = sheet.Folder AND sheet.Name = 'SomeName' |
| 75 | + ) ) |
| 76 | + AND ROOT.Id = 1"); |
| 77 | + queryThatCreatesWrongSQL.List(); |
| 78 | + // The only assertion here is that the generated SQL is valid and can be executed. |
| 79 | + // Right now, the generated SQL is missing the JOIN inside the subselect (EXISTS) to Folder. |
| 80 | + } |
| 81 | + } |
| 82 | + finally |
| 83 | + { |
| 84 | + s.Delete("from Sheet"); |
| 85 | + s.Delete("from Folder"); |
| 86 | + s.Delete("from Shelf"); |
| 87 | + t.Commit(); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + [Test] |
| 94 | + public void Test3() { |
| 95 | + using (ISession s = OpenSession()) { |
| 96 | + using (ITransaction t = s.BeginTransaction()) { |
| 97 | + try { |
| 98 | + { |
| 99 | + // The only assertion here is that the generated SQL is valid and can be executed. |
| 100 | + // Right now, the generated SQL is missing the JOIN inside the subselect (EXISTS) to Folder. |
| 101 | + var queryThatCreatesWrongSQL = s.CreateQuery(@" |
| 102 | + SELECT ROOT FROM NHibernate.Test.NHSpecificTest.GH1228.Shelf AS ROOT |
| 103 | + WHERE (EXISTS (FROM NHibernate.Test.NHSpecificTest.GH1228.Sheet AS sheet |
| 104 | + JOIN sheet.Folder AS folder |
| 105 | + WHERE folder.Shelf = ROOT AND sheet.Name = 'SomeName' |
| 106 | + ) ) |
| 107 | + AND ROOT.Id = 1"); |
| 108 | + queryThatCreatesWrongSQL.List(); |
| 109 | + // The only assertion here is that the generated SQL is valid and can be executed. |
| 110 | + // Right now, the generated SQL is missing the JOIN inside the subselect (EXISTS) to Folder. |
| 111 | + } |
| 112 | + { |
| 113 | + var queryThatCreatesWrongSQL = s.CreateQuery(@" |
| 114 | + SELECT ROOT FROM NHibernate.Test.NHSpecificTest.GH1228.Sheet AS ROOT |
| 115 | + WHERE (EXISTS (FROM NHibernate.Test.NHSpecificTest.GH1228.Shelf AS inv |
| 116 | + JOIN inv.Folders AS folder |
| 117 | + WHERE folder = ROOT.Folder AND inv.Id = 1 |
| 118 | + ) ) |
| 119 | + AND ROOT.Name = 'SomeName'"); |
| 120 | + queryThatCreatesWrongSQL.List(); |
| 121 | + } |
| 122 | + } |
| 123 | + finally { |
| 124 | + s.Delete("from Sheet"); |
| 125 | + s.Delete("from Folder"); |
| 126 | + s.Delete("from Shelf"); |
| 127 | + t.Commit(); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments