Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Fix untestable extension methods #527

Closed
davidfowl opened this issue Jan 1, 2016 · 17 comments
Closed

Fix untestable extension methods #527

davidfowl opened this issue Jan 1, 2016 · 17 comments
Assignees
Milestone

Comments

@davidfowl
Copy link
Member

These methods demand that files be on disk. What makes it worse is that these are extension methods so they cannot be stubbed.

Maybe we should make these virtual on HttpResponse and IFormFile (interface method).

/cc @Eilon @Tratcher @lodejard

@Tratcher Tratcher added the bug label Jan 4, 2016
@glennc
Copy link
Member

glennc commented Jan 7, 2016

If we are going to do this we should do it now, moving methods around after RC2 should be avoided.

@glennc glennc added this to the 1.0.0-rc2 milestone Jan 7, 2016
@davidfowl
Copy link
Member Author

another alternative might be to add an overload that takes IFileInfo

@davidfowl
Copy link
Member Author

Ughm IFileInfo is read only...

@khellang
Copy link
Contributor

another alternative might be to add an overload that takes IFileInfo

Add an overload where? For SendFile?

What about the FormFileExtensions? Promote them to IFormFile?

@davidfowl
Copy link
Member Author

@khellang Those are the 2 options. Either promote to interface or use some overload that takes a writable file abstraction.

@davidfowl
Copy link
Member Author

For SendFile, we should allow passing IFileInfo

@muratg
Copy link

muratg commented Jan 21, 2016

Moving this to Backlog as we will be in RC2 ask mode very soon. If you feel strongly about this issue, please ping me.

@muratg muratg modified the milestones: Backlog, 1.0.0-rc2 Jan 21, 2016
@lodejard
Copy link
Contributor

On the Form file extensions, why not Task SaveAsync(Stream target)?

The IFileInfo for SendFile is good though - because if it's has a non-null-or-empty PhysicalFilePath some servers can accelerate that.

@khellang
Copy link
Contributor

I think Task SaveAsync(Stream target) makes sense, then the Task SaveAsync(string path) overloads could be extension methods again 😛

@davidfowl
Copy link
Member Author

Only problem with extension methods is that it reintroduces the original problem if you ever use them... Which is what the original problem and why this bug was filed 😄

@khellang
Copy link
Contributor

Only problem with extension methods is that it reintroduces the original problem if you ever use them

Yes and no. You can still mock the SaveAsmethod on the interface, which is an improvement.

@khellang
Copy link
Contributor

Also, if it's changed to a Stream, does the SaveAs name make sense?

@davidfowl
Copy link
Member Author

If we add Save(Stream target) then there's no point adding an untestable extension method.

@khellang
Copy link
Contributor

So no point in adding a convenience method for saving to a path? Like

public static void SaveAs(this IFormFile file, string path)
{
    using (var fileStream = File.Create(path, DefaultBufferSize))
    {
        file.Save(fileStream);
    }
}

@davidfowl
Copy link
Member Author

It just means you can't test it is all.

@lodejard
Copy link
Contributor

It's better in general for devs to call File.Create for themselves. Otherwise you'll end up with some (but not all) of the APIs that take Stream having a string overload for convenience, but you don't know what flags they pass. What file sharing for example? Fail if file exists? Those details may not be consistent if you took a look at how the various convenience methods create files on your behalf...

@Tratcher
Copy link
Member

Wouldn't that be CopyTo[Async](Stream)? Save implies the destination is a file, which is no longer necessary.

@Tratcher Tratcher removed this from the Backlog milestone Feb 11, 2016
@Tratcher Tratcher self-assigned this Feb 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants