Skip to content

Conversation

@tomwilde
Copy link
Contributor

@tomwilde tomwilde commented May 9, 2019

Fixes #465


using(var stream = fileSystem.FileStream.Create(FilePath, fileMode, System.IO.FileAccess.Write))
{
using(var writer = new System.IO.StreamWriter(stream, System.Text.Encoding.UTF8, 4096, leaveOpen: true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are problems in appveyor tests because NET40 didn't have constructor that support leaveOpen parameter.
To fix that you can make conditional scenario for #if NET40 to get same react just don't create writer in using so Dispose will not be run.

But please someone confirm that what i write make sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d suggest just removing this argument, it does not seem to be necessary here. Same for the buffer size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even get rid of the StreamWriter and just write directly to the Stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated... :)

@fgreinacher fgreinacher changed the title bug fix for issue #465 Truncate existing files when writing via FileMode.Create/CreateNew May 15, 2019
@fgreinacher fgreinacher merged commit 8c96d0b into TestableIO:master May 15, 2019
@fgreinacher
Copy link
Contributor

Thanks @tomwilde!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MockFileStreamFactory.Create with FileMode.Create does not truncate an existing file

3 participants