-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMoveTheDocumentToFolder.cs
More file actions
45 lines (39 loc) · 1.94 KB
/
MoveTheDocumentToFolder.cs
File metadata and controls
45 lines (39 loc) · 1.94 KB
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
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SignNow.Net.Examples
{
public partial class DocumentExamples
{
[TestMethod]
public async Task MoveDocumentToFolderAsync()
{
// Upload test document
await using var fileStream = File.OpenRead(PdfWithSignatureField);
var testDocument = await testContext.Documents
.UploadDocumentAsync(fileStream, "MoveDocumentTest.pdf");
// Create new Folder where you'd like to keep test document
var root = await testContext.Folders.GetAllFoldersAsync().ConfigureAwait(false);
var documentsFolder = root.Folders.FirstOrDefault(f => f.Name == "Documents");
var folderToMove = await testContext.Folders
.CreateFolderAsync("FolderToMoveDocument", documentsFolder?.Id)
.ConfigureAwait(false);
// Move test document to folder created with previous step
await testContext.Documents
.MoveDocumentAsync(testDocument.Id, folderToMove.Id)
.ConfigureAwait(false);
// Get folder with updated document
var folderToMoveUpdated = await testContext.Folders
.GetFolderAsync(folderToMove.Id)
.ConfigureAwait(false);
// Check if test document has been moved
Assert.AreEqual("FolderToMoveDocument", folderToMoveUpdated.Name);
Assert.AreEqual(1, folderToMoveUpdated.TotalDocuments);
Assert.AreEqual(testDocument.Id, folderToMoveUpdated.Documents.FirstOrDefault(d => d.Id == testDocument.Id)?.Id);
// Finally - delete document and folder
await testContext.Documents.DeleteDocumentAsync(testDocument.Id).ConfigureAwait(false);
await testContext.Folders.DeleteFolderAsync(folderToMoveUpdated.Id).ConfigureAwait(false);
}
}
}