|
| 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.Dialect; |
| 13 | +using NHibernate.Linq; |
| 14 | +using NHibernate.Transform; |
| 15 | +using NUnit.Framework; |
| 16 | + |
| 17 | +namespace NHibernate.Test.NHSpecificTest.GH1994 |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + [TestFixture] |
| 21 | + public class FixtureAsync : BugTestCase |
| 22 | + { |
| 23 | + protected override void OnSetUp() |
| 24 | + { |
| 25 | + using (var session = OpenSession()) |
| 26 | + using (var transaction = session.BeginTransaction()) |
| 27 | + { |
| 28 | + var a = new Asset(); |
| 29 | + a.Documents.Add(new Document { IsDeleted = true }); |
| 30 | + a.Documents.Add(new Document { IsDeleted = false }); |
| 31 | + |
| 32 | + session.Save(a); |
| 33 | + transaction.Commit(); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + protected override void OnTearDown() |
| 38 | + { |
| 39 | + using (var session = OpenSession()) |
| 40 | + using (var transaction = session.BeginTransaction()) |
| 41 | + { |
| 42 | + // The HQL delete does all the job inside the database without loading the entities, but it does |
| 43 | + // not handle delete order for avoiding violating constraints if any. Use |
| 44 | + // session.Delete("from System.Object"); |
| 45 | + // instead if in need of having NHibernate ordering the deletes, but this will cause |
| 46 | + // loading the entities in the session. |
| 47 | + |
| 48 | + session.Delete("from System.Object"); |
| 49 | + |
| 50 | + transaction.Commit(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + [Test] |
| 55 | + public async Task TestUnfilteredLinqQueryAsync() |
| 56 | + { |
| 57 | + using (var s = OpenSession()) |
| 58 | + { |
| 59 | + var query = await (s.Query<Asset>() |
| 60 | + .FetchMany(x => x.Documents) |
| 61 | + .ToListAsync()); |
| 62 | + |
| 63 | + Assert.That(query.Count, Is.EqualTo(1), "unfiltered assets"); |
| 64 | + Assert.That(query[0].Documents.Count, Is.EqualTo(2), "unfiltered asset documents"); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + [Test] |
| 69 | + public async Task TestFilteredByWhereCollectionLinqQueryAsync() |
| 70 | + { |
| 71 | + if(Dialect is PostgreSQLDialect) |
| 72 | + Assert.Ignore("Dialect doesn't support 0/1 to bool implicit cast"); |
| 73 | + |
| 74 | + using (var s = OpenSession()) |
| 75 | + { |
| 76 | + var query = await (s.Query<Asset>() |
| 77 | + .FetchMany(x => x.DocumentsFiltered) |
| 78 | + .ToListAsync()); |
| 79 | + |
| 80 | + Assert.That(query.Count, Is.EqualTo(1), "unfiltered assets"); |
| 81 | + Assert.That(query[0].DocumentsFiltered.Count, Is.EqualTo(1), "unfiltered asset documents"); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + [Test] |
| 86 | + public async Task TestFilteredLinqQueryAsync() |
| 87 | + { |
| 88 | + using (var s = OpenSession()) |
| 89 | + { |
| 90 | + s.EnableFilter("deletedFilter").SetParameter("deletedParam", false); |
| 91 | + var query = await (s.Query<Asset>() |
| 92 | + .FetchMany(x => x.Documents) |
| 93 | + .ToListAsync()); |
| 94 | + |
| 95 | + Assert.That(query.Count, Is.EqualTo(1), "filtered assets"); |
| 96 | + Assert.That(query[0].Documents.Count, Is.EqualTo(1), "filtered asset documents"); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + [Test] |
| 101 | + public async Task TestFilteredQueryOverAsync() |
| 102 | + { |
| 103 | + using (var s = OpenSession()) |
| 104 | + { |
| 105 | + s.EnableFilter("deletedFilter").SetParameter("deletedParam", false); |
| 106 | + |
| 107 | + var query = await (s.QueryOver<Asset>() |
| 108 | + .Fetch(SelectMode.Fetch, x => x.Documents) |
| 109 | + .TransformUsing(Transformers.DistinctRootEntity) |
| 110 | + .ListAsync<Asset>()); |
| 111 | + |
| 112 | + Assert.That(query.Count, Is.EqualTo(1), "filtered assets"); |
| 113 | + Assert.That(query[0].Documents.Count, Is.EqualTo(1), "filtered asset documents"); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments