|
| 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.Collections.Generic; |
| 12 | +using NHibernate.Cfg.MappingSchema; |
| 13 | +using NHibernate.Mapping.ByCode; |
| 14 | +using NHibernate.Transform; |
| 15 | +using NUnit.Framework; |
| 16 | + |
| 17 | +namespace NHibernate.Test.NHSpecificTest.GH3169 |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + [TestFixture] |
| 21 | + public class ByCodeFixtureAsync : TestCaseMappingByCode |
| 22 | + { |
| 23 | + public class ResultDto |
| 24 | + { |
| 25 | + public string regionCode { get; set; } |
| 26 | + } |
| 27 | + |
| 28 | + protected override HbmMapping GetMappings() |
| 29 | + { |
| 30 | + var mapper = new ModelMapper(); |
| 31 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 32 | + } |
| 33 | + |
| 34 | + |
| 35 | + [Test] |
| 36 | + public async Task CachedQueryWithTransformerAsync() |
| 37 | + { |
| 38 | + Task<IList<ResultDto>> GetCacheableSqlQueryResultsAsync(ISession s) |
| 39 | + { |
| 40 | + try |
| 41 | + { |
| 42 | + return s.CreateSQLQuery( |
| 43 | + "select 'REGIONCODE' as regionCode ") |
| 44 | + .AddScalar("regionCode", NHibernateUtil.String) |
| 45 | + .SetResultTransformer(Transformers.AliasToBean<ResultDto>()) |
| 46 | + .SetCacheable(true) |
| 47 | + .ListAsync<ResultDto>(); |
| 48 | + } |
| 49 | + catch (System.Exception ex) |
| 50 | + { |
| 51 | + return Task.FromException<IList<ResultDto>>(ex); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + using (var session = OpenSession()) |
| 56 | + { |
| 57 | + using (EnableStatisticsScope()) |
| 58 | + { |
| 59 | + var l = await (GetCacheableSqlQueryResultsAsync(session)); |
| 60 | + Assert.AreEqual(1, l.Count); |
| 61 | + //Uncomment if we properly fix caching auto discovery type queries with transformers |
| 62 | + //Assert.That(Sfi.Statistics.QueryCacheMissCount, Is.EqualTo(1), "results are expected from DB"); |
| 63 | + //Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(0), "results are expected from DB"); |
| 64 | + } |
| 65 | + |
| 66 | + using (EnableStatisticsScope()) |
| 67 | + { |
| 68 | + var l2 = await (GetCacheableSqlQueryResultsAsync(session)); |
| 69 | + Assert.AreEqual(1, l2.Count); |
| 70 | + //Uncomment if we properly fix caching auto discovery type queries with transformers |
| 71 | + //Assert.That(Sfi.Statistics.QueryCacheMissCount, Is.EqualTo(0), "results are expected from cache"); |
| 72 | + //Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1), "results are expected from cache"); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments