1- using System . Collections . Concurrent ;
1+ using System ;
2+ using System . Collections . Concurrent ;
23using System . Reflection ;
4+ using System . Runtime . Serialization ;
35using NHibernate . Proxy ;
46using NHibernate . Proxy . DynamicProxy ;
57using NUnit . Framework ;
68
79namespace NHibernate . Test . NHSpecificTest . NH3954
810{
9- [ TestFixture , Explicit ( "Demonstrates bug impact on cache, but which tests will fail is a bit unpredictable" ) ]
11+ [ TestFixture , Explicit ( "Demonstrates bug impact on cache, but which tests will fail is a bit unpredictable" ) , Obsolete ]
1012 public class ProxyCacheFixture
1113 {
1214 private ProxyCache _cache ;
13- private ConcurrentDictionary < ProxyCacheEntry , System . Type > _internalCache ;
15+ private ConcurrentDictionary < ProxyCacheEntry , TypeInfo > _internalCache ;
1416 private int _hashCode1 ;
1517 private int _hashCode2 ;
1618
1719 private static readonly FieldInfo InternalCacheField =
18- typeof ( ProxyCache ) . GetField ( "cache " , BindingFlags . Static | BindingFlags . NonPublic ) ;
20+ typeof ( ProxyFactory ) . GetField ( "_cache " , BindingFlags . Static | BindingFlags . NonPublic ) ;
1921
2022 [ SetUp ]
2123 public void SetUp ( )
2224 {
2325 _cache = new ProxyCache ( ) ;
2426
25- _internalCache = ( ConcurrentDictionary < ProxyCacheEntry , System . Type > ) InternalCacheField . GetValue ( null ) ;
27+ _internalCache = ( ConcurrentDictionary < ProxyCacheEntry , TypeInfo > ) InternalCacheField . GetValue ( null ) ;
2628
2729 _cache . StoreProxyType ( typeof ( Entity1FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity1 ) ) ;
2830 _cache . StoreProxyType ( typeof ( Entity2FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity2 ) , typeof ( INHibernateProxy ) ) ;
2931 _cache . StoreProxyType ( typeof ( Entity3FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity3 ) ) ;
30- _cache . StoreProxyType ( typeof ( Entity4FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity4 ) , typeof ( IProxy ) ) ;
31- _cache . StoreProxyType ( typeof ( Entity5FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity5 ) , typeof ( INHibernateProxy ) , typeof ( IProxy ) ) ;
32+ _cache . StoreProxyType ( typeof ( Entity4FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity4 ) , typeof ( ISerializable ) ) ;
33+ _cache . StoreProxyType ( typeof ( Entity5FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity5 ) , typeof ( INHibernateProxy ) , typeof ( ISerializable ) ) ;
3234
3335 // Artificially inject other entries with same hashcodes
3436 _hashCode1 = new ProxyCacheEntry ( typeof ( Entity1 ) , null ) . GetHashCode ( ) ;
@@ -37,14 +39,14 @@ public void SetUp()
3739
3840 _hashCode2 = new ProxyCacheEntry ( typeof ( Entity2 ) , new [ ] { typeof ( INHibernateProxy ) } ) . GetHashCode ( ) ;
3941 Inject ( new ProxyCacheEntry ( typeof ( Entity2 ) , null ) , _hashCode2 , typeof ( Entity2FakeProxy2 ) ) ;
40- Inject ( new ProxyCacheEntry ( typeof ( Entity4 ) , new [ ] { typeof ( IProxy ) } ) , _hashCode2 , typeof ( Entity4FakeProxy2 ) ) ;
41- Inject ( new ProxyCacheEntry ( typeof ( Entity5 ) , new [ ] { typeof ( INHibernateProxy ) , typeof ( IProxy ) } ) , _hashCode2 , typeof ( Entity5FakeProxy2 ) ) ;
42+ Inject ( new ProxyCacheEntry ( typeof ( Entity4 ) , new [ ] { typeof ( ISerializable ) } ) , _hashCode2 , typeof ( Entity4FakeProxy2 ) ) ;
43+ Inject ( new ProxyCacheEntry ( typeof ( Entity5 ) , new [ ] { typeof ( INHibernateProxy ) , typeof ( ISerializable ) } ) , _hashCode2 , typeof ( Entity5FakeProxy2 ) ) ;
4244 }
4345
4446 private void Inject ( ProxyCacheEntry entryToTweak , int hashcode , System . Type result )
4547 {
4648 TweakEntry ( entryToTweak , hashcode ) ;
47- _internalCache [ entryToTweak ] = result ;
49+ _internalCache [ entryToTweak ] = result . GetTypeInfo ( ) ;
4850 }
4951
5052 private static readonly FieldInfo HashCodeField =
@@ -112,14 +114,14 @@ public void ProxyCacheEntity3FakeProxy2()
112114 [ Test ]
113115 public void ProxyCacheEntity4FakeProxy ( )
114116 {
115- var result = _cache . GetProxyType ( typeof ( Entity4 ) , typeof ( IProxy ) ) ;
117+ var result = _cache . GetProxyType ( typeof ( Entity4 ) , typeof ( ISerializable ) ) ;
116118 Assert . AreEqual ( typeof ( Entity4FakeProxy ) , result ) ;
117119 }
118120
119121 [ Test ]
120122 public void ProxyCacheEntity4FakeProxy2 ( )
121123 {
122- var entry = new ProxyCacheEntry ( typeof ( Entity4 ) , new [ ] { typeof ( IProxy ) } ) ;
124+ var entry = new ProxyCacheEntry ( typeof ( Entity4 ) , new [ ] { typeof ( ISerializable ) } ) ;
123125 TweakEntry ( entry , _hashCode2 ) ;
124126 var result = _internalCache [ entry ] ;
125127 Assert . AreEqual ( typeof ( Entity4FakeProxy2 ) , result ) ;
@@ -128,15 +130,15 @@ public void ProxyCacheEntity4FakeProxy2()
128130 [ Test ]
129131 public void ProxyCacheEntity5FakeProxy ( )
130132 {
131- var result = _cache . GetProxyType ( typeof ( Entity5 ) , typeof ( IProxy ) , typeof ( INHibernateProxy ) ) ;
133+ var result = _cache . GetProxyType ( typeof ( Entity5 ) , typeof ( ISerializable ) , typeof ( INHibernateProxy ) ) ;
132134 Assert . AreEqual ( typeof ( Entity5FakeProxy ) , result ) ;
133135 }
134136
135137 [ Test ]
136138 public void ProxyCacheEntity5FakeProxy2 ( )
137139 {
138140 // Interfaces order inverted on purpose: must be supported.
139- var entry = new ProxyCacheEntry ( typeof ( Entity5 ) , new [ ] { typeof ( IProxy ) , typeof ( INHibernateProxy ) } ) ;
141+ var entry = new ProxyCacheEntry ( typeof ( Entity5 ) , new [ ] { typeof ( ISerializable ) , typeof ( INHibernateProxy ) } ) ;
140142 TweakEntry ( entry , _hashCode2 ) ;
141143 var result = _internalCache [ entry ] ;
142144 Assert . AreEqual ( typeof ( Entity5FakeProxy2 ) , result ) ;
@@ -149,7 +151,7 @@ public void ProxyCacheNone()
149151 // (Otherwise the test may starts failing unexpectedly sometimes, as the original bug ...)
150152 // This one was not added in anyway.
151153 TypeInfo result ;
152- Assert . IsFalse ( _cache . TryGetProxyType ( typeof ( Entity2 ) , new [ ] { typeof ( IProxy ) } , out result ) ) ;
154+ Assert . IsFalse ( _cache . TryGetProxyType ( typeof ( Entity2 ) , new [ ] { typeof ( ISerializable ) } , out result ) ) ;
153155 }
154156 }
155- }
157+ }
0 commit comments