File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
StoneAge.Data.FileSystem.Tests Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . IO ;
33using System . Linq ;
44using System . Threading . Tasks ;
@@ -112,6 +112,25 @@ public async Task WhenFileExist_ExpectItOverWritten()
112112 contents . Should ( ) . BeEquivalentTo ( new byte [ 5 ] ) ;
113113 }
114114
115+ [ Test ]
116+ public async Task WhenFileDataIsNull_ExpectErrorMessage ( )
117+ {
118+ //---------------Arrange-------------------
119+ var path = Path . GetTempPath ( ) ;
120+ var fileName = Guid . NewGuid ( ) + ".txt" ;
121+ var document = new DocumentBuilder ( )
122+ . With_Name ( fileName )
123+ . With_Bytes ( null ) // explicitly set null data
124+ . Create_Document ( ) ;
125+
126+ var sut = new FileSystem ( ) ;
127+ //---------------Act----------------------
128+ var result = await sut . Write ( path , document ) ;
129+ //---------------Assert-----------------------
130+ result . HadError . Should ( ) . BeTrue ( ) ;
131+ result . ErrorMessages . Should ( ) . Contain ( "No file data provided; cannot write file." ) ;
132+ }
133+
115134 private static void Write_File_Contents_For_Testing ( string path , string fileName )
116135 {
117136 File . WriteAllText ( Path . Combine ( path , fileName ) , "test line" ) ;
Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
@@ -196,6 +196,13 @@ public async Task<IEnumerable<string>> ReadAllLines(string path)
196196 private WriteFileResult Write_File_To_Path ( IDocument file , string filePath , FileMode fileMode )
197197 {
198198 var result = new WriteFileResult ( ) ;
199+
200+ if ( file . Data == null )
201+ {
202+ result . ErrorMessages . Add ( "No file data provided; cannot write file." ) ;
203+ return result ;
204+ }
205+
199206 try
200207 {
201208 using ( var stream = new FileStream ( filePath , fileMode ) )
You can’t perform that action at this time.
0 commit comments