@@ -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 ]
@@ -130,7 +158,7 @@ public void VerifyProxyForClassWithInternalInterface()
130
158
}
131
159
132
160
[ Test ]
133
- public void VerifyProxyForClassWithAdditionalInterface ( )
161
+ public void VerifyProxyOnInterface ( )
134
162
{
135
163
var factory = new StaticProxyFactory ( ) ;
136
164
factory . PostInstantiate (
@@ -139,7 +167,7 @@ public void VerifyProxyForClassWithAdditionalInterface()
139
167
// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
140
168
// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
141
169
// having an additional interface in the interface list, instead of just having INHibernateProxy.
142
- // (Quite a loosy semantic...)
170
+ // (Quite a loose semantic...)
143
171
new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
144
172
null , null , null ) ;
145
173
@@ -157,6 +185,69 @@ public void VerifyProxyForClassWithAdditionalInterface()
157
185
#endif
158
186
}
159
187
188
+ [ Test ]
189
+ public void VerifyProxyForClassWithAdditionalInterface ( )
190
+ {
191
+ var factory = new StaticProxyFactory ( ) ;
192
+ factory . PostInstantiate (
193
+ typeof ( PublicInterfaceTestClass ) . FullName ,
194
+ typeof ( PublicInterfaceTestClass ) ,
195
+ new HashSet < System . Type > { typeof ( INHibernateProxy ) } ,
196
+ null , null , null ) ;
197
+
198
+ #if NETFX
199
+ VerifyGeneratedAssembly (
200
+ ( ) =>
201
+ {
202
+ #endif
203
+ var proxy = factory . GetProxy ( 1 , null ) ;
204
+ Assert . That ( proxy , Is . Not . Null ) ;
205
+ Assert . That ( proxy , Is . InstanceOf < IPublic > ( ) ) ;
206
+ Assert . That ( proxy , Is . InstanceOf < PublicInterfaceTestClass > ( ) ) ;
207
+
208
+ // Check interface and implicit implementations do both call the delegated state
209
+ var state = new PublicInterfaceTestClass { Id = 5 , Name = "State" } ;
210
+ proxy . HibernateLazyInitializer . SetImplementation ( state ) ;
211
+ var pub = ( IPublic ) proxy ;
212
+ var ent = ( PublicInterfaceTestClass ) proxy ;
213
+ Assert . That ( pub . Id , Is . EqualTo ( 5 ) , "IPublic.Id" ) ;
214
+ Assert . That ( ent . Id , Is . EqualTo ( 5 ) , "entity.Id" ) ;
215
+ Assert . That ( pub . Name , Is . EqualTo ( "State" ) , "IPublic.State" ) ;
216
+ Assert . That ( ent . Name , Is . EqualTo ( "State" ) , "entity.State" ) ;
217
+ ent . Id = 10 ;
218
+ pub . Name = "Test" ;
219
+ Assert . That ( pub . Id , Is . EqualTo ( 10 ) , "IPublic.Id" ) ;
220
+ Assert . That ( state . Id , Is . EqualTo ( 10 ) , "state.Id" ) ;
221
+ Assert . That ( ent . Name , Is . EqualTo ( "Test" ) , "entity.Name" ) ;
222
+ Assert . That ( state . Name , Is . EqualTo ( "Test" ) , "state.Name" ) ;
223
+ #if NETFX
224
+ } ) ;
225
+ #endif
226
+ }
227
+
228
+ [ Test ]
229
+ public void VerifyProxyForClassWithAdditionalExplicitInterface ( )
230
+ {
231
+ var factory = new StaticProxyFactory ( ) ;
232
+ factory . PostInstantiate (
233
+ typeof ( PublicExplicitInterfaceTestClass ) . FullName ,
234
+ typeof ( PublicExplicitInterfaceTestClass ) ,
235
+ new HashSet < System . Type > { typeof ( INHibernateProxy ) } ,
236
+ null , null , null ) ;
237
+ #if NETFX
238
+ VerifyGeneratedAssembly (
239
+ ( ) =>
240
+ {
241
+ #endif
242
+ var proxy = factory . GetProxy ( 1 , null ) ;
243
+ Assert . That ( proxy , Is . Not . Null ) ;
244
+ Assert . That ( proxy , Is . InstanceOf < IPublic > ( ) ) ;
245
+ Assert . That ( proxy , Is . InstanceOf < PublicExplicitInterfaceTestClass > ( ) ) ;
246
+ #if NETFX
247
+ } ) ;
248
+ #endif
249
+ }
250
+
160
251
[ Test ]
161
252
public void VerifyProxyForAbstractClass ( )
162
253
{
@@ -331,10 +422,10 @@ public void VerifyFieldInterceptorProxyWithAdditionalInterface()
331
422
// By way of the "proxy" attribute on the "class" mapping, an interface to use for the
332
423
// lazy entity load proxy instead of the persistentClass can be specified. This is "translated" into
333
424
// having an additional interface in the interface list, instead of just having INHibernateProxy.
334
- // (Quite a loosy semantic...)
425
+ // (Quite a loose semantic...)
335
426
// The field interceptor proxy ignores this setting, as it does not delegate its implementation
336
427
// to an instance of the persistentClass, and so cannot implement interface methods if it does not
337
- // inherit the persitentClass .
428
+ // inherit the persistentClass .
338
429
new HashSet < System . Type > { typeof ( INHibernateProxy ) , typeof ( IPublic ) } ,
339
430
null , null , null ) ;
340
431
#if NETFX
0 commit comments