public void TestDeleteWithContainerNameDefaultFile() { #region AddFile // Arrange using (BlobController controller1 = new BlobController(new BlobBL(new Blob()))) { // Act string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png"); using (Stream stream = File.OpenRead(filePath)) { MyTestPostedFileBase file = new MyTestPostedFileBase(stream, "image/png", "ProfileIcon.png"); controller1.FileUpload(file); } } #endregion // Arrange using (BlobController controller = new BlobController(new BlobBL(new Blob()))) { // Act var result = controller.DeleteFile(_defaultContainer); //Assert Assert.IsFalse(result.Data.ToString() == "error", "Exception occur so error."); } }
public void TestFileUploadException() { // Arrange using (BlobController controller = new BlobController(new ToDoMockBlobService())) { // Act string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png"); using (MultipartFormDataContent form = new MultipartFormDataContent()) { using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath))) { fileContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("image/png"); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "ProfileIcon.png" }; form.Add(fileContent); controller.Request = new HttpRequestMessage { Method = HttpMethod.Post, Content = form }; var response = controller.FileUpload().Result; //Assert Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); } } } }
public void TestFileUploadWrongDataScenario() { // Arrange using (BlobController controller = new BlobController(new BlobBL(new Blob()))) { // Act string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png"); using (MultipartFormDataContent form = new MultipartFormDataContent()) { using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath))) { fileContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "ProfileIcon.png" }; form.Add(fileContent); controller.Request = new HttpRequestMessage { Method = HttpMethod.Post, Content = form }; var response = controller.FileUpload().Result; //Assert Assert.AreEqual(HttpStatusCode.UnsupportedMediaType, response.StatusCode); } } } }
public void TestDeleteWithContainerNameDefaultFile() { #region AddFile // Arrange using (BlobController controllerBlob = new BlobController(new BlobBL(new Blob()))) { // Act string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png"); using (MultipartFormDataContent form = new MultipartFormDataContent()) { using (var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath))) { fileContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("image/png"); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "ProfileIcon.png" }; form.Add(fileContent); controllerBlob.Request = new HttpRequestMessage { Method = HttpMethod.Post, Content = form }; var response1 = controllerBlob.FileUpload().Result; } } } #endregion // Arrange using (BlobController controller = new BlobController(new BlobBL(new Blob()))) { controller.Request = new HttpRequestMessage { Method = HttpMethod.Delete }; // Act var response = controller.DeleteFile(_defaultContainer); //Assert Assert.IsTrue(response.IsSuccessStatusCode); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); } }
public void TestFileUpload() { // Arrange using (BlobController controller = new BlobController(new BlobBL(new Blob()))) { // Act string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())), "ProfileIcon.png"); using (Stream stream = File.OpenRead(filePath)) { MyTestPostedFileBase obj = new MyTestPostedFileBase(stream, "image/png", "ProfileIcon.png"); var result = controller.FileUpload(obj, _defaultContainer); //Assert Assert.IsFalse(result.Data.ToString() == "error", "Exception occur so error."); } } }