1+ using DiscordPlayerCountBot . Json ;
2+
3+ namespace DiscordPlayerCountBot . Tests ;
4+
5+ [ Collection ( "Json Serialization Test Suite" ) ]
6+ public class JsonTests
7+ {
8+ [ Fact ( DisplayName = "Test Primitives Float" , Timeout = 30 ) ]
9+ public void SerializePrimitivesFloat ( )
10+ {
11+ var testFloat = JsonHelper . DeserializeObject < float > ( "2.23" ) ;
12+
13+ Assert . True ( testFloat == ( float ) 2.23 , $ "{ testFloat } ") ;
14+ Assert . True ( testFloat . GetType ( ) == typeof ( float ) ) ;
15+ }
16+
17+ [ Fact ( DisplayName = "Test Primitives Double" , Timeout = 30 ) ]
18+ public void SerializePrimitivesDouble ( )
19+ {
20+ var testDouble = JsonHelper . DeserializeObject < double > ( "200.00" ) ;
21+
22+ Assert . True ( testDouble == 200.00 ) ;
23+ Assert . True ( testDouble . GetType ( ) == typeof ( double ) ) ;
24+
25+ }
26+
27+ [ Fact ( DisplayName = "Test Primitives Char" , Timeout = 30 ) ]
28+ public void SerializePrimitivesChar ( )
29+ {
30+ var testChar = JsonHelper . DeserializeObject < char > ( "3" ) ;
31+
32+ Assert . True ( testChar == '3' ) ;
33+ Assert . True ( testChar . GetType ( ) == typeof ( char ) ) ;
34+ }
35+
36+ [ Fact ( DisplayName = "Test Primitives Bool" , Timeout = 30 ) ]
37+ public void SerializePrimitivesBool ( )
38+ {
39+ var testBooleanTrue = JsonHelper . DeserializeObject < bool > ( "true" ) ;
40+
41+ Assert . True ( testBooleanTrue ) ;
42+ Assert . True ( testBooleanTrue . GetType ( ) == typeof ( bool ) ) ;
43+
44+ var testBooleanFalse = JsonHelper . DeserializeObject < bool > ( "false" ) ;
45+
46+ Assert . True ( ! testBooleanFalse ) ;
47+ Assert . True ( testBooleanFalse . GetType ( ) == typeof ( bool ) ) ;
48+ }
49+
50+ [ Fact ( DisplayName = "Test Primitives Int" , Timeout = 30 ) ]
51+ public void SerializePrimitivesInt ( )
52+ {
53+ var testInt = JsonHelper . DeserializeObject < int > ( "100" ) ;
54+
55+ Assert . True ( testInt == 100 ) ;
56+ Assert . True ( testInt . GetType ( ) == typeof ( int ) ) ;
57+ }
58+
59+ [ Fact ( DisplayName = "Test Strings" , Timeout = 30 ) ]
60+ public void SerializeStrings ( )
61+ {
62+ var testString = JsonHelper . DeserializeObject < string > ( "test" ) ?? "" ;
63+
64+ Assert . True ( ! string . IsNullOrEmpty ( testString ) , "Should not be null or empty." ) ;
65+ Assert . True ( ! string . IsNullOrWhiteSpace ( testString ) , "Should not be null or whitespace." ) ;
66+ Assert . Equal ( "test" , testString , true , true , true ) ;
67+ Assert . True ( testString . GetType ( ) == typeof ( string ) ) ;
68+ }
69+ }
0 commit comments