@@ -33,13 +33,57 @@ public class InternalInterfaceTestClass : IInternal
33
33
34
34
public interface IPublic
35
35
{
36
- int Id { get ; }
36
+ int Id { get ; set ; }
37
+ string Name { get ; set ; }
37
38
}
38
39
39
40
[ Serializable ]
40
41
public class PublicInterfaceTestClass : IPublic
41
42
{
42
43
public virtual int Id { get ; set ; }
44
+ public virtual string Name { get ; set ; }
45
+
46
+ public PublicInterfaceTestClass ( )
47
+ {
48
+ // Check access to properties from the default constructor do not fail once proxified
49
+ Id = - 1 ;
50
+ Assert . That ( Id , Is . EqualTo ( - 1 ) ) ;
51
+ Name = "Unknown" ;
52
+ Assert . That ( Name , Is . EqualTo ( "Unknown" ) ) ;
53
+ }
54
+ }
55
+
56
+ [ Serializable ]
57
+ public class PublicExplicitInterfaceTestClass : IPublic
58
+ {
59
+ int IPublic . Id { get ; set ; }
60
+ string IPublic . Name { get ; set ; }
61
+
62
+ public PublicExplicitInterfaceTestClass ( )
63
+ {
64
+ // Check access to properties from the default constructor do not fail once proxified
65
+ IPublic pub = this ;
66
+ pub . Id = - 1 ;
67
+ Assert . That ( pub . Id , Is . EqualTo ( - 1 ) ) ;
68
+ pub . Name = "Unknown" ;
69
+ Assert . That ( pub . Name , Is . EqualTo ( "Unknown" ) ) ;
70
+ }
71
+ }
72
+
73
+ [ Serializable ]
74
+ public abstract class AbstractTestClass : IPublic
75
+ {
76
+ protected AbstractTestClass ( )
77
+ {
78
+ Id = - 1 ;
79
+ Assert . That ( Id , Is . Zero ) ;
80
+ Name = "Unknown" ;
81
+ Assert . That ( Name , Is . Null ) ;
82
+ }
83
+
84
+ public abstract int Id { get ; set ; }
85
+
86
+ public abstract string Name { get ; set ; }
43
87
}
44
88
45
89
[ Serializable ]
@@ -156,8 +200,8 @@ public void VerifyProxyForClassWithAdditionalInterface()
156
200
// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
157
201
// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
158
202
// having an additional interface in the interface list, instead of just having INHibernateProxy.
159
- // (Quite a loosy semantic...)
160
- new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
203
+ // (Quite a loose semantic...)
204
+ new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
161
205
null , null , null ) ;
162
206
163
207
#if NETFX
@@ -174,6 +218,85 @@ public void VerifyProxyForClassWithAdditionalInterface()
174
218
#endif
175
219
}
176
220
221
+ [ Test ]
222
+ public void VerifyProxyForClassWithInterface ( )
223
+ {
224
+ var factory = new StaticProxyFactory ( ) ;
225
+ factory . PostInstantiate (
226
+ typeof ( PublicInterfaceTestClass ) . FullName ,
227
+ typeof ( PublicInterfaceTestClass ) ,
228
+ new HashSet < System . Type > { typeof ( INHibernateProxy ) } ,
229
+ null , null , null ) ;
230
+
231
+ #if NETFX
232
+ VerifyGeneratedAssembly (
233
+ ( ) =>
234
+ {
235
+ #endif
236
+ var proxy = factory . GetProxy ( 1 , null ) ;
237
+ Assert . That ( proxy , Is . Not . Null ) ;
238
+ Assert . That ( proxy , Is . InstanceOf < IPublic > ( ) ) ;
239
+ Assert . That ( proxy , Is . InstanceOf < PublicInterfaceTestClass > ( ) ) ;
240
+
241
+ // Check interface and implicit implementations do both call the delegated state
242
+ var state = new PublicInterfaceTestClass { Id = 5 , Name = "State" } ;
243
+ proxy . HibernateLazyInitializer . SetImplementation ( state ) ;
244
+ var pub = ( IPublic ) proxy ;
245
+ var ent = ( PublicInterfaceTestClass ) proxy ;
246
+ Assert . That ( pub . Id , Is . EqualTo ( 5 ) , "IPublic.Id" ) ;
247
+ Assert . That ( ent . Id , Is . EqualTo ( 5 ) , "entity.Id" ) ;
248
+ Assert . That ( pub . Name , Is . EqualTo ( "State" ) , "IPublic.Name" ) ;
249
+ Assert . That ( ent . Name , Is . EqualTo ( "State" ) , "entity.Name" ) ;
250
+ ent . Id = 10 ;
251
+ pub . Name = "Test" ;
252
+ Assert . That ( pub . Id , Is . EqualTo ( 10 ) , "IPublic.Id" ) ;
253
+ Assert . That ( state . Id , Is . EqualTo ( 10 ) , "state.Id" ) ;
254
+ Assert . That ( ent . Name , Is . EqualTo ( "Test" ) , "entity.Name" ) ;
255
+ Assert . That ( state . Name , Is . EqualTo ( "Test" ) , "state.Name" ) ;
256
+ #if NETFX
257
+ } ) ;
258
+ #endif
259
+ }
260
+
261
+ [ Test ]
262
+ public void VerifyProxyForClassWithExplicitInterface ( )
263
+ {
264
+ var factory = new StaticProxyFactory ( ) ;
265
+ factory . PostInstantiate (
266
+ typeof ( PublicExplicitInterfaceTestClass ) . FullName ,
267
+ typeof ( PublicExplicitInterfaceTestClass ) ,
268
+ new HashSet < System . Type > { typeof ( INHibernateProxy ) } ,
269
+ null , null , null ) ;
270
+ #if NETFX
271
+ VerifyGeneratedAssembly (
272
+ ( ) =>
273
+ {
274
+ #endif
275
+ var proxy = factory . GetProxy ( 1 , null ) ;
276
+ Assert . That ( proxy , Is . Not . Null ) ;
277
+ Assert . That ( proxy , Is . InstanceOf < IPublic > ( ) ) ;
278
+ Assert . That ( proxy , Is . InstanceOf < PublicExplicitInterfaceTestClass > ( ) ) ;
279
+
280
+ // Check interface and implicit implementations do both call the delegated state
281
+ IPublic state = new PublicExplicitInterfaceTestClass ( ) ;
282
+ state . Id = 5 ;
283
+ state . Name = "State" ;
284
+ proxy . HibernateLazyInitializer . SetImplementation ( state ) ;
285
+ var entity = ( IPublic ) proxy ;
286
+ Assert . That ( entity . Id , Is . EqualTo ( 5 ) , "Id" ) ;
287
+ Assert . That ( entity . Name , Is . EqualTo ( "State" ) , "Name" ) ;
288
+
289
+ entity . Id = 10 ;
290
+ entity . Name = "Test" ;
291
+ Assert . That ( entity . Id , Is . EqualTo ( 10 ) , "entity.Id" ) ;
292
+ Assert . That ( state . Id , Is . EqualTo ( 10 ) , "state.Id" ) ;
293
+ Assert . That ( entity . Name , Is . EqualTo ( "Test" ) , "entity.Name" ) ;
294
+ Assert . That ( state . Name , Is . EqualTo ( "Test" ) , "state.Name" ) ;
295
+ #if NETFX
296
+ } ) ;
297
+ #endif
298
+ }
299
+
177
300
[ Test ]
178
301
public void VerifyProxyForRefOutClass ( )
179
302
{
@@ -219,6 +342,30 @@ public void VerifyProxyForRefOutClass()
219
342
#endif
220
343
}
221
344
345
+ [ Test ]
346
+ public void VerifyProxyForAbstractClass ( )
347
+ {
348
+ var factory = new StaticProxyFactory ( ) ;
349
+ factory . PostInstantiate (
350
+ typeof ( AbstractTestClass ) . FullName ,
351
+ typeof ( AbstractTestClass ) ,
352
+ new HashSet < System . Type > { typeof ( INHibernateProxy ) } ,
353
+ null , null , null ) ;
354
+
355
+ #if NETFX
356
+ VerifyGeneratedAssembly (
357
+ ( ) =>
358
+ {
359
+ #endif
360
+ var proxy = factory . GetProxy ( 1 , null ) ;
361
+ Assert . That ( proxy , Is . Not . Null ) ;
362
+ Assert . That ( proxy , Is . InstanceOf < IPublic > ( ) ) ;
363
+ Assert . That ( proxy , Is . InstanceOf < AbstractTestClass > ( ) ) ;
364
+ #if NETFX
365
+ } ) ;
366
+ #endif
367
+ }
368
+
222
369
[ Test ]
223
370
public void InitializedProxyStaysInitializedAfterDeserialization ( )
224
371
{
@@ -369,10 +516,10 @@ public void VerifyFieldInterceptorProxyWithAdditionalInterface()
369
516
// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
370
517
// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
371
518
// having an additional interface in the interface list, instead of just having INHibernateProxy.
372
- // (Quite a loosy semantic...)
519
+ // (Quite a loose semantic...)
373
520
// The field interceptor proxy ignores this setting, as it does not delegate its implementation
374
521
// to an instance of the persistentClass, and so cannot implement interface methods if it does not
375
- // inherit the persitentClass .
522
+ // inherit the persistentClass .
376
523
new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
377
524
null , null , null ) ;
378
525
#if NETFX
0 commit comments