Description
Note: this is a "Jump In" issue, which means it's suitable for people that want to contribute to the project, but aren't confident with the codebase yet. See the TestStack contribution page for details. If you get stuck then feel free to add a comment and one of the TestStack contributors will help guide you! Good luck :)
Add assertions after the .WithCallTo(...)
extension to check for the various file results.
I wouldn't expect this issue to be done in one go - maybe a PR per each one or two of the following.
In terms of implementation: you want to put this stuff in the ControllerResultTest
class and similarly add unit tests to the ControllerResultTestShould
class. Note the test class has data-driven tests for checking the return type checks by adding lines to the ReturnTypes field in the "Test cases" region.
Check for result type being FileResult
note this is a breaking change (because the current method checks for and returns FileContentResult
) and would need to be added to a BREAKING_CHANGES.md file (example: from Seleno)
_controller.WithCallTo(c => c.Index())
.ShouldRenderFile();
Check for result type being FileResult
and content type being "text/plain"
note this is a breaking change (because the current method checks for and returns FileContentResult
) and would need to be added to a BREAKING_CHANGES.md file (example: from Seleno)
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFile(expectedContentType);
Check for result type being FileContentResult
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents();
Check for result type being FileContentResult
and the content matching
const string expectedContent = "asdf";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents(expectedContent);
var expectedContent = new byte[]{1,2,3};
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents(expectedContent);
Check for result type being FileContentResult
and the content matching and the content type matching
const string expectedContent = "asdf";
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents(expectedContent, expectedContentType);
var expectedContent = new byte[]{1,2,3};
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents(expectedContent, expectedContentType);
Check for result type being FileStreamResult
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream();
Check for result type being FileStreamResult
and the stream matching
var expectedStream = new MemoryStream();
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream(expectedStream);
Check for result type being FileStreamResult
and the stream matching and the content type matching
var expectedStream = new MemoryStream();
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream(expectedStream, expectedContentType);
Check for result type being FileStreamResult
and the stream contents matching
const string expectedContent = "asdf";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream(expectedContent);
var expectedContent = new byte[]{1,2,3};
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream(expectedContent);
Check for result type being FileStreamResult
and the stream contents matching and the content type matching
var expectedContent = "asdf";
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream(expectedContent, expectedContentType);
var expectedContent = new byte[]{1,2,3};
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFileStream(expectedContent, expectedContentType);
Check for result type being FilePathResult
_controller.WithCallTo(c => c.Index())
.ShouldRenderFilePath();
Check for result type being FilePathResult
and file path matching
const string expectedFilePath;
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFilePath(expectedFilePath);
Check for result type being FilePathResult
and file path matching and the content type matching
const string expectedFilePath;
const string expectedContentType = "text/plain";
...
_controller.WithCallTo(c => c.Index())
.ShouldRenderFilePath(expectedFilePath, expectedContentType);