internal FunctionResult ExecuteCompiled(params object[] parameters) { FunctionTester <MongoDBMapReduce> functionTester = new FunctionTester <MongoDBMapReduce>(); functionTester.CustomTypes.Add(OutputType); return(functionTester.Compile( new PropertyValue(MongoDBMapReduceShared.Names.ConnectionString, ConnectionString), new PropertyValue(MongoDBMapReduceShared.Names.Collection, Collection), new PropertyValue(MongoDBMapReduceShared.Names.Query, Query), new PropertyValue(MongoDBMapReduceShared.Names.OutputType, OutputType), new PropertyValue(MongoDBMapReduceShared.Names.Sort, Sort), new PropertyValue(MongoDBMapReduceShared.Names.Limit, Limit), new PropertyValue(MongoDBMapReduceShared.Names.Map, Map), new PropertyValue(MongoDBMapReduceShared.Names.Reduce, Reduce), new PropertyValue(MongoDBMapReduceShared.Names.Finalize, Finalize), new PropertyValue(MongoDBMapReduceShared.Names.ReturnOptionsPropertyName, ReturnModeType) ).Execute( new ParameterValue[] { new ParameterValue(MongoDBMapReduceShared.Names.ConnectionString, ConnectionString), new ParameterValue(MongoDBMapReduceShared.Names.Collection, Collection), new ParameterValue(MongoDBMapReduceShared.Names.Query, Query), new ParameterValue(MongoDBMapReduceShared.Names.Sort, Sort), new ParameterValue(MongoDBMapReduceShared.Names.Limit, Limit), new ParameterValue(MongoDBMapReduceShared.Names.Map, Map), new ParameterValue(MongoDBMapReduceShared.Names.Reduce, Reduce), new ParameterValue(MongoDBMapReduceShared.Names.Finalize, Finalize) }.Concat(parameters.Where(v => v is ParameterValue).Select(v => v as ParameterValue)).ToArray() )); }
public void ReadText( [Values( TextSplit.Never, TextSplit.Page)] TextSplit splitText) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ReadPdf.Resources.Text.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ReadPdfProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadText].Value = true; designer.Properties[PropertyNames.SplitText].Value = splitText; var tester = new FunctionTester <ReadPdfProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); switch (splitText) { case TextSplit.Never: Assert.AreEqual("Text on page 1\nFooter text on page 1\r\nText on page 2\r\nText on page 3", result.Value.Text); break; case TextSplit.Page: Assert.AreEqual(new List <string> { "Text on page 1\nFooter text on page 1", "Text on page 2", "Text on page 3" }, result.Value.Text); break; } }
public void ProtectWithScreenReaderRestrictions( [Values( FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth, [Values( true, false)] bool allowScreenReaders) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, allowScreenReaders: allowScreenReaders); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true, expectedAllowScreenReaders: allowScreenReaders); if (protectAuth == FileAuthentication.Password) { using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword)) { PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true); } } }
public void ValidateSplitOutputStructure() { var tester = new FunctionTester <PdfOperationsProvider>(); FunctionDesigner designer = tester.CreateDesigner(); Assert.IsNull(designer.Output); Property operation = designer.Properties[PropertyNames.Operation]; operation.Value = Operation.Split; Property loopResults = designer.Properties[PropertyNames.SplitLoopResults]; loopResults.Value = false; Assert.AreEqual(0, designer.ExecutionPaths.Count); IEnumerable <ITypeProperty> properties = designer.Output.GetProperties(); Assert.AreEqual(2, properties.Count()); properties.ElementAt(0).AssertList(OutputNames.PageFiles, typeof(string)); properties.ElementAt(1).AssertCompiled(OutputNames.NumberOfPages, typeof(int)); loopResults.Value = true; Assert.AreEqual(1, designer.ExecutionPaths.Count); ExecutionPath executionPath = designer.ExecutionPaths[0]; Assert.AreEqual(ExecutionPathNames.PageFiles, executionPath.Name); Assert.AreEqual(TypeReference.Create(typeof(string)), executionPath.Output); properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertCompiled(OutputNames.NumberOfPages, typeof(int)); }
internal FunctionResult ExecuteCompiled(params object[] parameters) { FunctionTester <MongoDBRead> functionTester = new FunctionTester <MongoDBRead>(); functionTester.CustomTypes.Add(OutputType); return(functionTester.Compile( new PropertyValue(MongoDBReadShared.Names.ConnectionString, ConnectionString), new PropertyValue(MongoDBReadShared.Names.Collection, Collection), new PropertyValue(MongoDBReadShared.Names.Query, Query), new PropertyValue(MongoDBReadShared.Names.OutputType, OutputType), new PropertyValue(MongoDBReadShared.Names.AggregationPipeline, AggregationPipeline), new PropertyValue(MongoDBReadShared.Names.Fields, Fields), new PropertyValue(MongoDBReadShared.Names.Sort, Sort), new PropertyValue(MongoDBReadShared.Names.Skip, Skip), new PropertyValue(MongoDBReadShared.Names.Limit, Limit), new PropertyValue(MongoDBReadShared.Names.Operation, Operation), new PropertyValue(MongoDBReadShared.Names.ReturnOptionsPropertyName, ReturnModeType) ).Execute( new ParameterValue[] { new ParameterValue(MongoDBReadShared.Names.ConnectionString, ConnectionString), new ParameterValue(MongoDBReadShared.Names.Collection, Collection), new ParameterValue(MongoDBReadShared.Names.Query, Query), new ParameterValue(MongoDBReadShared.Names.AggregationPipeline, AggregationPipeline), new ParameterValue(MongoDBReadShared.Names.Fields, Fields), new ParameterValue(MongoDBReadShared.Names.Sort, Sort), new ParameterValue(MongoDBReadShared.Names.Skip, Skip), new ParameterValue(MongoDBReadShared.Names.Limit, Limit) }.Concat(parameters.Where(v => v is ParameterValue).Select(v => v as ParameterValue)).ToArray() )); }
public void AddWatermarkWithAuthentication( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication watermarkAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory); string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Watermark.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); var watermarkPages = string.Empty; ConfigureWatermarkFunctionValues(designer, watermarkAuth, watermarkFilePath, WatermarkPosition.Below, watermarkPages); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <AddWatermarkProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\nWatermark\r\n4\nWatermark", null); }
public void ReadSignature() { var store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(this.authenticationManager.Certificate); store.Close(); string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Signature.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadSignature].Value = true; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.IsTrue(result.Value.Signatures.IsSigned); AssertSignature(result.Value.Signatures.LatestSignature, false, "I moderated the doc", "Office location 2", "Jane Doe", new DateTime(2016, 8, 8, 15, 12, 57, DateTimeKind.Utc), true, 1, "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n", false); dynamic allSignatures = result.Value.Signatures.AllSignatures; Assert.AreEqual(2, allSignatures.Count); AssertSignature(allSignatures[0], false, "I created the doc", "Office location 1", "John Smith", new DateTime(2016, 8, 8, 15, 12, 14, DateTimeKind.Utc), true, 1, string.Empty, true); AssertSignature(allSignatures[1], false, "I moderated the doc", "Office location 2", "Jane Doe", new DateTime(2016, 8, 8, 15, 12, 57, DateTimeKind.Utc), true, 1, "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n", false); store.Open(OpenFlags.ReadWrite); store.Remove(this.authenticationManager.Certificate); store.Close(); }
public void ReadXfaFormDataWithCustomTypeOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; ITypeReference dataType = TypeReference.CreateGeneratedType( new TypeProperty("form1_910_93_46FullName_910_93", typeof(string)), new TypeProperty("form1_910_93_46Surname_910_93", typeof(string)), new TypeProperty("form1_910_93_46Email_910_93", typeof(string)), new TypeProperty("form1_910_93_46EmailMe_910_93", typeof(string))); designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.CustomType; designer.Properties[PropertyNames.FormDataType].Value = dataType; var tester = new FunctionTester<ReadProvider>(); tester.CustomTypes.Add(dataType); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("John", result.Value.FormData.form1_910_93_46FullName_910_93); Assert.AreEqual("Doe", result.Value.FormData.form1_910_93_46Surname_910_93); Assert.AreEqual("*****@*****.**", result.Value.FormData.form1_910_93_46Email_910_93); Assert.AreEqual("1", result.Value.FormData.form1_910_93_46EmailMe_910_93); }
public void Concatenate() { string inputFilePath1 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate1.pdf", this.inputDirectory); PdfComparer.AssertPageCount(inputFilePath1, FileAuthentication.None, this.authenticationManager, 1); PdfComparer.AssertText(inputFilePath1, FileAuthentication.None, this.authenticationManager, "1", "function Script1()\r\n{}\n"); string inputFilePath2 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate2.pdf", this.inputDirectory); PdfComparer.AssertPageCount(inputFilePath2, FileAuthentication.None, this.authenticationManager, 1); PdfComparer.AssertText(inputFilePath2, FileAuthentication.None, this.authenticationManager, "2", "function Script2()\r\n{}\n"); string outputFilePath = Path.Combine(this.outputDirectory, "Concat.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); designer.Properties[PropertyNames.Operation].Value = Operation.Concatenate; designer.Properties[PropertyNames.InputFiles].Value = new List <string> { inputFilePath1, inputFilePath2 }; designer.Properties[PropertyNames.InputAuthenticationType].Value = AuthenticationType.None; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.IsTrue(File.Exists(outputFilePath)); PdfComparer.AssertPageCount(outputFilePath, FileAuthentication.None, this.authenticationManager, 2); PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, $"1{Environment.NewLine}2", "function Script1()\r\n{}\n\nfunction Script2()\r\n{}\n\n"); }
public void ValidateReadSignatureOutputStructure() { var tester = new FunctionTester<ReadProvider>(); FunctionDesigner designer = tester.CreateDesigner(); Assert.IsNull(designer.Output); Property readSignature = designer.Properties[PropertyNames.ReadSignature]; Assert.IsFalse(readSignature.GetValue<bool>()); readSignature.Value = true; IEnumerable<ITypeProperty> properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertGenerated(OutputNames.Signatures); properties = properties.ElementAt(0).TypeReference.GetProperties(); Assert.AreEqual(3, properties.Count()); properties.ElementAt(0).AssertCompiled(OutputNames.IsSigned, typeof(bool)); properties.ElementAt(1).AssertGenerated(OutputNames.LatestSignature); ITypeReference signatureType = properties.ElementAt(1).TypeReference; properties.ElementAt(2).AssertList(OutputNames.AllSignatures, signatureType); properties = signatureType.GetProperties(); Assert.AreEqual(9, properties.Count()); properties.ElementAt(0).AssertCompiled(OutputNames.SignedBy, typeof(string)); properties.ElementAt(1).AssertCompiled(OutputNames.SignedAt, typeof(string)); properties.ElementAt(2).AssertCompiled(OutputNames.Reason, typeof(string)); properties.ElementAt(3).AssertCompiled(OutputNames.SignedOn, typeof(DateTime)); properties.ElementAt(4).AssertCompiled(OutputNames.Unmodified, typeof(bool)); properties.ElementAt(5).AssertCompiled(OutputNames.SignedRevision, typeof(int)); properties.ElementAt(6).AssertCompiled(OutputNames.IsLatestRevision, typeof(bool)); properties.ElementAt(7).AssertCompiled(OutputNames.Verified, typeof(bool)); properties.ElementAt(8).AssertCompiled(OutputNames.VerificationMessage, typeof(string)); }
public void AddWatermark( [Values( FileAuthentication.None, FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth, [Values( WatermarkPosition.Above, WatermarkPosition.Below)] WatermarkPosition position) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory); string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Watermark.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); var watermarkPages = "4;1-2,2,2"; ConfigureWatermarkFunctionValues(designer, FileAuthentication.None, watermarkFilePath, position, watermarkPages); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <AddWatermarkProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertText(outputFilePath, inputAuth, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\r\n4\nWatermark", null); }
public void ReadAcroFormDataWithListOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.List; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); List<KeyValuePair<string, string>> dataList = result.Value.FormDataList; Assert.AreEqual(4, dataList.Count); KeyValuePair<string, string> item = dataList[0]; Assert.AreEqual("First Name", item.Key); Assert.AreEqual("Jeremy", item.Value); item = dataList[1]; Assert.AreEqual("Surname", item.Key); Assert.AreEqual("Woods", item.Value); item = dataList[2]; Assert.AreEqual("Gender", item.Key); Assert.AreEqual("Male", item.Value); item = dataList[3]; Assert.AreEqual("AcceptTCs", item.Key); Assert.AreEqual("Yes", item.Value); }
public void ReadXfaFormDataWithListOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.List; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); List<KeyValuePair<string, string>> dataList = result.Value.FormDataList; Assert.AreEqual(5, dataList.Count); KeyValuePair<string, string> item = dataList[0]; Assert.AreEqual("form1[0].FullName[0]", item.Key); Assert.AreEqual("John", item.Value); item = dataList[1]; Assert.AreEqual("form1[0].Surname[0]", item.Key); Assert.AreEqual("Doe", item.Value); item = dataList[2]; Assert.AreEqual("form1[0].EmailMe[0]", item.Key); Assert.AreEqual("1", item.Value); item = dataList[3]; Assert.AreEqual("form1[0].Email[0]", item.Key); Assert.AreEqual("*****@*****.**", item.Value); item = dataList[4]; Assert.AreEqual("form1[0]", item.Key); Assert.AreEqual("*****@*****.**", item.Value); }
public void SignAcroWithPageSignature() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Sign.pdf"); int left = 45; int top = 223; int width = 109; int height = 79; int page = 2; this.lockDocument = !this.lockDocument; FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureSignCertificateProperties(designer, FileAuthentication.CertificateFile, this.lockDocument); designer.Properties[PropertyNames.Placement].Value = SignaturePosition.OnPage; designer.Properties[PropertyNames.PositionX].Value = left; designer.Properties[PropertyNames.PositionY].Value = top; designer.Properties[PropertyNames.Width].Value = width; designer.Properties[PropertyNames.Height].Value = height; designer.Properties[PropertyNames.Page].Value = page; designer.Properties[PropertyNames.BackgroundImage].Value = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign_Image.png", this.inputDirectory); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <SignProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertPageSignature(outputFilePath, FileAuthentication.None, this.authenticationManager, signName, signLocation, signReason, this.lockDocument, page, Utilities.MillimetersToPoints(left), Utilities.MillimetersToPoints(top), Utilities.MillimetersToPoints(width), Utilities.MillimetersToPoints(height)); }
public void SignWithInvisibleSignature( [Values( FileAuthentication.None, FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth, [Values( FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication signAuth, [Values( "Sign.pdf", "SignXFA.pdf")] string fileName) { string inputFilePath = ResourceHelpers.WriteResourceToFile($"Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.{fileName}", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, fileName); this.lockDocument = !this.lockDocument; FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); ConfigureSignCertificateProperties(designer, signAuth, this.lockDocument); designer.Properties[PropertyNames.Placement].Value = SignaturePosition.Hidden; designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <SignProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertPageSignature(outputFilePath, inputAuth, this.authenticationManager, signName, signLocation, signReason, this.lockDocument, 1, 0, 0, 0, 0); }
public void ReadAcroFormDataWithCustomTypeOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; ITypeReference dataType = TypeReference.CreateGeneratedType( new TypeProperty("First_32Name", typeof(string)), new TypeProperty("Surname", typeof(string)), new TypeProperty("Gender", typeof(string)), new TypeProperty("AcceptTCs", typeof(string))); designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.CustomType; designer.Properties[PropertyNames.FormDataType].Value = dataType; var tester = new FunctionTester<ReadProvider>(); tester.CustomTypes.Add(dataType); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("Jeremy", result.Value.FormData.First_32Name); Assert.AreEqual("Woods", result.Value.FormData.Surname); Assert.AreEqual("Male", result.Value.FormData.Gender); Assert.AreEqual("Yes", result.Value.FormData.AcceptTCs); }
public void ValidateReadTextOutputStructure() { var tester = new FunctionTester <ReadPdfProvider>(); FunctionDesigner designer = tester.CreateDesigner(); Assert.IsNull(designer.Output); Property readText = designer.Properties[PropertyNames.ReadText]; Assert.IsFalse(readText.GetValue <bool>()); readText.Value = true; Property splitText = designer.Properties[PropertyNames.SplitText]; splitText.Value = TextSplit.Never; IEnumerable <ITypeProperty> properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertCompiled(OutputNames.Text, typeof(string)); splitText.Value = TextSplit.Page; properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertList(OutputNames.Text, typeof(string)); }
public void ProtectWithPrintRestrictions( [Values( FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth, [Values( Printing.None, Printing.LowResolution, Printing.HighResolution)] Printing printing) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, printing: printing); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); bool allowDegradedPrinting = false; bool allowPrinting = false; switch (printing) { case Printing.None: break; case Printing.LowResolution: allowDegradedPrinting = true; break; case Printing.HighResolution: allowDegradedPrinting = true; allowPrinting = true; break; default: throw new NotSupportedException("Invalid Printing specified."); } PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true, expectedAllowDegradedPrinting: allowDegradedPrinting, expectedAllowPrinting: allowPrinting); if (protectAuth == FileAuthentication.Password) { using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword)) { PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true); } } }
private FunctionResult Execute(string searchPattern, bool includeSubFolders, bool returnFullPath, bool loopResults) { var tester = new FunctionTester <FileList>().Compile( new PropertyValue(FileListShared.IncludeSubfoldersPropertyName, includeSubFolders), new PropertyValue(FileListShared.ReturnFullPathPropertyName, returnFullPath), new PropertyValue(FileListShared.LoopResultsPropertyName, loopResults)); return(tester.Execute(new ParameterValue(FileListShared.FolderPathPropertyName, this.path), new ParameterValue(FileListShared.SearchPatternPropertyName, searchPattern))); }
protected FunctionResult Execute(TIn input) { var tester = new FunctionTester <TFunction>().Compile( GetStaticParameters(input) ); return(tester.Execute( GetDynamicParameters(input) )); }
private dynamic Execute(string fileName) { FunctionExecutor tester = new FunctionTester <BinaryFileRead>().Compile( ); var result = tester.Execute( new ParameterValue(FileShared.FilePathPropertyName, fileName) ); Assert.IsFalse(FileHelpers.IsFileLocked(fileName)); return(result); }
public void ValidateReadFormDataOutputStructure() { var tester = new FunctionTester<ReadProvider>(); FunctionDesigner designer = tester.CreateDesigner(); Assert.IsNull(designer.Output); Property readFormData = designer.Properties[PropertyNames.ReadFormData]; Assert.IsFalse(readFormData.GetValue<bool>()); readFormData.Value = true; Property returnDataAs = designer.Properties[PropertyNames.ReturnFormDataAs]; returnDataAs.Value = FormExtraction.CustomType; IEnumerable<ITypeProperty> properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertCompiled(OutputNames.FormData, typeof(object)); Property formDataType = designer.Properties[PropertyNames.FormDataType]; formDataType.Value = TypeReference.Create(typeof(string)); properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertCompiled(OutputNames.FormData, typeof(string)); returnDataAs.Value = FormExtraction.Infer; Property samplePdf = designer.Properties[PropertyNames.SamplePdf]; Assert.AreEqual(string.Empty, samplePdf.GetValue<string>()); properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertGenerated(OutputNames.FormData); Assert.AreEqual(0, properties.ElementAt(0).TypeReference.GetProperties().Count()); string blankPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory); samplePdf.Value = blankPdfFile; properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertGenerated(OutputNames.FormData); Assert.AreEqual(0, properties.ElementAt(0).TypeReference.GetProperties().Count()); string inferPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.InferFields.pdf", this.inputDirectory); samplePdf.Value = inferPdfFile; properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertGenerated(OutputNames.FormData); IEnumerable<ITypeProperty> outputProperties = properties.ElementAt(0).TypeReference.GetProperties(); Assert.AreEqual(2, outputProperties.Count()); outputProperties.ElementAt(0).AssertCompiled("First_32Name", typeof(string)); outputProperties.ElementAt(1).AssertCompiled("Surname", typeof(string)); returnDataAs.Value = FormExtraction.List; properties = designer.Output.GetProperties(); Assert.AreEqual(1, properties.Count()); properties.ElementAt(0).AssertList(OutputNames.FormDataList, typeof(KeyValuePair<string, string>)); }
public void ReadSignatureWithUnsignedDocument() { string blankPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); designer.Properties[PropertyNames.ReadSignature].Value = true; designer.Properties[PropertyNames.PdfFilePath].Value = blankPdfFile; designer.Properties[PropertyNames.AuthenticationType].Value = AuthenticationType.None; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.IsFalse(result.Value.Signatures.IsSigned); Assert.AreEqual(0, result.Value.Signatures.AllSignatures.Count); AssertSignature(result.Value.Signatures.LatestSignature, true, string.Empty, string.Empty, string.Empty, DateTime.MinValue.ToUniversalTime(), true, 0, "No certificate found.", false); }
public void ReadWithNoOutput( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication inputAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.ReadText].Value = false; designer.Properties[PropertyNames.ReadFormData].Value = false; designer.Properties[PropertyNames.ReadSignature].Value = false; var tester = new FunctionTester<ReadProvider>(); Assert.DoesNotThrow(() => tester.Execute(designer.GetProperties(), designer.GetParameters())); }
public void Split( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication inputAuth, [Values( true, false)] bool loopResults) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Split.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Split.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.Operation].Value = Operation.Split; designer.Properties[PropertyNames.SplitLoopResults].Value = loopResults; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual(2, result.Value.NumberOfPages); if (loopResults) { Assert.AreEqual(2, result.ExecutionPathResult.Count()); NextResult nextResult = result.ExecutionPathResult.ElementAt(0); Assert.AreEqual(ExecutionPathNames.PageFiles, nextResult.Name); AssertOutputFile(nextResult.Value, inputAuth, Path.Combine(this.outputDirectory, "Split_1.pdf"), 1, "1"); nextResult = result.ExecutionPathResult.ElementAt(1); Assert.AreEqual(ExecutionPathNames.PageFiles, nextResult.Name); AssertOutputFile(nextResult.Value, inputAuth, Path.Combine(this.outputDirectory, "Split_2.pdf"), 1, "2"); } else { Assert.AreEqual(2, result.Value.PageFiles.Count); string pageFile = result.Value.PageFiles[0]; AssertOutputFile(pageFile, inputAuth, Path.Combine(this.outputDirectory, "Split_1.pdf"), 1, "1"); pageFile = result.Value.PageFiles[1]; AssertOutputFile(pageFile, inputAuth, Path.Combine(this.outputDirectory, "Split_2.pdf"), 1, "2"); } }
public void ReadAcroFormDataWithInferredOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.Infer; string inferFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); designer.Properties[PropertyNames.SamplePdf].Value = inferFilePath; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("Jeremy", result.Value.FormData.First_32Name); Assert.AreEqual("Woods", result.Value.FormData.Surname); Assert.AreEqual("Male", result.Value.FormData.Gender); Assert.AreEqual("Yes", result.Value.FormData.AcceptTCs); }
public void ReadXfaFormDataWithInferredOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.Infer; string inferFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.InferFieldsXFA.pdf", this.inputDirectory); designer.Properties[PropertyNames.SamplePdf].Value = inferFilePath; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("John", result.Value.FormData.form1_910_93_46FullName_910_93); Assert.AreEqual("Doe", result.Value.FormData.form1_910_93_46Surname_910_93); Assert.AreEqual("*****@*****.**", result.Value.FormData.form1_910_93_46Email_910_93); Assert.AreEqual("1", result.Value.FormData.form1_910_93_46EmailMe_910_93); }
private FunctionResult Execute( ExistOptions fileExists, DoesNotExistOptions fileNotExist, string filePathProp, object contentsProp ) { FunctionExecutor tester = new FunctionTester <BinaryFileWrite>().Compile( new PropertyValue(BinaryFileWriteShared.FileExistsPropertyName, fileExists), new PropertyValue(BinaryFileWriteShared.FileDoesNotExistPropertyName, fileNotExist) ); var result = tester.Execute( new ParameterValue(FileShared.FilePathPropertyName, (BinaryFileHandle)filePathProp), new ParameterValue(BinaryFileWriteShared.ContentsPropertyName, contentsProp) ); Assert.IsFalse(FileHelpers.IsFileLocked(result.Value)); return(result); }
public void FillFormXfa( [Values( FileAuthentication.None, FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.FillFormXFA.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "FillXfa.pdf"); var formData = new { form1_910_93_46FullName_910_93 = "John", form1_910_93_46Surname_910_93 = "Doe", form1_910_93_46Email_910_93 = "*****@*****.**", form1_910_93_46EmailMe_910_93 = true }; FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.Operation].Value = Operation.FillForm; designer.Properties[PropertyNames.FillFormFormData].Value = formData; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); var formValues = new Dictionary <string, string> { { "form1[0].FullName[0]", formData.form1_910_93_46FullName_910_93 }, { "form1[0].Surname[0]", formData.form1_910_93_46Surname_910_93 }, { "form1[0].Email[0]", formData.form1_910_93_46Email_910_93 }, { "form1[0].EmailMe[0]", (formData.form1_910_93_46EmailMe_910_93) ? "Yes" : "No" }, { "form1[0]", "*****@*****.**" } }; PdfComparer.AssertFields(outputFilePath, inputAuth, this.authenticationManager, formValues); }
public void ProtectWithNoRestrictions( [Values( FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication protectAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertProtectionAllRights(outputFilePath, protectAuth, this.authenticationManager, true, true); }