10
10
11
11
using System ;
12
12
using System . Linq ;
13
- using NHibernate . Cfg ;
14
13
using NHibernate . Cfg . MappingSchema ;
15
14
using NHibernate . Mapping . ByCode ;
16
15
using NUnit . Framework ;
@@ -22,9 +21,7 @@ namespace NHibernate.Test.NHSpecificTest.GH2043
22
21
[ TestFixture ]
23
22
public class FixtureAsync : TestCaseMappingByCode
24
23
{
25
- private Guid _entityWithClassProxy1Id ;
26
24
private Guid _entityWithClassProxy2Id ;
27
- private Guid _entityWithInterfaceProxy1Id ;
28
25
private Guid _entityWithInterfaceProxy2Id ;
29
26
private Guid _entityWithClassLookupId ;
30
27
private Guid _entityWithInterfaceLookupId ;
@@ -34,6 +31,7 @@ protected override HbmMapping GetMappings()
34
31
var mapper = new ModelMapper ( ) ;
35
32
mapper . Class < EntityWithClassProxyDefinition > ( rc =>
36
33
{
34
+ rc . Table ( "ProxyDefinition" ) ;
37
35
rc . Proxy ( typeof ( EntityWithClassProxyDefinition ) ) ;
38
36
39
37
rc . Id ( x => x . Id ) ;
@@ -42,6 +40,7 @@ protected override HbmMapping GetMappings()
42
40
43
41
mapper . Class < EntityWithInterfaceProxyDefinition > ( rc =>
44
42
{
43
+ rc . Table ( "IProxyDefinition" ) ;
45
44
rc . Proxy ( typeof ( IEntityProxy ) ) ;
46
45
47
46
rc . Id ( x => x . Id ) ;
@@ -69,13 +68,13 @@ protected override HbmMapping GetMappings()
69
68
protected override void OnSetUp ( )
70
69
{
71
70
using ( var session = OpenSession ( ) )
71
+ using ( var transaction = session . BeginTransaction ( ) )
72
72
{
73
73
var entityCP1 = new EntityWithClassProxyDefinition
74
74
{
75
75
Id = Guid . NewGuid ( ) ,
76
76
Name = "Name 1"
77
77
} ;
78
- _entityWithClassProxy1Id = entityCP1 . Id ;
79
78
80
79
var entityCP2 = new EntityWithClassProxyDefinition
81
80
{
@@ -89,7 +88,6 @@ protected override void OnSetUp()
89
88
Id = Guid . NewGuid ( ) ,
90
89
Name = "Name 1"
91
90
} ;
92
- _entityWithInterfaceProxy1Id = entityIP1 . Id ;
93
91
94
92
var entityIP2 = new EntityWithInterfaceProxyDefinition
95
93
{
@@ -123,21 +121,20 @@ protected override void OnSetUp()
123
121
session . Save ( entityIL ) ;
124
122
125
123
session . Flush ( ) ;
124
+ transaction . Commit ( ) ;
126
125
}
127
126
}
128
127
129
128
130
129
protected override void OnTearDown ( )
131
130
{
132
131
using ( var session = OpenSession ( ) )
132
+ using ( var transaction = session . BeginTransaction ( ) )
133
133
{
134
- using ( var transaction = session . BeginTransaction ( ) )
135
- {
136
- session . Delete ( "from System.Object" ) ;
134
+ session . Delete ( "from System.Object" ) ;
137
135
138
- session . Flush ( ) ;
139
- transaction . Commit ( ) ;
140
- }
136
+ session . Flush ( ) ;
137
+ transaction . Commit ( ) ;
141
138
}
142
139
}
143
140
@@ -146,38 +143,34 @@ protected override void OnTearDown()
146
143
public async Task UpdateEntityWithClassLookupAsync ( )
147
144
{
148
145
using ( var session = OpenSession ( ) )
146
+ using ( var transaction = session . BeginTransaction ( ) )
149
147
{
150
- using ( var transaction = session . BeginTransaction ( ) )
151
- {
152
- var entityToUpdate = await ( session . Query < EntityWithClassLookup > ( )
153
- . FirstAsync ( e => e . Id == _entityWithClassLookupId ) ) ;
148
+ var entityToUpdate = await ( session . Query < EntityWithClassLookup > ( )
149
+ . FirstAsync ( e => e . Id == _entityWithClassLookupId ) ) ;
154
150
155
- entityToUpdate . EntityLookup = ( EntityWithClassProxyDefinition ) await ( session . LoadAsync ( typeof ( EntityWithClassProxyDefinition ) , _entityWithClassProxy2Id ) ) ;
151
+ entityToUpdate . EntityLookup = ( EntityWithClassProxyDefinition ) await ( session . LoadAsync ( typeof ( EntityWithClassProxyDefinition ) , _entityWithClassProxy2Id ) ) ;
156
152
157
- await ( session . UpdateAsync ( entityToUpdate ) ) ;
158
- await ( session . FlushAsync ( ) ) ;
159
- await ( transaction . RollbackAsync ( ) ) ;
160
- }
153
+ await ( session . UpdateAsync ( entityToUpdate ) ) ;
154
+ await ( session . FlushAsync ( ) ) ;
155
+ await ( transaction . CommitAsync ( ) ) ;
161
156
}
162
157
}
163
158
164
159
165
160
[ Test ]
166
161
public async Task UpdateEntityWithInterfaceLookupAsync ( )
167
162
{
168
- using ( var session = OpenSession ( ) )
163
+ using ( var session = OpenSession ( ) )
164
+ using ( var transaction = session . BeginTransaction ( ) )
169
165
{
170
- using ( var transaction = session . BeginTransaction ( ) )
171
- {
172
- var entityToUpdate = await ( session . Query < EntityWithInterfaceLookup > ( )
173
- . FirstAsync ( e => e . Id == _entityWithInterfaceLookupId ) ) ;
166
+ var entityToUpdate = await ( session . Query < EntityWithInterfaceLookup > ( )
167
+ . FirstAsync ( e => e . Id == _entityWithInterfaceLookupId ) ) ;
174
168
175
- entityToUpdate . EntityLookup = ( IEntityProxy ) await ( session . LoadAsync ( typeof ( EntityWithInterfaceProxyDefinition ) , _entityWithInterfaceProxy2Id ) ) ;
169
+ entityToUpdate . EntityLookup = ( IEntityProxy ) await ( session . LoadAsync ( typeof ( EntityWithInterfaceProxyDefinition ) , _entityWithInterfaceProxy2Id ) ) ;
176
170
177
- await ( session . UpdateAsync ( entityToUpdate ) ) ;
178
- await ( session . FlushAsync ( ) ) ;
179
- await ( transaction . RollbackAsync ( ) ) ;
180
- }
171
+ await ( session . UpdateAsync ( entityToUpdate ) ) ;
172
+ await ( session . FlushAsync ( ) ) ;
173
+ await ( transaction . CommitAsync ( ) ) ;
181
174
}
182
175
}
183
176
}
0 commit comments