1
- using System . Collections . Concurrent ;
1
+ using System ;
2
+ using System . Collections . Concurrent ;
2
3
using System . Reflection ;
4
+ using System . Runtime . Serialization ;
3
5
using NHibernate . Proxy ;
4
6
using NHibernate . Proxy . DynamicProxy ;
5
7
using NUnit . Framework ;
6
8
7
9
namespace NHibernate . Test . NHSpecificTest . NH3954
8
10
{
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 ]
10
12
public class ProxyCacheFixture
11
13
{
12
14
private ProxyCache _cache ;
13
- private ConcurrentDictionary < ProxyCacheEntry , System . Type > _internalCache ;
15
+ private ConcurrentDictionary < ProxyCacheEntry , TypeInfo > _internalCache ;
14
16
private int _hashCode1 ;
15
17
private int _hashCode2 ;
16
18
17
19
private static readonly FieldInfo InternalCacheField =
18
- typeof ( ProxyCache ) . GetField ( "cache " , BindingFlags . Static | BindingFlags . NonPublic ) ;
20
+ typeof ( ProxyFactory ) . GetField ( "_cache " , BindingFlags . Static | BindingFlags . NonPublic ) ;
19
21
20
22
[ SetUp ]
21
23
public void SetUp ( )
22
24
{
23
25
_cache = new ProxyCache ( ) ;
24
26
25
- _internalCache = ( ConcurrentDictionary < ProxyCacheEntry , System . Type > ) InternalCacheField . GetValue ( null ) ;
27
+ _internalCache = ( ConcurrentDictionary < ProxyCacheEntry , TypeInfo > ) InternalCacheField . GetValue ( null ) ;
26
28
27
29
_cache . StoreProxyType ( typeof ( Entity1FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity1 ) ) ;
28
30
_cache . StoreProxyType ( typeof ( Entity2FakeProxy ) . GetTypeInfo ( ) , typeof ( Entity2 ) , typeof ( INHibernateProxy ) ) ;
29
31
_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 ) ) ;
32
34
33
35
// Artificially inject other entries with same hashcodes
34
36
_hashCode1 = new ProxyCacheEntry ( typeof ( Entity1 ) , null ) . GetHashCode ( ) ;
@@ -37,14 +39,14 @@ public void SetUp()
37
39
38
40
_hashCode2 = new ProxyCacheEntry ( typeof ( Entity2 ) , new [ ] { typeof ( INHibernateProxy ) } ) . GetHashCode ( ) ;
39
41
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 ) ) ;
42
44
}
43
45
44
46
private void Inject ( ProxyCacheEntry entryToTweak , int hashcode , System . Type result )
45
47
{
46
48
TweakEntry ( entryToTweak , hashcode ) ;
47
- _internalCache [ entryToTweak ] = result ;
49
+ _internalCache [ entryToTweak ] = result . GetTypeInfo ( ) ;
48
50
}
49
51
50
52
private static readonly FieldInfo HashCodeField =
@@ -112,14 +114,14 @@ public void ProxyCacheEntity3FakeProxy2()
112
114
[ Test ]
113
115
public void ProxyCacheEntity4FakeProxy ( )
114
116
{
115
- var result = _cache . GetProxyType ( typeof ( Entity4 ) , typeof ( IProxy ) ) ;
117
+ var result = _cache . GetProxyType ( typeof ( Entity4 ) , typeof ( ISerializable ) ) ;
116
118
Assert . AreEqual ( typeof ( Entity4FakeProxy ) , result ) ;
117
119
}
118
120
119
121
[ Test ]
120
122
public void ProxyCacheEntity4FakeProxy2 ( )
121
123
{
122
- var entry = new ProxyCacheEntry ( typeof ( Entity4 ) , new [ ] { typeof ( IProxy ) } ) ;
124
+ var entry = new ProxyCacheEntry ( typeof ( Entity4 ) , new [ ] { typeof ( ISerializable ) } ) ;
123
125
TweakEntry ( entry , _hashCode2 ) ;
124
126
var result = _internalCache [ entry ] ;
125
127
Assert . AreEqual ( typeof ( Entity4FakeProxy2 ) , result ) ;
@@ -128,15 +130,15 @@ public void ProxyCacheEntity4FakeProxy2()
128
130
[ Test ]
129
131
public void ProxyCacheEntity5FakeProxy ( )
130
132
{
131
- var result = _cache . GetProxyType ( typeof ( Entity5 ) , typeof ( IProxy ) , typeof ( INHibernateProxy ) ) ;
133
+ var result = _cache . GetProxyType ( typeof ( Entity5 ) , typeof ( ISerializable ) , typeof ( INHibernateProxy ) ) ;
132
134
Assert . AreEqual ( typeof ( Entity5FakeProxy ) , result ) ;
133
135
}
134
136
135
137
[ Test ]
136
138
public void ProxyCacheEntity5FakeProxy2 ( )
137
139
{
138
140
// 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 ) } ) ;
140
142
TweakEntry ( entry , _hashCode2 ) ;
141
143
var result = _internalCache [ entry ] ;
142
144
Assert . AreEqual ( typeof ( Entity5FakeProxy2 ) , result ) ;
@@ -149,7 +151,7 @@ public void ProxyCacheNone()
149
151
// (Otherwise the test may starts failing unexpectedly sometimes, as the original bug ...)
150
152
// This one was not added in anyway.
151
153
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 ) ) ;
153
155
}
154
156
}
155
- }
157
+ }
0 commit comments