File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 22
22
//
23
23
#endregion
24
24
25
+ using System ;
25
26
using System . IO ;
26
27
using Xunit ;
27
28
@@ -99,6 +100,30 @@ public void HandlesClassWrappingCustomStruct()
99
100
Assert . Equal ( 123 , after . Value . Score ) ;
100
101
}
101
102
103
+ [ Fact ]
104
+ public void ThrowsIfNullStream ( )
105
+ {
106
+ var ex = Assert . Throws < ArgumentNullException > ( ( ) => new Serialiser < UserScore > ( ) . Serialise ( ( Stream ) null , new UserScore ( "Doug" , 100 ) ) ) ;
107
+
108
+ Assert . Equal ( "stream" , ex . ParamName ) ;
109
+
110
+ ex = Assert . Throws < ArgumentNullException > ( ( ) => new Serialiser ( typeof ( UserScore ) ) . Serialise ( ( Stream ) null , new UserScore ( "Doug" , 100 ) ) ) ;
111
+
112
+ Assert . Equal ( "stream" , ex . ParamName ) ;
113
+ }
114
+
115
+ [ Fact ]
116
+ public void ThrowsIfNullPacker ( )
117
+ {
118
+ var ex = Assert . Throws < ArgumentNullException > ( ( ) => new Serialiser < UserScore > ( ) . Serialise ( ( UnsafePacker ) null , new UserScore ( "Doug" , 100 ) ) ) ;
119
+
120
+ Assert . Equal ( "packer" , ex . ParamName ) ;
121
+
122
+ ex = Assert . Throws < ArgumentNullException > ( ( ) => new Serialiser ( typeof ( UserScore ) ) . Serialise ( ( UnsafePacker ) null , new UserScore ( "Doug" , 100 ) ) ) ;
123
+
124
+ Assert . Equal ( "packer" , ex . ParamName ) ;
125
+ }
126
+
102
127
#region Helper
103
128
104
129
private static T RoundTrip < T > ( T before )
Original file line number Diff line number Diff line change @@ -40,12 +40,16 @@ public Serialiser(DasherContext context = null)
40
40
41
41
public void Serialise ( Stream stream , T value )
42
42
{
43
+ if ( stream == null )
44
+ throw new ArgumentNullException ( nameof ( stream ) ) ;
43
45
using ( var packer = new UnsafePacker ( stream ) )
44
46
Serialise ( packer , value ) ;
45
47
}
46
48
47
49
public void Serialise ( UnsafePacker packer , T value )
48
50
{
51
+ if ( packer == null )
52
+ throw new ArgumentNullException ( nameof ( packer ) ) ;
49
53
_action ( packer , _context , value ) ;
50
54
}
51
55
@@ -71,12 +75,16 @@ public Serialiser(Type type, DasherContext context = null)
71
75
72
76
public void Serialise ( Stream stream , object value )
73
77
{
78
+ if ( stream == null )
79
+ throw new ArgumentNullException ( nameof ( stream ) ) ;
74
80
using ( var packer = new UnsafePacker ( stream ) )
75
81
Serialise ( packer , value ) ;
76
82
}
77
83
78
84
public void Serialise ( UnsafePacker packer , object value )
79
85
{
86
+ if ( packer == null )
87
+ throw new ArgumentNullException ( nameof ( packer ) ) ;
80
88
_action ( packer , _context , value ) ;
81
89
}
82
90
You can’t perform that action at this time.
0 commit comments