|
| 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 NHibernate.Criterion; |
| 13 | +using NHibernate.Linq; |
| 14 | +using NHibernate.Transform; |
| 15 | +using NUnit.Framework; |
| 16 | + |
| 17 | +namespace NHibernate.Test.NHSpecificTest.NH750 |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + [TestFixture] |
| 21 | + public class ManyToManyThrowsForNotFoundFixtureAsync : BugTestCase |
| 22 | + { |
| 23 | + private int _id; |
| 24 | + |
| 25 | + protected override void OnSetUp() |
| 26 | + { |
| 27 | + using (var s = Sfi.OpenSession()) |
| 28 | + using (var t = s.BeginTransaction()) |
| 29 | + { |
| 30 | + Device dv = new Device("Device"); |
| 31 | + Drive dr = new Drive("Drive"); |
| 32 | + s.Save(dr); |
| 33 | + dv.DrivesNotIgnored.Add(dr); |
| 34 | + |
| 35 | + _id = (int) s.Save(dv); |
| 36 | + s.Flush(); |
| 37 | + |
| 38 | + s.Clear(); |
| 39 | + s.Delete(dr); |
| 40 | + t.Commit(); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + protected override void OnTearDown() |
| 45 | + { |
| 46 | + using (var s = OpenSession()) |
| 47 | + using (var t = s.BeginTransaction()) |
| 48 | + { |
| 49 | + s.Delete("from Device"); |
| 50 | + s.Delete("from Drive"); |
| 51 | + t.Commit(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + [Test] |
| 56 | + public async Task LazyLoadAsync() |
| 57 | + { |
| 58 | + using var s = OpenSession(); |
| 59 | + var device = await (s.GetAsync<Device>(_id)); |
| 60 | + Assert.ThrowsAsync<ObjectNotFoundException>(() => NHibernateUtil.InitializeAsync(device.DrivesNotIgnored)); |
| 61 | + } |
| 62 | + |
| 63 | + [Test] |
| 64 | + public void QueryOverFetchAsync() |
| 65 | + { |
| 66 | + using var s = OpenSession(); |
| 67 | + var queryOver = s.QueryOver<Device>() |
| 68 | + .Fetch(SelectMode.Fetch, x => x.DrivesNotIgnored) |
| 69 | + .Where(Restrictions.IdEq(_id)) |
| 70 | + .TransformUsing(Transformers.DistinctRootEntity); |
| 71 | + Assert.ThrowsAsync<ObjectNotFoundException>(async () => await (NHibernateUtil.InitializeAsync(await (queryOver.SingleOrDefaultAsync())))); |
| 72 | + } |
| 73 | + |
| 74 | + [Test] |
| 75 | + public void LinqFetchAsync() |
| 76 | + { |
| 77 | + using var s = OpenSession(); |
| 78 | + var query = s.Query<Device>() |
| 79 | + |
| 80 | + .Fetch(x => x.DrivesNotIgnored) |
| 81 | + .Where(x => x.Id == _id); |
| 82 | + Assert.ThrowsAsync<ObjectNotFoundException>(async () => await (NHibernateUtil.InitializeAsync(await (query.SingleOrDefaultAsync())))); |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments