@@ -33,13 +33,41 @@ 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
+ Assert . That ( Id , Is . Zero ) ;
50
+ Assert . That ( Name , Is . Null ) ;
51
+ Id = - 1 ;
52
+ Name = string . Empty ;
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
+ Assert . That ( pub . Id , Is . Zero ) ;
67
+ Assert . That ( pub . Name , Is . Null ) ;
68
+ pub . Id = - 1 ;
69
+ pub . Name = string . Empty ;
70
+ }
43
71
}
44
72
45
73
[ Serializable ]
@@ -172,7 +200,7 @@ public void VerifyProxyForClassWithAdditionalInterface()
172
200
// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
173
201
// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
174
202
// having an additional interface in the interface list, instead of just having INHibernateProxy.
175
- // (Quite a loosy semantic...)
203
+ // (Quite a loose semantic...)
176
204
new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
177
205
null , null , null ) ;
178
206
@@ -190,6 +218,85 @@ public void VerifyProxyForClassWithAdditionalInterface()
190
218
#endif
191
219
}
192
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
+
193
300
[ Test ]
194
301
public void VerifyProxyForRefOutClass ( )
195
302
{
@@ -409,10 +516,10 @@ public void VerifyFieldInterceptorProxyWithAdditionalInterface()
409
516
// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
410
517
// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
411
518
// having an additional interface in the interface list, instead of just having INHibernateProxy.
412
- // (Quite a loosy semantic...)
519
+ // (Quite a loose semantic...)
413
520
// The field interceptor proxy ignores this setting, as it does not delegate its implementation
414
521
// to an instance of the persistentClass, and so cannot implement interface methods if it does not
415
- // inherit the persitentClass .
522
+ // inherit the persistentClass .
416
523
new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
417
524
null , null , null ) ;
418
525
#if NETFX
0 commit comments