public void UploadImageHelper() { // Arrange PhotoUtils myutils = new PhotoUtils(); if (File.Exists(mytestutils.GetLocalRootPathToFile("\\uploaded_images\\raw\\") + "image_upload_test.jpg")) { File.Delete(mytestutils.GetLocalRootPathToFile("\\uploaded_images\\raw\\") + "image_upload_test.jpg"); } // setup mock object files for testing upload var file1 = new Mock<HttpPostedFileBase>(); file1.Setup(x => x.InputStream).Returns(stream1); file1.Setup(x => x.ContentLength).Returns((int)stream1.Length); file1.Setup(x => x.FileName).Returns("testimage1.jpg"); var file2 = new Mock<HttpPostedFileBase>(); file2.Setup(x => x.InputStream).Returns(stream2); file2.Setup(x => x.ContentLength).Returns((int)stream2.Length); file2.Setup(x => x.FileName).Returns("testimage3.jpg"); var file3 = new Mock<HttpPostedFileBase>(); file3.Setup(x => x.InputStream).Returns(stream3); file3.Setup(x => x.ContentLength).Returns((int)stream3.Length); file3.Setup(x => x.FileName).Returns("testimage4.gif"); String imgfolder = mytestutils.GetLocalRootPathToFile("\\uploaded_images\\raw\\"); String result1 = myutils.UploadImage(file1.Object, "image_upload_test.jpg", imgfolder, 262144, 280); String result2 = myutils.UploadImage(file2.Object, "image_upload_test2.jpg", imgfolder, 262144, 280); String result3 = myutils.UploadImage(file3.Object, "image_upload_test3.jpg", imgfolder, 262144, 280); Boolean isFileUploaded = File.Exists(mytestutils.GetLocalRootPathToFile("\\uploaded_images\\raw\\") + "image_upload_test.jpg"); Boolean isFileUploaded2 = File.Exists(mytestutils.GetLocalRootPathToFile("\\uploaded_images\\raw\\") + "image_upload_test2.jpg"); Boolean isFileUploaded3 = File.Exists(mytestutils.GetLocalRootPathToFile("\\uploaded_images\\raw\\") + "image_upload_test3.jpg"); Assert.IsTrue(isFileUploaded); Assert.IsFalse(isFileUploaded2); Assert.IsFalse(isFileUploaded2); Assert.AreEqual("OK: File uploaded!", result1); Assert.IsTrue(result2.StartsWith("ERROR: File is larger than")); Assert.IsTrue(result3.StartsWith("ERROR: Cannot accept files of this type.")); }