Adjusted order of execution for Linux
MODIFY
src/Chapter10.Tests/Listing10.20.Tests.cs
src/Chapter10.Tests/Listing10.20.Tests.cs
@@ -26,14 +26,20 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20.Tests
private static void DeleteTempFile()
{
- if(IsFileLocked(TempFileName))
+ if (File.Exists(TempFileName))
{
- throw new IOException($"The file, '{TempFileName}', is in use can can't be deleted.");
- }
- else if (File.Exists(TempFileName))
+ try
{
File.Delete(TempFileName);
}
+ catch(IOException exception)
+ {
+ if (IsFileLocked(TempFileName))
+ {
+ throw new IOException($"The file, '{TempFileName}', is in use can can't be deleted.", exception);
+ }
+ }
+ }
}
@@ -61,10 +67,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20.Tests
{
try
{
- using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
- {
+ using FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
stream.Close();
- }
+
//file is not locked
return false;
}
@@ -88,6 +93,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20.Tests
return true;
}
}
+ finally
+ {
+
+ }
}
}
}
\ No newline at end of file

Adjusted order of execution for Linux