[Dev Tip] Wrap HttpPostedFileStream for unit test,…



using System.IO;
using System.Web;

namespace Hydra.Insurance.Web.Helpers
{
public class HttpPostedFileStreamWrapper : HttpPostedFileBase
{
private string contentType;
private string filename;
private Stream inputStream;

public HttpPostedFileStreamWrapper(Stream inputStream, string contentType = null, string filename = null)
{
this.inputStream = inputStream;
this.contentType = contentType;
this.filename = filename;
}

public override int ContentLength
{
get
{
return (int)inputStream.Length;
}
}

public override string ContentType
{
get
{
return contentType;
}
}

public override string FileName
{
get
{
return filename;
}
}

public override Stream InputStream
{
get
{
return inputStream;
}
}

public override void SaveAs(string filename)
{
using (var stream = File.OpenWrite(filename))
{
InputStream.CopyTo(stream);
}
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s