@@ -39,7 +39,7 @@ public void GivenSystemCreatedFileName_WhenSaving_TheContentIsAsExpected()
3939 public void GivenSystemSpecialFolderAndCustomName_WhenSaving_TheContentIsAsExpected ( )
4040 {
4141 //Arrange
42- var appDataPath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
42+ var appDataPath = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
4343 var tempFile = Path . Combine ( appDataPath , "text.txt" ) ;
4444
4545 //Act
@@ -51,4 +51,47 @@ public void GivenSystemSpecialFolderAndCustomName_WhenSaving_TheContentIsAsExpec
5151 //Assert
5252 Assert . Equal ( "Hello from CodeMaze!" , tempFileContent ) ;
5353 }
54- }
54+
55+ [ Fact ]
56+ public void GivenTempSubdirectory_WhenSaving_TheContentIsAsExpected ( )
57+ {
58+ //Arrange
59+ var tempDirectory = Directory . CreateTempSubdirectory ( "codemaze-" ) ;
60+ var tempFile = Path . Combine ( tempDirectory . FullName , "text.txt" ) ;
61+
62+ //Act
63+ TempFileCreator . CreateTempFile ( tempFile ) ;
64+ var tempFileContent = File . ReadAllText ( tempFile ) ;
65+
66+ tempDirectory . Delete ( recursive : true ) ;
67+
68+ //Assert
69+ Assert . Equal ( "Hello from CodeMaze!" , tempFileContent ) ;
70+ Assert . False ( Directory . Exists ( tempDirectory . FullName ) ) ;
71+ }
72+
73+ [ Fact ]
74+ public void GivenDeleteOnClose_WhenStreamIsDisposed_TheFileIsGone ( )
75+ {
76+ //Arrange
77+ var tempFile = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
78+ var options = new FileStreamOptions
79+ {
80+ Mode = FileMode . CreateNew ,
81+ Access = FileAccess . ReadWrite ,
82+ Options = FileOptions . DeleteOnClose
83+ } ;
84+
85+ //Act
86+ bool existedWhileOpen ;
87+ using ( var stream = new FileStream ( tempFile , options ) )
88+ {
89+ stream . Write ( "Hello from CodeMaze!"u8 ) ;
90+ existedWhileOpen = File . Exists ( tempFile ) ;
91+ }
92+
93+ //Assert
94+ Assert . True ( existedWhileOpen ) ;
95+ Assert . False ( File . Exists ( tempFile ) ) ;
96+ }
97+ }
0 commit comments