-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPrefillTextFields.cs
76 lines (65 loc) · 2.78 KB
/
PrefillTextFields.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SignNow.Net.Interfaces;
using SignNow.Net.Model.EditFields;
namespace SignNow.Net.Examples
{
public partial class DocumentExamples
{
[TestMethod]
public async Task PrefillTextFieldsAsync()
{
// Upload test document
await using var fileStream = File.OpenRead(PdfWithSignatureField);
var testDocument = await testContext.Documents
.UploadDocumentWithFieldExtractAsync(fileStream, "PrefillDocumentTest.pdf")
.ConfigureAwait(false);
// get uploaded document
var documentUploaded = await testContext.Documents.GetDocumentAsync(testDocument.Id).ConfigureAwait(false);
Assert.IsNull(documentUploaded.Fields.FirstOrDefault()?.JsonAttributes.PrefilledText);
// Add simple text field which will be prefilled next.
var editFields = new List<IFieldEditable>
{
new TextField
{
PageNumber = 0,
Name = "Text_1",
Height = 40,
Width = 200,
X = 10,
Y = 40,
Role = "Signer 1"
}
};
var editDocument = await testContext.Documents
.EditDocumentAsync(testDocument.Id, editFields)
.ConfigureAwait(false);
// Get edited document
var documentEdited = await testContext.Documents.GetDocumentAsync(editDocument.Id).ConfigureAwait(false);
// Check that document has fields
Assert.IsNull(documentEdited.Fields.FirstOrDefault()?.JsonAttributes.PrefilledText);
Assert.AreEqual("Text_1", documentEdited.Fields.FirstOrDefault()?.JsonAttributes.Name);
// Prefill text field
var fields = new List<TextField>
{
new TextField
{
Name = "Text_1",
PrefilledText = "Test Prefill"
}
};
await testContext.Documents.PrefillTextFieldsAsync(testDocument.Id, fields).ConfigureAwait(false);
// Get final document
var documentFinal = await testContext.Documents.GetDocumentAsync(testDocument.Id).ConfigureAwait(false);
// Check that document has fields
Assert.AreEqual("Test Prefill", documentFinal.Fields.FirstOrDefault()?.JsonAttributes.PrefilledText);
// clean up
DeleteTestDocument(documentUploaded.Id);
DeleteTestDocument(documentEdited.Id);
DeleteTestDocument(documentFinal.Id);
}
}
}