|
| 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.GH1921 |
| 16 | +{ |
| 17 | + using System.Threading.Tasks; |
| 18 | + using System.Threading; |
| 19 | + [TestFixture] |
| 20 | + public class FixtureAsync : BugTestCase |
| 21 | + { |
| 22 | + protected override bool AppliesTo(Dialect.Dialect dialect) |
| 23 | + { |
| 24 | + return TestDialect.NativeGeneratorSupportsBulkInsertion; |
| 25 | + } |
| 26 | + |
| 27 | + protected override void OnSetUp() |
| 28 | + { |
| 29 | + using (var session = OpenSession()) |
| 30 | + using (var transaction = session.BeginTransaction()) |
| 31 | + { |
| 32 | + var e1 = new Entity { Name = "Bob" }; |
| 33 | + session.Save(e1); |
| 34 | + |
| 35 | + var e2 = new Entity { Name = "Sally" }; |
| 36 | + session.Save(e2); |
| 37 | + |
| 38 | + var me1 = new MultiTableEntity { Name = "Bob", OtherName = "Bob" }; |
| 39 | + session.Save(me1); |
| 40 | + |
| 41 | + var me2 = new MultiTableEntity { Name = "Sally", OtherName = "Sally" }; |
| 42 | + session.Save(me2); |
| 43 | + |
| 44 | + transaction.Commit(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + protected override void OnTearDown() |
| 49 | + { |
| 50 | + using (var session = OpenSession()) |
| 51 | + using (var transaction = session.BeginTransaction()) |
| 52 | + { |
| 53 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 54 | + |
| 55 | + transaction.Commit(); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + [Theory] |
| 60 | + public async Task DmlInsertAsync(bool filtered) |
| 61 | + { |
| 62 | + using (var session = OpenSession()) |
| 63 | + using (var transaction = session.BeginTransaction()) |
| 64 | + { |
| 65 | + if (filtered) |
| 66 | + session.EnableFilter("NameFilter").SetParameter("name", "Bob"); |
| 67 | + var rowCount = await (session.CreateQuery("insert into Entity (Name) select e.Name from Entity e") |
| 68 | + .ExecuteUpdateAsync()); |
| 69 | + await (transaction.CommitAsync()); |
| 70 | + |
| 71 | + Assert.That(rowCount, Is.EqualTo(filtered ? 1 : 2)); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + [Theory] |
| 76 | + public async Task DmlUpdateAsync(bool filtered) |
| 77 | + { |
| 78 | + using (var session = OpenSession()) |
| 79 | + using (var transaction = session.BeginTransaction()) |
| 80 | + { |
| 81 | + if (filtered) |
| 82 | + session.EnableFilter("NameFilter").SetParameter("name", "Bob"); |
| 83 | + var rowCount = await (session.CreateQuery("update Entity e set Name = 'newName'").ExecuteUpdateAsync()); |
| 84 | + await (transaction.CommitAsync()); |
| 85 | + |
| 86 | + Assert.That(rowCount, Is.EqualTo(filtered ? 1 : 2)); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + [Theory] |
| 91 | + public async Task DmlDeleteAsync(bool filtered) |
| 92 | + { |
| 93 | + using (var session = OpenSession()) |
| 94 | + using (var transaction = session.BeginTransaction()) |
| 95 | + { |
| 96 | + if (filtered) |
| 97 | + session.EnableFilter("NameFilter").SetParameter("name", "Bob"); |
| 98 | + var rowCount = await (session.CreateQuery("delete Entity").ExecuteUpdateAsync()); |
| 99 | + await (transaction.CommitAsync()); |
| 100 | + |
| 101 | + Assert.That(rowCount, Is.EqualTo(filtered ? 1 : 2)); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + [TestCase(null)] |
| 106 | + [TestCase("NameFilter")] |
| 107 | + [TestCase("OtherNameFilter")] |
| 108 | + public async Task MultiTableDmlInsertAsync(string filter, CancellationToken cancellationToken = default(CancellationToken)) |
| 109 | + { |
| 110 | + var isFiltered = !string.IsNullOrEmpty(filter); |
| 111 | + |
| 112 | + using (var session = OpenSession()) |
| 113 | + using (var transaction = session.BeginTransaction()) |
| 114 | + { |
| 115 | + if (isFiltered) |
| 116 | + session.EnableFilter(filter).SetParameter("name", "Bob"); |
| 117 | + var rowCount = |
| 118 | + await (session |
| 119 | + .CreateQuery( |
| 120 | + // No insert of OtherName: not supported (INSERT statements cannot refer to superclass/joined properties) |
| 121 | + "insert into MultiTableEntity (Name) select e.Name from MultiTableEntity e") |
| 122 | + .ExecuteUpdateAsync(cancellationToken)); |
| 123 | + await (transaction.CommitAsync(cancellationToken)); |
| 124 | + |
| 125 | + Assert.That(rowCount, Is.EqualTo(isFiltered ? 1 : 2), "ResultCount"); |
| 126 | + } |
| 127 | + |
| 128 | + using (var session = OpenSession()) |
| 129 | + using (var transaction = session.BeginTransaction()) |
| 130 | + { |
| 131 | + Assert.That( |
| 132 | + await (session.Query<MultiTableEntity>().CountAsync(e => e.Name != "Bob", cancellationToken)), |
| 133 | + Is.EqualTo(isFiltered ? 1 : 2), "Name != \"Bob\""); |
| 134 | + Assert.That( |
| 135 | + await (session.Query<MultiTableEntity>().CountAsync(e => e.OtherName == null, cancellationToken)), |
| 136 | + Is.EqualTo(isFiltered ? 1 : 2), "OtherName is null"); |
| 137 | + await (transaction.CommitAsync(cancellationToken)); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + [TestCase(null)] |
| 142 | + [TestCase("NameFilter")] |
| 143 | + [TestCase("OtherNameFilter")] |
| 144 | + public async Task MultiTableDmlUpdateAsync(string filter, CancellationToken cancellationToken = default(CancellationToken)) |
| 145 | + { |
| 146 | + var isFiltered = !string.IsNullOrEmpty(filter); |
| 147 | + |
| 148 | + using (var session = OpenSession()) |
| 149 | + using (var transaction = session.BeginTransaction()) |
| 150 | + { |
| 151 | + if (isFiltered) |
| 152 | + session.EnableFilter(filter).SetParameter("name", "Bob"); |
| 153 | + var rowCount = |
| 154 | + await (session |
| 155 | + .CreateQuery( |
| 156 | + "update MultiTableEntity e" + |
| 157 | + " set Name = 'newName', OtherName = 'newOtherName'" + |
| 158 | + // Check referencing columns is supported |
| 159 | + " where e.Name is not null and e.OtherName is not null") |
| 160 | + .ExecuteUpdateAsync(cancellationToken)); |
| 161 | + await (transaction.CommitAsync(cancellationToken)); |
| 162 | + |
| 163 | + Assert.That(rowCount, Is.EqualTo(isFiltered ? 1 : 2), "ResultCount"); |
| 164 | + } |
| 165 | + |
| 166 | + using (var session = OpenSession()) |
| 167 | + using (var transaction = session.BeginTransaction()) |
| 168 | + { |
| 169 | + Assert.That( |
| 170 | + await (session.Query<MultiTableEntity>().CountAsync(e => e.Name == "newName", cancellationToken)), |
| 171 | + Is.EqualTo(isFiltered ? 1 : 2), "Name == \"newName\""); |
| 172 | + Assert.That( |
| 173 | + await (session.Query<MultiTableEntity>().CountAsync(e => e.OtherName == "newOtherName", cancellationToken)), |
| 174 | + Is.EqualTo(isFiltered ? 1 : 2), "Name == \"newOtherName\""); |
| 175 | + await (transaction.CommitAsync(cancellationToken)); |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + [TestCase(null)] |
| 180 | + [TestCase("NameFilter")] |
| 181 | + [TestCase("OtherNameFilter")] |
| 182 | + public async Task MultiTableDmlDeleteAsync(string filter, CancellationToken cancellationToken = default(CancellationToken)) |
| 183 | + { |
| 184 | + var isFiltered = !string.IsNullOrEmpty(filter); |
| 185 | + |
| 186 | + using (var session = OpenSession()) |
| 187 | + using (var transaction = session.BeginTransaction()) |
| 188 | + { |
| 189 | + if (isFiltered) |
| 190 | + session.EnableFilter(filter).SetParameter("name", "Bob"); |
| 191 | + var rowCount = |
| 192 | + await (session |
| 193 | + .CreateQuery( |
| 194 | + "delete MultiTableEntity e" + |
| 195 | + // Check referencing columns is supported |
| 196 | + " where e.Name is not null and e.OtherName is not null") |
| 197 | + .ExecuteUpdateAsync(cancellationToken)); |
| 198 | + await (transaction.CommitAsync(cancellationToken)); |
| 199 | + |
| 200 | + Assert.That(rowCount, Is.EqualTo(isFiltered ? 1 : 2), "ResultCount"); |
| 201 | + } |
| 202 | + |
| 203 | + using (var session = OpenSession()) |
| 204 | + using (var transaction = session.BeginTransaction()) |
| 205 | + { |
| 206 | + Assert.That( |
| 207 | + await (session.Query<MultiTableEntity>().CountAsync(e => e.Name != "Bob", cancellationToken)), |
| 208 | + Is.EqualTo(isFiltered ? 1 : 0), "Name != \"Bob\""); |
| 209 | + Assert.That( |
| 210 | + await (session.Query<MultiTableEntity>().CountAsync(e => e.OtherName != "Bob", cancellationToken)), |
| 211 | + Is.EqualTo(isFiltered ? 1 : 0), "OtherName != \"Bob\""); |
| 212 | + await (transaction.CommitAsync(cancellationToken)); |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | +} |
0 commit comments