File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1240,5 +1240,43 @@ public void MockFile_AppendText_CreatesNewFileForAppendToNonExistingFile()
12401240 Assert . That ( file . TextContents , Is . EqualTo ( "New too!" ) ) ;
12411241 Assert . That ( filesystem . FileExists ( filepath ) ) ;
12421242 }
1243+
1244+ [ Test ]
1245+ public void Serializable_works ( )
1246+ {
1247+ //Arrange
1248+ MockFileData data = new MockFileData ( "Text Contents" ) ;
1249+
1250+ //Act
1251+ System . Runtime . Serialization . IFormatter formatter = new System . Runtime . Serialization . Formatters . Binary . BinaryFormatter ( ) ;
1252+ Stream stream = new MemoryStream ( ) ;
1253+ formatter . Serialize ( stream , data ) ;
1254+
1255+ //Assert
1256+ Assert . Pass ( ) ;
1257+ }
1258+
1259+ [ Test ]
1260+ public void Serializable_can_deserialize ( )
1261+ {
1262+ //Arrange
1263+ string textContentStr = "Text Contents" ;
1264+
1265+ //Act
1266+ MockFileData data = new MockFileData ( textContentStr ) ;
1267+
1268+ System . Runtime . Serialization . IFormatter formatter = new System . Runtime . Serialization . Formatters . Binary . BinaryFormatter ( ) ;
1269+ Stream stream = new MemoryStream ( ) ;
1270+ formatter . Serialize ( stream , data ) ;
1271+
1272+ stream . Seek ( 0 , SeekOrigin . Begin ) ;
1273+
1274+ MockFileData deserialized = ( MockFileData ) formatter . Deserialize ( stream ) ;
1275+
1276+ //Assert
1277+ Assert . That ( deserialized . TextContents , Is . EqualTo ( textContentStr ) ) ;
1278+ }
1279+
1280+
12431281 }
12441282}
You can’t perform that action at this time.
0 commit comments