MockHttpPostedFileBase.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.IO;
  2. using System.Web;
  3. namespace Mvc.Stream.Tests.Mocks
  4. {
  5. public class MockHttpPostedFileBase : HttpPostedFileBase
  6. {
  7. public MockHttpPostedFileBase(int contentLen, string fileName, string contentType, System.IO.Stream stream = null)
  8. {
  9. ContentLength = contentLen;
  10. FileName = fileName;
  11. ContentType = contentType;
  12. InputStream = stream;
  13. }
  14. public override int ContentLength { get; }
  15. public override string FileName { get; }
  16. public override System.IO.Stream InputStream { get; }
  17. public override string ContentType { get; }
  18. public override void SaveAs(string filename)
  19. {
  20. var fileInfo = new FileInfo(filename);
  21. var directory = new DirectoryInfo(Path.GetDirectoryName(fileInfo.FullName));
  22. if (!directory.Exists)
  23. {
  24. directory.Create();
  25. }
  26. using (var file = fileInfo.CreateText())
  27. {
  28. file.Write("test");
  29. }
  30. }
  31. }
  32. }