Skip to content

Commit 294d186

Browse files
committed
Test case
1 parent 7cc1307 commit 294d186

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.Generic;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NHibernate.Transform;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH3169
8+
{
9+
[TestFixture]
10+
public class ByCodeFixture : TestCaseMappingByCode
11+
{
12+
public class ResultDto
13+
{
14+
public string regionCode { get; set; }
15+
}
16+
17+
protected override HbmMapping GetMappings()
18+
{
19+
var mapper = new ModelMapper();
20+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
21+
}
22+
23+
24+
[Test]
25+
public void CachedQueryWithTransformer()
26+
{
27+
IList<ResultDto> GetCacheableSqlQueryResults(ISession s)
28+
{
29+
return s.CreateSQLQuery(
30+
"select 'REGIONCODE' as regionCode ")
31+
.AddScalar("regionCode", NHibernateUtil.String)
32+
.SetResultTransformer(Transformers.AliasToBean<ResultDto>())
33+
.SetCacheable(true)
34+
.List<ResultDto>();
35+
}
36+
37+
using (var session = OpenSession())
38+
{
39+
using (EnableStatisticsScope())
40+
{
41+
var l = GetCacheableSqlQueryResults(session);
42+
Assert.AreEqual(1, l.Count);
43+
//Uncomment if we properly fix caching auto discovery type queries with transformers
44+
//Assert.That(Sfi.Statistics.QueryCacheMissCount, Is.EqualTo(1), "results are expected from DB");
45+
//Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(0), "results are expected from DB");
46+
}
47+
48+
using (EnableStatisticsScope())
49+
{
50+
var l2 = GetCacheableSqlQueryResults(session);
51+
Assert.AreEqual(1, l2.Count);
52+
//Uncomment if we properly fix caching auto discovery type queries with transformers
53+
//Assert.That(Sfi.Statistics.QueryCacheMissCount, Is.EqualTo(0), "results are expected from cache");
54+
//Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1), "results are expected from cache");
55+
}
56+
}
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)