public void Test_Non_Pdf_Uploaded_Failure() { //Arrange var fileMock = new Mock <IFormFile>(); //Setup mock file using a memory stream var content = "Hello World from a Fake File"; var fileName = "test.txt"; var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(content); writer.Flush(); ms.Position = 0; fileMock.Setup(_ => _.OpenReadStream()).Returns(ms); fileMock.Setup(_ => _.FileName).Returns(fileName); fileMock.Setup(_ => _.Length).Returns(ms.Length); var file = fileMock.Object; PdfDocumentController controller = new PdfDocumentController(); var result = controller.PostFile(file); Assert.IsInstanceOf <BadRequestObjectResult>(result.Result); }
public void Test_API_returns_Document_List() { PdfDocumentController controller = new PdfDocumentController(); var result = controller.GetFiles(); Assert.IsNotNull(result); }
public void Test_Pdf_Downlaod_By_Filename_Sucess() { var fileName = "test.pdf"; PdfDocumentController controller = new PdfDocumentController(); var result = controller.DownloadFile(fileName); Assert.IsNotNull(result); }
public void Test_Pdf_delete_the_deleted_one_returns_message() { string filename = "test.pdf"; PdfDocumentController controller = new PdfDocumentController(); var result = controller.Delete(filename); Assert.IsInstanceOf <BadRequestObjectResult>(result); }
public void Test_Pdf_deleted_by_file_name_success() { string filename = "test.pdf"; PdfDocumentController controller = new PdfDocumentController(); var result = controller.Delete(filename); Assert.IsInstanceOf <OkObjectResult>(result); }
public PdfDocumentControllerTests() { _urlHelperMock = new Mock <IUrlHelper>(); _documentHandlerMock = new Mock <IPdfDocumentHandler>(); _configurationMock = new Mock <IConfiguration>(); _serviceLoggerMock = new Mock <IServiceLogger>(); _fixture = new Fixture(); _sut = new PdfDocumentController(_documentHandlerMock.Object, _configurationMock.Object, _serviceLoggerMock.Object) { Url = _urlHelperMock.Object }; }
public void Test_Pdf_Size_Under_5MB_Sucess() { var fileName = Environment.CurrentDirectory + "\\TestFile\\TestFile-100KB.pdf"; var stream = File.OpenRead(fileName); var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)); PdfDocumentController controller = new PdfDocumentController(); var result = controller.PostFile(file); Assert.IsNotNull(result); Assert.IsInstanceOf <OkObjectResult>(result.Result); }
public void Test_Pdf_Size_Over_5MB_Failure() { var fileName = Environment.CurrentDirectory + "\\TestFile\\TestFile-5MB.pdf"; var stream = File.OpenRead(fileName); var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)); PdfDocumentController controller = new PdfDocumentController(); var result = controller.PostFile(file); Assert.IsNotNull(result); Assert.IsTrue(result.IsCompletedSuccessfully); Assert.IsInstanceOf <BadRequestObjectResult>(result.Result); }
/// <summary> /// Burns annotations on image. /// </summary> /// <param name="annotationViewer">The annotation viewer.</param> /// <param name="undoManager">The undo manager.</param> /// <param name="dataStorage">The data storage.</param> public static void BurnAnnotationsOnImage(AnnotationViewer annotationViewer, CompositeUndoManager undoManager, IDataStorage dataStorage) { // cancel annotation building annotationViewer.CancelAnnotationBuilding(); // if focused image is not correct if (!CheckImage(annotationViewer)) { return; } // get focused image VintasoftImage sourceImage = annotationViewer.Image; #if !REMOVE_PDF_PLUGIN // if focused image is PDF vector image if (sourceImage.IsVectorImage && sourceImage.SourceInfo.Decoder is PdfDecoder) { // get PDF page PdfPage page = PdfDocumentController.GetPageAssociatedWithImage(sourceImage); // if focused PDF page contains vector content if (!page.IsImageOnly) { DialogResult result = MessageBox.Show(string.Format("{0}\n\n{1}\n\n{2}\n\n{3}", "This page is a vector page of PDF document. How annotations should be drawn on the page?", "Press 'Yes' if you want convert annotations to PDF annotations and draw annotations on PDF page in a vector form.", "Press 'No' if you want rasterize PDF page and draw annotations on raster image in raster form.", "Press 'Cancel' to cancel burning."), "Burn Annotations", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { // burn vector annotations BurnPdfAnnotations( annotationViewer.AnnotationDataCollection, sourceImage.Resolution, page); // remove annotations annotationViewer.AnnotationDataCollection.ClearAndDisposeItems(); // reload focused image sourceImage.Reload(true); return; } if (result == DialogResult.Cancel) { return; } } } #endif // if undo manager is enabled if (undoManager.IsEnabled) { // create focused image copy using (VintasoftImage image = (VintasoftImage)sourceImage.Clone()) { // begin the composite undo action undoManager.BeginCompositeAction("Burn annotations on image"); // if undo manager does not contain the history for current image if (!undoManager.ContainsActionForSourceObject(sourceImage)) { // create change undo action ChangeImageUndoAction originalImageAction = new ChangeImageUndoAction(dataStorage, sourceImage); undoManager.AddAction(originalImageAction, null); } try { // burn annotations on focused image annotationViewer.AnnotationViewController.BurnAnnotationCollectionOnImage(annotationViewer.FocusedIndex); // create change undo action ChangeImageUndoAction action = new ChangeImageUndoAction(dataStorage, sourceImage, "Burn annotations on image"); undoManager.AddAction(action, image); } finally { // end the composite undo action undoManager.EndCompositeAction(); } } } else { // burn annotations on focused image annotationViewer.AnnotationViewController.BurnAnnotationCollectionOnImage(annotationViewer.FocusedIndex); } }