Skip to content

Opening a file in Read mode now returns a read-only stream#260

Merged
fgreinacher merged 5 commits intoTestableIO:masterfrom
Shtong:Fix230
Aug 5, 2018
Merged

Opening a file in Read mode now returns a read-only stream#260
fgreinacher merged 5 commits intoTestableIO:masterfrom
Shtong:Fix230

Conversation

@Shtong
Copy link
Copy Markdown

@Shtong Shtong commented Nov 15, 2017

Fixes #230

if (access == FileAccess.Read)
streamType = MockFileStream.StreamType.READ;
else if (mode == FileMode.Append)
streamType = MockFileStream.StreamType.APPEND;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like we've lost the stream.Seek call for the Append scenario?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Seeking is already handled by the MockFileStream constructor called later


// Assert
Assert.IsFalse(stream.CanWrite);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this include Assert.Throws<NotSupportedException>(() => stream.WriteByte(1)); for consistency with the other test, and to assert that the stream is indeed not writeable?

@jpreese jpreese added the state: waiting for feedback Issues that are waiting for feedback label Jul 8, 2018
@fgreinacher
Copy link
Copy Markdown
Contributor

@Shtong I know this PR is pretty old, but in case you still want to work in this, please update your branch and address the review comments. If you don’t want to work on this someone else might be able to help get this in :)

@Shtong
Copy link
Copy Markdown
Author

Shtong commented Jul 27, 2018

I'll try to see if I can back into that during the week-end

@Shtong
Copy link
Copy Markdown
Author

Shtong commented Jul 28, 2018

All done.

Note: the changes I made revealed a bug in the MockFile_OpenWrite_ShouldCreateNewFiles unit test. Because the folder in which the new file was requested didn't exist, OpenWrite should have thrown an exception, which is not the case in the master branch. The changes I made fixed this bug, so I fixed the unit tests to check for both scenarios (working with existing folder, and throwing with missing folder)

Copy link
Copy Markdown
Contributor

@fgreinacher fgreinacher left a comment

Choose a reason for hiding this comment

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

Some minor things from my side, but generally this looks good.

Comment thread TestingHelpers/MockFileStream.cs Outdated
canWrite = streamType != StreamType.READ;
}

private bool canWrite = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please move this field to the top, where the other fields are.

Comment thread TestingHelpers/MockFileStream.cs Outdated

private bool canWrite = true;

public override bool CanWrite
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

public override bool CanWrite => canWrite ?

Comment thread TestHelpers.Tests/MockFileTests.cs Outdated
}

[Test]
public void MockFile_OpenRead_ShouldNotReturnWritableStream()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

...ShouldReturnReadOnlyStream?


Assert.Throws<DirectoryNotFoundException>(() => fileSystem.File.OpenWrite(filePath));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove superfluous empty line

@fgreinacher
Copy link
Copy Markdown
Contributor

Great - thanks!

@fgreinacher fgreinacher merged commit 43684d3 into TestableIO:master Aug 5, 2018
@Shtong
Copy link
Copy Markdown
Author

Shtong commented Aug 5, 2018

Done, sorry I made a rebase to resolve merge conflicts which confused github to locate your comments!

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

Labels

state: waiting for feedback Issues that are waiting for feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants