File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222//
2323#endregion
2424
25+ using System ;
2526using System . IO ;
2627using Xunit ;
2728
@@ -99,6 +100,30 @@ public void HandlesClassWrappingCustomStruct()
99100 Assert . Equal ( 123 , after . Value . Score ) ;
100101 }
101102
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+
102127 #region Helper
103128
104129 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)
4040
4141 public void Serialise ( Stream stream , T value )
4242 {
43+ if ( stream == null )
44+ throw new ArgumentNullException ( nameof ( stream ) ) ;
4345 using ( var packer = new UnsafePacker ( stream ) )
4446 Serialise ( packer , value ) ;
4547 }
4648
4749 public void Serialise ( UnsafePacker packer , T value )
4850 {
51+ if ( packer == null )
52+ throw new ArgumentNullException ( nameof ( packer ) ) ;
4953 _action ( packer , _context , value ) ;
5054 }
5155
@@ -71,12 +75,16 @@ public Serialiser(Type type, DasherContext context = null)
7175
7276 public void Serialise ( Stream stream , object value )
7377 {
78+ if ( stream == null )
79+ throw new ArgumentNullException ( nameof ( stream ) ) ;
7480 using ( var packer = new UnsafePacker ( stream ) )
7581 Serialise ( packer , value ) ;
7682 }
7783
7884 public void Serialise ( UnsafePacker packer , object value )
7985 {
86+ if ( packer == null )
87+ throw new ArgumentNullException ( nameof ( packer ) ) ;
8088 _action ( packer , _context , value ) ;
8189 }
8290
You can’t perform that action at this time.
0 commit comments