1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
4
+ using System . Data ;
5
+ #endif
3
6
#if ! SILVERLIGHT
4
7
using NUnit . Framework ;
5
- using System . Data ;
6
8
#endif
7
9
using System . Collections ;
8
10
using System . Threading ;
@@ -48,10 +50,10 @@ public static void IsInstanceOf<T>(object o)
48
50
#endif
49
51
public class tests
50
52
{
51
- #region [ helpers ]
53
+ #region [ helpers ]
52
54
static int thousandtimes = 1000 ;
53
55
static int fivetimes = 5 ;
54
- #if ! SILVERLIGHT
56
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
55
57
static DataSet ds = new DataSet ( ) ;
56
58
#endif
57
59
//static bool exotic = false;
@@ -91,11 +93,13 @@ ahjksjkAHJKS سلام فارسی
91
93
public bool isNew { get ; set ; }
92
94
public string laststring { get ; set ; }
93
95
public Gender gender { get ; set ; }
96
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
97
+ public DataSet dataset { get ; set ; }
98
+ #endif
94
99
#if ! SILVERLIGHT
95
- public DataSet dataset { get ; set ; }
96
100
public Hashtable hash { get ; set ; }
97
101
#endif
98
- public Dictionary < string , baseclass > stringDictionary { get ; set ; }
102
+ public Dictionary < string , baseclass > stringDictionary { get ; set ; }
99
103
public Dictionary < baseclass , baseclass > objectDictionary { get ; set ; }
100
104
public Dictionary < int , baseclass > intDictionary { get ; set ; }
101
105
public Guid ? nullableGuid { get ; set ; }
@@ -122,10 +126,12 @@ public static colclass CreateObject(bool exotic, bool dataset)
122
126
c . hash = new Hashtable ( ) ;
123
127
c . hash . Add ( new class1 ( "0" , "hello" , Guid . NewGuid ( ) ) , new class2 ( "1" , "code" , "desc" ) ) ;
124
128
c . hash . Add ( new class2 ( "0" , "hello" , "pppp" ) , new class1 ( "1" , "code" , Guid . NewGuid ( ) ) ) ;
125
- if ( dataset )
129
+ #endif
130
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
131
+ if ( dataset )
126
132
c . dataset = CreateDataset ( ) ;
127
133
#endif
128
- c . bytes = new byte [ 1024 ] ;
134
+ c . bytes = new byte [ 1024 ] ;
129
135
c . stringDictionary = new Dictionary < string , baseclass > ( ) ;
130
136
c . objectDictionary = new Dictionary < baseclass , baseclass > ( ) ;
131
137
c . intDictionary = new Dictionary < int , baseclass > ( ) ;
@@ -211,8 +217,8 @@ public class Retclass
211
217
public object obj ;
212
218
public string ppp { get { return "sdfas df " ; } }
213
219
public DateTime date { get ; set ; }
214
- #if ! SILVERLIGHT
215
- public DataTable ds { get ; set ; }
220
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
221
+ public DataTable ds { get ; set ; }
216
222
#endif
217
223
}
218
224
@@ -224,8 +230,8 @@ public struct Retstruct
224
230
public int Field2 ;
225
231
public string ppp { get { return "sdfas df " ; } }
226
232
public DateTime date { get ; set ; }
227
- #if ! SILVERLIGHT
228
- public DataTable ds { get ; set ; }
233
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
234
+ public DataTable ds { get ; set ; }
229
235
#endif
230
236
}
231
237
@@ -249,8 +255,8 @@ private static long CreateLong(string s)
249
255
return neg ? - num : num ;
250
256
}
251
257
252
- #if ! SILVERLIGHT
253
- private static DataSet CreateDataset ( )
258
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
259
+ private static DataSet CreateDataset ( )
254
260
{
255
261
DataSet ds = new DataSet ( ) ;
256
262
for ( int j = 1 ; j < 3 ; j ++ )
@@ -289,9 +295,9 @@ public class RetNestedclass
289
295
public Retclass Nested { get ; set ; }
290
296
}
291
297
292
- #endregion
298
+ #endregion
293
299
294
- #if NET4
300
+ #if ! CORE_TEST
295
301
[ TestFixtureSetUp ]
296
302
#else
297
303
[ OneTimeSetUp ]
@@ -318,8 +324,8 @@ public static void ClassTest()
318
324
r . Field1 = "dsasdF" ;
319
325
r . Field2 = 2312 ;
320
326
r . date = DateTime . Now ;
321
- #if ! SILVERLIGHT
322
- r . ds = CreateDataset ( ) . Tables [ 0 ] ;
327
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
328
+ r . ds = CreateDataset ( ) . Tables [ 0 ] ;
323
329
#endif
324
330
325
331
var s = JSON . ToJSON ( r ) ;
@@ -338,8 +344,8 @@ public static void StructTest()
338
344
r . Field1 = "dsasdF" ;
339
345
r . Field2 = 2312 ;
340
346
r . date = DateTime . Now ;
341
- #if ! SILVERLIGHT
342
- r . ds = CreateDataset ( ) . Tables [ 0 ] ;
347
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
348
+ r . ds = CreateDataset ( ) . Tables [ 0 ] ;
343
349
#endif
344
350
345
351
var s = JSON . ToNiceJSON ( r ) ;
@@ -357,8 +363,8 @@ public static void ParseTest()
357
363
r . Field1 = "dsasdF" ;
358
364
r . Field2 = 2312 ;
359
365
r . date = DateTime . Now ;
360
- #if ! SILVERLIGHT
361
- r . ds = CreateDataset ( ) . Tables [ 0 ] ;
366
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
367
+ r . ds = CreateDataset ( ) . Tables [ 0 ] ;
362
368
#endif
363
369
364
370
var s = JSON . ToJSON ( r ) ;
@@ -878,7 +884,8 @@ public static void SingleCharNumber()
878
884
Assert . That ( zero , Is . EqualTo ( o ) ) ;
879
885
}
880
886
881
-
887
+ #endif
888
+ #if ! SILVERLIGHT && ( NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4 )
882
889
883
890
[ Test ]
884
891
public static void Datasets ( )
@@ -908,8 +915,10 @@ public static void Datasets()
908
915
Assert . AreEqual ( 100 , oo . Rows . Count ) ;
909
916
}
910
917
918
+ #endif
919
+ #if ! SILVERLIGHT
911
920
912
- [ Test ]
921
+ [ Test ]
913
922
public static void DynamicTest ( )
914
923
{
915
924
string s = "{\" Name\" :\" aaaaaa\" ,\" Age\" :10,\" dob\" :\" 2000-01-01 00:00:00Z\" ,\" inner\" :{\" prop\" :30},\" arr\" :[1,{\" a\" :2},3,4,5,6]}" ;
@@ -950,7 +959,7 @@ public static void GetDynamicMemberNamesTests()
950
959
}
951
960
#endif
952
961
953
- [ Test ]
962
+ [ Test ]
954
963
public static void CommaTests ( )
955
964
{
956
965
var s = JSON . ToJSON ( new commaclass ( ) , new JSONParameters ( ) { UseExtensions = true } ) ;
@@ -1882,7 +1891,7 @@ public static void comments()
1882
1891
Assert . AreEqual ( 2 , ( o as IDictionary ) . Count ) ;
1883
1892
}
1884
1893
1885
- #if NET4
1894
+ #if ! CORE_TEST || NETFRAMEWORK || ! NETCOREAPP3_0_OR_GREATER
1886
1895
public class ctype
1887
1896
{
1888
1897
public System . Net . IPAddress ip ;
@@ -2067,7 +2076,7 @@ public static void bytearrindic()
2067
2076
var d = JSON . ToObject < Dictionary < string , byte [ ] > > ( s ) ;
2068
2077
}
2069
2078
2070
- #region twitter
2079
+ #region twitter
2071
2080
public class Twitter
2072
2081
{
2073
2082
public Query query { get ; set ; }
@@ -2119,11 +2128,11 @@ public class BoundingBox
2119
2128
public string type { get ; set ; }
2120
2129
}
2121
2130
}
2122
- #endregion
2131
+ #endregion
2123
2132
[ Test ]
2124
2133
public static void twitter ( )
2125
2134
{
2126
- #region tw data
2135
+ #region tw data
2127
2136
string ss = @"{
2128
2137
""query"": {
2129
2138
""params"": {
@@ -2481,7 +2490,7 @@ public static void twitter()
2481
2490
]
2482
2491
}
2483
2492
}" ;
2484
- #endregion
2493
+ #endregion
2485
2494
var o = JSON . ToObject < Twitter > ( ss ) ;
2486
2495
}
2487
2496
@@ -3516,7 +3525,8 @@ public static void UTCDateFalse()
3516
3525
var dt = new DateTime ( 2021 , 1 , 10 , 12 , 0 , 0 , DateTimeKind . Utc ) ;
3517
3526
var js = JSON . ToJSON ( dt ) ;
3518
3527
Console . WriteLine ( js ) ;
3519
- Assert . AreEqual ( 15 , JSON . ToObject < DateTime > ( js , new JSONParameters ( ) { UseUTCDateTime = false } ) . Hour ) ;
3528
+ var dt2 = DateTime . SpecifyKind ( dt . ToLocalTime ( ) , DateTimeKind . Utc ) ;
3529
+ Assert . AreEqual ( dt2 . Hour , JSON . ToObject < DateTime > ( js , new JSONParameters ( ) { UseUTCDateTime = false } ) . Hour ) ;
3520
3530
}
3521
3531
//[Test]
3522
3532
//public static void ma()
@@ -3915,19 +3925,35 @@ public static void json5_additional_tests_3()
3915
3925
Console . WriteLine ( "Test for -0x0 --> -0" ) ;
3916
3926
3917
3927
Assert . AreEqual (
3918
- #if NET4
3928
+ #if NETFRAMEWORK || NET4 || NETCOREAPP && ! NETCOREAPP3_0_OR_GREATER
3919
3929
"9.0144042682896313E+28"
3920
3930
#else
3921
3931
"9.014404268289631E+28"
3922
3932
#endif
3923
3933
, JSON . ToJSON ( JSON . Parse ( "+0x0123456789abcdefABCDEF0000" ) ) ) ;
3924
3934
Console . WriteLine ( "Test for long hex number" ) ;
3925
3935
3926
- AssertException ( typeof ( FormatException ) , "Input string was not in a correct format." , ( ) => JSON . Parse ( "..2" ) ) ;
3927
- Console . WriteLine ( ".. is illegal" ) ;
3928
-
3929
- AssertException ( typeof ( FormatException ) , "Input string was not in a correct format." , ( ) => JSON . Parse ( "{a:..2}" ) ) ;
3930
- Console . WriteLine ( ".. is illegal inside of an object" ) ;
3936
+ try
3937
+ {
3938
+ AssertException ( typeof ( FormatException ) , "Input string was not in a correct format." , ( ) => JSON . Parse ( "..2" ) ) ;
3939
+ Console . WriteLine ( ".. is illegal" ) ;
3940
+ }
3941
+ catch
3942
+ {
3943
+ AssertException ( typeof ( FormatException ) , "The input string '..2' was not in a correct format." , ( ) => JSON . Parse ( "..2" ) ) ;
3944
+ Console . WriteLine ( ".. is illegal" ) ;
3945
+ }
3946
+
3947
+ try
3948
+ {
3949
+ AssertException ( typeof ( FormatException ) , "Input string was not in a correct format." , ( ) => JSON . Parse ( "{a:..2}" ) ) ;
3950
+ Console . WriteLine ( ".. is illegal inside of an object" ) ;
3951
+ }
3952
+ catch
3953
+ {
3954
+ AssertException ( typeof ( FormatException ) , "The input string '..2' was not in a correct format." , ( ) => JSON . Parse ( "{a:..2}" ) ) ;
3955
+ Console . WriteLine ( ".. is illegal inside of an object" ) ;
3956
+ }
3931
3957
3932
3958
Assert . AreEqual ( 1e41 , JSON . Parse ( "100000000000000000000000000000000000000000" ) ) ;
3933
3959
Console . WriteLine ( "Parses 100000000000000000000000000000000000000000" ) ;
0 commit comments