public void WhenInvalidTemplateName_ShouldReturnZeroBytes()
                    {
                        // arrange
                        var pdfUtil      = new PdfTestUtils();
                        var templateName = "BootCampForm-DOESNOTEXIST-v2.pdf";
                        var localPath    = pdfUtil.CreateTemplatePath(templateName);
                        var formFields   = new List <SimplePdfFormField> {
                            new SimplePdfFormField {
                                Name = "FirstName", Value = "Travis"
                            },
                            new SimplePdfFormField {
                                Name = "Surname", Value = "Frisinger"
                            },
                            new SimplePdfFormField {
                                Name = "DateOfBirth", Value = "1981-04-29"
                            },
                        };
                        var pdfService = new PdfRenderingRendering();
                        // act
                        var actual = pdfService
                                     .WithTemplate(templateName, localPath)
                                     .WithFormData(formFields)
                                     .Populate();
                        // assert
                        var expectedLength = 0;

                        actual.Length.Should().Be(expectedLength);
                    }
                        public void WhenProtectingNonEmptyPassword_ShouldReturnPasswordProtectedPdf()
                        {
                            // arrange
                            var pdfUtil      = new PdfTestUtils();
                            var templateName = "BootCampForm-v2.pdf";
                            var localPath    = pdfUtil.CreateTemplatePath(templateName);
                            var formFields   = new List <SimplePdfFormField> {
                                new SimplePdfFormField {
                                    Name = "FirstName", Value = "Travis"
                                },
                                new SimplePdfFormField {
                                    Name = "Surname", Value = "Frisinger"
                                },
                                new SimplePdfFormField {
                                    Name = "DateOfBirth", Value = "1981-04-29"
                                },
                            };
                            var pdfService = new PdfRenderingRendering();
                            // act
                            var actual = pdfService
                                         .WithTemplate(templateName, localPath)
                                         .WithFormData(formFields)
                                         .WithPassword("1234")
                                         .Populate();
                            // assert
                            var unsignedBytesLength = pdfUtil.FetchExpectedFileLength("readonly.pdf");

                            actual.Length.Should().NotBe(unsignedBytesLength);
                        }
            public void WhenValidFormInformation_ShouldReturnNewFileNameOfPopulatedPdf()
            {
                // arrange
                var pdfUtils = new PdfTestUtils();
                var fileName = "BootCampForm-v2.pdf";

                pdfUtils.UploadTemplateToCloud(fileName);
                var pdfManipuation = new PdfManipuation();
                var fields         = new List <SimplePdfFormField>
                {
                    new SimplePdfFormField {
                        Name = "FirstName", Value = "Bob"
                    },
                    new SimplePdfFormField {
                        Name = "Surname", Value = "Smith"
                    },
                    new SimplePdfFormField {
                        Name = "DateOfBirth", Value = "1981-04-29"
                    }
                };
                // act
                var actual = pdfManipuation.PopulateTemplate(fileName, fields);
                // assert
                var expected = $"-{fileName}";

                actual.Should().Contain(expected);
            }
            public void WhenValidFormInformation_ShouldReturnBytesOfModifedPdf()
            {
                // arrange
                var pdfUtils = new PdfTestUtils();
                var fileName = "BootCampForm-v2.pdf";

                pdfUtils.UploadTemplateToCloud(fileName);
                var pdfManipuation = new PdfManipuation();
                var fields         = new List <SimplePdfFormField>
                {
                    new SimplePdfFormField {
                        Name = "FirstName", Value = "Travis"
                    },
                    new SimplePdfFormField {
                        Name = "Surname", Value = "Frisinger"
                    },
                    new SimplePdfFormField {
                        Name = "DateOfBirth", Value = "1981-04-29"
                    },
                };
                var cloudStorageName = pdfManipuation.PopulateTemplate(fileName, fields);
                // act
                var actual = pdfManipuation.MarkFieldsAsReadOnly(cloudStorageName, fields);
                // assert
                var expectedLength = pdfUtils.FetchExpectedFileLength("readonly.pdf");

                actual.Length.Should().Be(expectedLength);
            }
            public void WhenEmptyPassword_ShouldReturnZeroBytes(string password)
            {
                // arrange
                var fileName       = "BootCampForm-v2.pdf";
                var pdfUtils       = new PdfTestUtils();
                var pdfBytes       = pdfUtils.FetchFileFromLocal(fileName);
                var pdfManipuation = new PdfManipuation();
                // act
                var actual = pdfManipuation.PasswordProtect(pdfBytes, password);

                // assert
                actual.Length.Should().Be(0);
            }
            public void WhenNonEmptyPassword_ShouldReturnBytesOfPasswordProtectedPdf()
            {
                // arrange
                var fileName       = "BootCampForm-v2.pdf";
                var password       = "******";
                var pdfUtils       = new PdfTestUtils();
                var pdfBytes       = pdfUtils.FetchFileFromLocal(fileName);
                var pdfManipuation = new PdfManipuation();
                // act
                var actual = pdfManipuation.PasswordProtect(pdfBytes, password);

                // assert
                Assert.DoesNotThrow(() => pdfUtils.DecryptBytes(actual, password));
            }
Пример #7
0
            public void WhenTemplateExistInCloud_ShouldReturnClonedFileName()
            {
                // arrange
                var pdfTestUtils = new PdfTestUtils();
                var templateName = "BootCampForm-v2.pdf";
                var filePath     = pdfTestUtils.CreateTemplatePath(templateName);
                var pdfStorage   = new PdfStorage();

                pdfStorage.UploadTemplate(filePath, templateName);
                // act
                var actual = pdfStorage.CloneTemplate(templateName);

                // assert
                actual.Should().Contain(templateName);
            }
Пример #8
0
            public void WhenFileExistInCloud_ShouldBeAbleToDownloadFile()
            {
                // arrange
                var pdfTestUtils = new PdfTestUtils();
                var templateName = "BootCampForm-v2.pdf";
                var filePath     = pdfTestUtils.CreateTemplatePath(templateName);
                var pdfStorage   = new PdfStorage();

                pdfStorage.UploadTemplate(filePath, templateName);
                // act
                var actual = pdfStorage.Download(templateName);
                // assert
                var expectedLength = FetchBootCampFormExpectedLength(filePath);

                actual.Length.Should().Be(expectedLength);
            }
Пример #9
0
            public void WhenTemplateNotPresent_ShouldReturnErrors()
            {
                // arrange
                var pdfTestUtils = new PdfTestUtils();
                var templateName = "BootCampForm-DOESNOTEXIST-v2.pdf";
                var filePath     = pdfTestUtils.CreateTemplatePath(templateName);
                var pdfStorage   = new PdfStorage();
                // act
                var actual = pdfStorage.UploadTemplate(filePath, templateName);
                // assert
                var expected = new UploadResult {
                    Successful = false, Errors = { "Cannot locate pdf template [BootCampForm-DOESNOTEXIST-v2.pdf]" }
                };

                actual.Should().BeEquivalentTo(expected);
            }
Пример #10
0
            public void WhenWhiteSpaceOrNullStorageFilename_ShouldReturnErrors(string fileName)
            {
                // arrange
                var pdfTestUtils = new PdfTestUtils();
                var templateName = "BootCampForm-v2.pdf";
                var filePath     = pdfTestUtils.CreateTemplatePath(templateName);
                var pdfStorage   = new PdfStorage();
                // act
                var actual = pdfStorage.UploadTemplate(filePath, fileName);
                // assert
                var expected = new UploadResult {
                    Successful = false, Errors = { "Storage Filename cannot be whitespace or null" }
                };

                actual.Should().BeEquivalentTo(expected);
            }
Пример #11
0
            public void WhenTemplateExistLocally_ShouldUploadPdf()
            {
                // arrange
                var pdfTestUtils = new PdfTestUtils();
                var templateName = "BootCampForm-v2.pdf";
                var filePath     = pdfTestUtils.CreateTemplatePath(templateName);
                var pdfStorage   = new PdfStorage();
                // act
                var actual = pdfStorage.UploadTemplate(filePath, templateName);
                // assert
                var expected = new UploadResult {
                    Successful = true
                };

                actual.Should().BeEquivalentTo(expected);
            }