Update 10.20 to match book and update test as well
MODIFY
src/Chapter10.Tests/Listing10.20.Tests.cs
src/Chapter10.Tests/Listing10.20.Tests.cs
@@ -47,7 +47,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20.Tests
public void Create_GivenNewDocument_FileGetsCreated()
{
TemporaryFileStream fileStream = new TemporaryFileStream(TempFileName);
- Assert.IsTrue(File.Exists(fileStream.File.FullName));
+ Assert.IsTrue(File.Exists(fileStream.File?.FullName!));
}
[TestMethod]

MODIFY
src/Chapter10/Listing10.20.DefiningAFinalizer.cs
src/Chapter10/Listing10.20.DefiningAFinalizer.cs
@@ -34,13 +34,22 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20
}
}
- public FileStream Stream { get; }
- public FileInfo File { get; }
+ public FileStream Stream { get; private set; }
+ public FileInfo File { get; private set; }
public void Close()
{
Stream?.Dispose();
+ try
+ {
File?.Delete();
}
+ catch(IOException exception)
+ {
+ Console.WriteLine(exception);
+ }
+ Stream = null;
+ File = null;
+ }
}
}
\ No newline at end of file

Update 10.20 to match book and update test as well