File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,24 @@ public void Can_Deserialize_Various_Enum_Values ()
277
277
Assert . Equal ( Disposition . SoSo , output . Integer ) ;
278
278
}
279
279
280
+ [ Fact ]
281
+ public void Can_Deserialize_Various_Enum_Types ( )
282
+ {
283
+ var data = File . ReadAllText ( Path . Combine ( "SampleData" , "jsonenumtypes.txt" ) ) ;
284
+ var response = new RestResponse { Content = data } ;
285
+ var json = new JsonDeserializer ( ) ;
286
+ var output = json . Deserialize < JsonEnumTypesTestStructure > ( response ) ;
287
+
288
+ Assert . Equal ( ByteEnum . EnumMin , output . ByteEnumType ) ;
289
+ Assert . Equal ( SByteEnum . EnumMin , output . SByteEnumType ) ;
290
+ Assert . Equal ( ShortEnum . EnumMin , output . ShortEnumType ) ;
291
+ Assert . Equal ( UShortEnum . EnumMin , output . UShortEnumType ) ;
292
+ Assert . Equal ( IntEnum . EnumMin , output . IntEnumType ) ;
293
+ Assert . Equal ( UIntEnum . EnumMin , output . UIntEnumType ) ;
294
+ Assert . Equal ( LongEnum . EnumMin , output . LongEnumType ) ;
295
+ Assert . Equal ( ULongEnum . EnumMin , output . ULongEnumType ) ;
296
+ }
297
+
280
298
[ Fact ]
281
299
public void Deserialization_Of_Undefined_Int_Value_Returns_Enum_Default ( )
282
300
{
Original file line number Diff line number Diff line change 81
81
</ItemGroup >
82
82
<ItemGroup >
83
83
<Compile Include =" SampleClasses\EmployeeTracker.cs" />
84
+ <Compile Include =" SampleClasses\EnumTest.cs" />
84
85
<Compile Include =" SampleClasses\GoogleWeatherWithAttributes.cs" />
85
86
<Compile Include =" XmlAttributeDeserializerTests.cs" />
86
87
<Compile Include =" CultureChange.cs" />
124
125
<Content Include =" SampleData\jsondictionary.txt" >
125
126
<CopyToOutputDirectory >Always</CopyToOutputDirectory >
126
127
</Content >
128
+ <Content Include =" SampleData\jsonenumtypes.txt" >
129
+ <CopyToOutputDirectory >Always</CopyToOutputDirectory >
130
+ </Content >
127
131
<Content Include =" SampleData\objectproperty.txt" >
128
132
<CopyToOutputDirectory >Always</CopyToOutputDirectory >
129
133
</Content >
Original file line number Diff line number Diff line change
1
+ namespace RestSharp . Tests . SampleClasses
2
+ {
3
+ public enum ByteEnum : byte
4
+ {
5
+ EnumMin = 0 ,
6
+ EnumMax = 255
7
+ }
8
+
9
+ public enum SByteEnum : sbyte
10
+ {
11
+ EnumMin = - 128 ,
12
+ EnumMax = 127
13
+ }
14
+
15
+ public enum ShortEnum : short
16
+ {
17
+ EnumMin = - 32768 ,
18
+ EnumMax = 32767
19
+ }
20
+
21
+ public enum UShortEnum : ushort
22
+ {
23
+ EnumMin = 0 ,
24
+ EnumMax = 65535
25
+ }
26
+
27
+ public enum IntEnum : int
28
+ {
29
+ EnumMin = - 2147483648 ,
30
+ EnumMax = 2147483647
31
+ }
32
+
33
+ public enum UIntEnum : uint
34
+ {
35
+ EnumMin = 0 ,
36
+ EnumMax = 4294967295
37
+ }
38
+
39
+ public enum LongEnum : long
40
+ {
41
+ EnumMin = - 9223372036854775808 ,
42
+ EnumMax = 9223372036854775807
43
+ }
44
+
45
+ public enum ULongEnum : ulong
46
+ {
47
+ EnumMin = 0 ,
48
+ EnumMax = 18446744073709551615
49
+ }
50
+
51
+ public class JsonEnumTypesTestStructure
52
+ {
53
+ public ByteEnum ByteEnumType { get ; set ; }
54
+ public SByteEnum SByteEnumType { get ; set ; }
55
+ public ShortEnum ShortEnumType { get ; set ; }
56
+ public UShortEnum UShortEnumType { get ; set ; }
57
+ public IntEnum IntEnumType { get ; set ; }
58
+ public UIntEnum UIntEnumType { get ; set ; }
59
+ public LongEnum LongEnumType { get ; set ; }
60
+ public ULongEnum ULongEnumType { get ; set ; }
61
+ }
62
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "ByteEnumType": 0,
3
+ "SByteEnumType": -128,
4
+ "ShortEnumType": -32768,
5
+ "UShortEnumType": 0,
6
+ "IntEnumType": -2147483648,
7
+ "UIntEnumType": 0,
8
+ "LongEnumType": -9223372036854775808,
9
+ "ULongEnumType" : 0
10
+ }
You can’t perform that action at this time.
0 commit comments