Any way to create HttpPosted File?

S

Shimon Sim

I am writing a unit test for the class that will take a HttpPostedFile in of
it methods as a parameter. I need to pass this parameter to the method in
the test but I don't see any way to create this file using C#.
I understand that from security point of view it makes sense but I got to
write this test unless it's impossible.
Thanks,
Shimon.
 
K

Karl

I don't think you'll be able to do anything in an automatic/programmatic
fashion...

Karl
 
J

Joerg Jooss

Shimon said:
I am writing a unit test for the class that will take a
HttpPostedFile in of it methods as a parameter. I need to pass this
parameter to the method in the test but I don't see any way to create
this file using C#.
I understand that from security point of view it makes sense but I
got to write this test unless it's impossible.

I suggest changing the method so it doesn't accept a HttpPostedFile object,
but a Stream instead. This decouples your logic from ASP.NET specific
objects and makes it much easier to test -- not to mention enhanced
resuability.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top