5
5
using System . Runtime . InteropServices ;
6
6
using System . Security . Cryptography . X509Certificates ;
7
7
using System . Text ;
8
-
9
8
using Microsoft . Win32 . SafeHandles ;
10
9
11
10
using NUnit . Framework ;
12
11
13
12
namespace Force . DeepCloner . Tests
14
13
{
14
+ #if ! NETCORE
15
15
[ TestFixture ( false ) ]
16
+ #endif
16
17
[ TestFixture ( true ) ]
17
18
public class SystemTypesSpec : BaseTest
18
19
{
@@ -48,16 +49,19 @@ public void Type_With_Native_Resource_Should_Be_Cloned()
48
49
var cloned = writer . DeepClone ( ) ;
49
50
writer . Write ( "2" ) ;
50
51
cloned . Write ( 3 ) ;
52
+ #if ! NETCORE
51
53
var f = typeof ( FileStream ) . GetField ( "_handle" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
52
54
var f2 = typeof ( SafeHandle ) . GetField ( "_state" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
53
55
Console . WriteLine ( f2 . GetValue ( f . GetValue ( writer . BaseStream ) ) ) ;
54
56
Console . WriteLine ( f2 . GetValue ( f . GetValue ( cloned . BaseStream ) ) ) ;
55
- writer . Close ( ) ;
57
+ #endif
58
+
59
+ writer . Dispose ( ) ;
56
60
// cloned.Close();
57
61
// not a bug anymore, this is feature: we don't duplicate handles, because it can cause unpredictable results
58
62
// ~~this was a bug, we should not throw there~~
59
63
60
- Assert . Throws < ObjectDisposedException > ( cloned . Close ) ;
64
+ Assert . Throws < ObjectDisposedException > ( cloned . Flush ) ;
61
65
var res = File . ReadAllText ( fileName ) ;
62
66
Assert . That ( res , Is . EqualTo ( "123" ) ) ;
63
67
}
@@ -130,9 +134,12 @@ public void Certificate_Should_Be_Cloned()
130
134
cert . DeepClone ( ) ;
131
135
cert . DeepClone ( ) ;
132
136
GC . Collect ( ) ;
137
+ #if ! NETCORE
133
138
GC . WaitForFullGCComplete ( ) ;
139
+ #endif
134
140
}
135
141
142
+ #if ! NETCORE
136
143
[ Test ( Description = "Without special handling it causes exception on destruction due native resources usage" ) ]
137
144
public void ObjectHandle_Should_Be_Cloned ( )
138
145
{
@@ -144,6 +151,7 @@ public void ObjectHandle_Should_Be_Cloned()
144
151
GC . Collect ( ) ;
145
152
GC . WaitForFullGCComplete ( ) ;
146
153
}
154
+ #endif
147
155
148
156
[ Test ( Description = "Without special handling it causes exception on destruction due native resources usage" ) ]
149
157
public void Certificate_Should_Be_Shallow_Cloned ( )
@@ -152,7 +160,9 @@ public void Certificate_Should_Be_Shallow_Cloned()
152
160
cert . ShallowClone ( ) ;
153
161
cert . ShallowClone ( ) ;
154
162
GC . Collect ( ) ;
163
+ #if ! NETCORE
155
164
GC . WaitForFullGCComplete ( ) ;
165
+ #endif
156
166
}
157
167
}
158
168
}
0 commit comments