-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing(Porting) SaveAS API to HttpPostedFile #459
Conversation
[Fact] | ||
public void SaveAs() | ||
{ | ||
var file = new Mock<IFormFile>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you follow the arrange/act/assert pattern as above? Can you add a test for something rooted? maybe to the temp directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twsouthwick does this look ok ? (Dividing into 2 separate test cases)
[Fact]
public void SaveAsForInvalidRootPath()
{
// Arrange
var file = new Mock<IFormFile>();
var expectedStream = new Mock<Stream>();
file.Setup(f => f.OpenReadStream()).Returns(expectedStream.Object);
var posted = new HttpPostedFile(file.Object);
//Act and Assert
Assert.Throws<HttpException>(() => posted.SaveAs("InvalidPath"));
}
[Fact]
public void SaveAsWithValidRootPath()
{
// Arrange
var file = new Mock<IFormFile>();
var expectedStream = new Mock<Stream>();
file.Setup(f => f.OpenReadStream()).Returns(expectedStream.Object);
string validTempPath = string.Format(CultureInfo.InvariantCulture, @"{0}{1}.txt", Path.GetTempPath(), Guid.NewGuid());
var posted = new HttpPostedFile(file.Object);
//Act
posted.SaveAs(validTempPath);
//Assert
Assert.True(File.Exists(validTempPath), "Temp file should be created");
//Cleanup
File.Delete(validTempPath);
}
|
||
using (var fileStream = new FileStream(filename, FileMode.Create)) | ||
{ | ||
InputStream.Seek(0, SeekOrigin.Begin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary
|
||
public void SaveAs(string filename) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw putting "Fixes ..." at the bottom automatically links to the issue and will close it upon completion (as well as kicks off some automation we have) |
ok.. I have been tagging in the description , can stick to what suggested here as long as it triggers the automation. |
@@ -163,7 +163,7 @@ public void RewritePath(string filePath, string pathInfo, string? queryString, b | |||
return Server; | |||
} | |||
|
|||
return null; | |||
return Context.RequestServices?.GetService(service); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there's a weird merge thing going on
@birojnayak there appears to be a weird merge thing going on. Can you clean that up? The #457 change is showing up here when it shouldn't be |
@birojnayak Is there a chance this PR could also add |
@twsouthwick feel free to merge it.. added to HttpPostedFileBase and HttpPostedFileWrapper |
This will bring the SaveAS API to HttpPostedFile, which will be used in FileUpload control CoreWebForms/CoreWebForms#29
Fixes #451