Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 27cb905

Browse filesBrowse files
Generate async files
1 parent ae83e33 commit 27cb905
Copy full SHA for 27cb905

File tree

1 file changed

+130
-0
lines changed
Filter options

1 file changed

+130
-0
lines changed
+130Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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.Cfg.MappingSchema;
14+
using NHibernate.Linq;
15+
using NHibernate.Mapping.ByCode;
16+
using NUnit.Framework;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH3643
19+
{
20+
using System.Threading.Tasks;
21+
using System.Threading;
22+
[TestFixture]
23+
public class FixtureByCodeAsync : TestCaseMappingByCode
24+
{
25+
protected override void Configure(Configuration configuration)
26+
{
27+
configuration.SetProperty(Environment.UseQueryCache, "true");
28+
configuration.SetProperty(Environment.GenerateStatistics, "true");
29+
}
30+
31+
protected override HbmMapping GetMappings()
32+
{
33+
var mapper = new ModelMapper();
34+
35+
mapper.Class<Entity>(
36+
rc =>
37+
{
38+
rc.Id(x => x.Id);
39+
rc.Bag(
40+
x => x.Children,
41+
m =>
42+
{
43+
m.Access(Accessor.Field);
44+
m.Key(k => k.Column("EntityId"));
45+
},
46+
r => r.OneToMany());
47+
48+
rc.Cache(
49+
cm =>
50+
{
51+
cm.Include(CacheInclude.All);
52+
cm.Usage(CacheUsage.ReadWrite);
53+
});
54+
});
55+
56+
mapper.Class<ChildEntity>(
57+
rc =>
58+
{
59+
rc.Id(x => x.Id);
60+
rc.Cache(
61+
cm =>
62+
{
63+
cm.Include(CacheInclude.All);
64+
cm.Usage(CacheUsage.ReadWrite);
65+
});
66+
});
67+
68+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
69+
}
70+
71+
protected override void OnSetUp()
72+
{
73+
using var session = OpenSession();
74+
using var transaction = session.BeginTransaction();
75+
76+
session.CreateSQLQuery(
77+
"INSERT INTO Entity (Id) VALUES (0)"
78+
).ExecuteUpdate();
79+
80+
session.CreateSQLQuery(
81+
"INSERT INTO ChildEntity (Id, EntityId) VALUES (0, 0)"
82+
).ExecuteUpdate();
83+
84+
session.CreateSQLQuery(
85+
"INSERT INTO ChildEntity (Id, EntityId) VALUES (1, 0)"
86+
).ExecuteUpdate();
87+
88+
transaction.Commit();
89+
}
90+
91+
protected override void OnTearDown()
92+
{
93+
using var session = OpenSession();
94+
using var transaction = session.BeginTransaction();
95+
96+
session.CreateSQLQuery("DELETE FROM ChildEntity").ExecuteUpdate();
97+
session.CreateSQLQuery("DELETE FROM Entity").ExecuteUpdate();
98+
99+
transaction.Commit();
100+
}
101+
102+
[Test]
103+
public async Task LoadsEntityWithEnumIdAndChildrenUsingQueryCacheAsync()
104+
{
105+
await (LoadEntityByNameWithQueryCacheAsync()); // warm up cache
106+
107+
var entity = await (LoadEntityByNameWithQueryCacheAsync());
108+
109+
Assert.That(entity.Children.Count(), Is.EqualTo(2));
110+
111+
Assert.That(Sfi.Statistics.QueryExecutionCount, Is.EqualTo(1), "Unexpected execution count");
112+
Assert.That(Sfi.Statistics.QueryCachePutCount, Is.EqualTo(1), "Unexpected cache put count");
113+
Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1), "Unexpected cache hit count");
114+
}
115+
116+
private async Task<Entity> LoadEntityByNameWithQueryCacheAsync(CancellationToken cancellationToken = default(CancellationToken))
117+
{
118+
using var session = OpenSession();
119+
using var transaction = session.BeginTransaction();
120+
var entity = (await (session
121+
.Query<Entity>()
122+
.FetchMany(x => x.Children)
123+
.WithOptions(opt => opt.SetCacheable(true))
124+
.ToListAsync(cancellationToken)))[0];
125+
126+
await (transaction.CommitAsync(cancellationToken));
127+
return entity;
128+
}
129+
}
130+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.