|
| 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.Cfg; |
| 13 | +using NHibernate.Linq; |
| 14 | +using NHibernate.Test.CacheTest.Caches; |
| 15 | +using NUnit.Framework; |
| 16 | +using Environment = NHibernate.Cfg.Environment; |
| 17 | + |
| 18 | +namespace NHibernate.Test.CacheTest |
| 19 | +{ |
| 20 | + using System.Threading.Tasks; |
| 21 | + [TestFixture] |
| 22 | + public class SerializingCacheFixtureAsync : TestCase |
| 23 | + { |
| 24 | + protected override string[] Mappings => new[] |
| 25 | + { |
| 26 | + "CacheTest.ReadOnly.hbm.xml" |
| 27 | + }; |
| 28 | + |
| 29 | + protected override string MappingsAssembly => "NHibernate.Test"; |
| 30 | + |
| 31 | + protected override string CacheConcurrencyStrategy => null; |
| 32 | + |
| 33 | + protected override void Configure(Configuration configuration) |
| 34 | + { |
| 35 | + configuration.SetProperty(Environment.UseSecondLevelCache, "true"); |
| 36 | + configuration.SetProperty(Environment.UseQueryCache, "true"); |
| 37 | + configuration.SetProperty(Environment.CacheProvider, typeof(SerializingCacheProvider).AssemblyQualifiedName); |
| 38 | + configuration.SetProperty(Environment.SessionFactoryName, "SerializingCacheFactory"); |
| 39 | + } |
| 40 | + |
| 41 | + protected override void OnSetUp() |
| 42 | + { |
| 43 | + using (var s = Sfi.OpenSession()) |
| 44 | + using (var tx = s.BeginTransaction()) |
| 45 | + { |
| 46 | + var totalItems = 6; |
| 47 | + for (var i = 1; i <= totalItems; i++) |
| 48 | + { |
| 49 | + var parent = new ReadOnly |
| 50 | + { |
| 51 | + Name = $"Name{i}" |
| 52 | + }; |
| 53 | + for (var j = 1; j <= totalItems; j++) |
| 54 | + { |
| 55 | + var child = new ReadOnlyItem |
| 56 | + { |
| 57 | + Parent = parent |
| 58 | + }; |
| 59 | + parent.Items.Add(child); |
| 60 | + } |
| 61 | + s.Save(parent); |
| 62 | + } |
| 63 | + tx.Commit(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + protected override void OnTearDown() |
| 68 | + { |
| 69 | + using (var s = OpenSession()) |
| 70 | + using (var tx = s.BeginTransaction()) |
| 71 | + { |
| 72 | + s.CreateQuery("delete from ReadOnlyItem").ExecuteUpdate(); |
| 73 | + s.CreateQuery("delete from ReadOnly").ExecuteUpdate(); |
| 74 | + tx.Commit(); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + [Test] |
| 79 | + public async Task CachedQueryTestAsync() |
| 80 | + { |
| 81 | + // Put things in cache |
| 82 | + using (var s = Sfi.OpenSession()) |
| 83 | + using (var tx = s.BeginTransaction()) |
| 84 | + { |
| 85 | + var items = await (s.Query<ReadOnly>().WithOptions(o => o.SetCacheable(true)).ToListAsync()); |
| 86 | + Assert.That(items, Has.Count.GreaterThan(0)); |
| 87 | + await (tx.CommitAsync()); |
| 88 | + } |
| 89 | + |
| 90 | + RebuildSessionFactory(); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments