File tree Expand file tree Collapse file tree
System.IO.Abstractions.TestingHelpers.Tests
System.IO.Abstractions.TestingHelpers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -230,6 +230,26 @@ public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem()
230230 Assert . AreEqual ( $ "Demo text contentThis should be at the end{ Environment . NewLine } ", newcontents ) ;
231231 }
232232
233+ [ Test ]
234+ public void MockFileInfo_AppendText_ShouldCreateFileIfMissing ( )
235+ {
236+ var fileSystem = new MockFileSystem ( ) ;
237+ var targetFile = XFS . Path ( @"c:\a.txt" ) ;
238+ var fileInfo = new MockFileInfo ( fileSystem , targetFile ) ;
239+
240+ using ( var file = fileInfo . AppendText ( ) )
241+ file . WriteLine ( "This should be the contents" ) ;
242+
243+ string newcontents ;
244+ using ( var newfile = fileInfo . OpenText ( ) )
245+ {
246+ newcontents = newfile . ReadToEnd ( ) ;
247+ }
248+
249+ Assert . That ( fileSystem . File . Exists ( targetFile ) , Is . True ) ;
250+ Assert . AreEqual ( $ "This should be the contents{ Environment . NewLine } ", newcontents ) ;
251+ }
252+
233253 [ Test ]
234254 public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem ( )
235255 {
Original file line number Diff line number Diff line change @@ -152,7 +152,6 @@ public override string Name
152152
153153 public override StreamWriter AppendText ( )
154154 {
155- if ( MockFileData == null ) throw CommonExceptions . FileNotFound ( path ) ;
156155 return new StreamWriter ( new MockFileStream ( mockFileSystem , FullName , MockFileStream . StreamType . APPEND ) ) ;
157156 }
158157
You can’t perform that action at this time.
0 commit comments