-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocImportFolderTests.cs
138 lines (120 loc) · 4.42 KB
/
DocImportFolderTests.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// ----------------------------------------------------------------------------
// <copyright file="DocImportFolderTests.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Relativity.Server.Import.SDK.Samples.Helpers;
namespace Relativity.Server.Import.SDK.Samples.Tests
{
/// <summary>
/// Represents a test that imports native documents with folders and validates the results.
/// </summary>
/// <remarks>
/// Due to poor performance, disabling client-side implementation by default.
/// </remarks>
[TestFixture(false)]
[TestFixture(true)]
public class DocImportFolderTests : DocImportTestsBase
{
/// <summary>
/// The flag that indicates whether to create folders server-side or client-side.
/// </summary>
private readonly bool serverSideFolders;
/// <summary>
/// Initializes a new instance of the <see cref="DocImportFolderTests"/> class.
/// </summary>
/// <param name="serverSideFolders">
/// <see langword="true" /> to create all folders via server-side WebPI; otherwise, <see langword="false" /> to create all folders via client-side API.
/// </param>
public DocImportFolderTests(bool serverSideFolders)
{
this.serverSideFolders = serverSideFolders;
}
[Test]
[TestCase("00-te/st")]
[TestCase("01-te:st")]
[TestCase("02-te?st")]
[TestCase("03-te<st")]
[TestCase("04-te>st")]
[TestCase("05-te\"st")]
[TestCase("06-te|st")]
[TestCase("07-te*st")]
public void ShouldImportTheDocWhenTheFolderContainsInvalidChars(string invalidFolder)
{
// Arrange
IList<string> initialFolders = this.QueryWorkspaceFolders();
string controlNumber = GenerateControlNumber();
string folder = $"\\{invalidFolder}-{this.serverSideFolders}";
kCura.Relativity.DataReaderClient.ImportBulkArtifactJob job =
this.ArrangeImportJob(controlNumber, folder, SampleDocPdfFileName);
// Act
job.Execute();
// Assert - the invalid folders were scrubbed and the import job is successful.
this.AssertImportSuccess();
// Assert - a new folder is added to the workspace.
int expectedDocCount = initialFolders.Count + 1;
IList<string> actualFolders = this.QueryWorkspaceFolders();
Assert.That(actualFolders.Count, Is.EqualTo(expectedDocCount));
}
[Test]
[TestCase("\\case-root1")]
[TestCase("\\case-root1\\")]
[TestCase("\\case-root1\\case-root2")]
[TestCase("\\case-root1\\case-Root2")]
[TestCase("\\case-ROOT1\\case-root2")]
[TestCase("\\case-ROOT1\\case-Root2")]
[TestCase("\\case-ROOT1\\case-ROOT2")]
public void ShouldNotDuplicateFoldersDueToCaseSensitivity(string folder)
{
// Arrange
string controlNumber = GenerateControlNumber();
kCura.Relativity.DataReaderClient.ImportBulkArtifactJob job =
this.ArrangeImportJob(controlNumber, folder, SampleDocPdfFileName);
// Act
job.Execute();
// Assert - the invalid folders were scrubbed and the import job is successful.
this.AssertImportSuccess();
// Assert - SQL collation is case-insensitive.
int separators = folder.TrimEnd('\\').Count(x => x == '\\');
if (separators == 1)
{
this.AssertDistinctFolders("case-root1");
}
else
{
this.AssertDistinctFolders("case-root1", "case-root2");
}
}
[Test]
[TestCase(10)]
[TestCase(25)]
[TestCase(50)]
public void ShouldSupportTheMaxFolderDepth(int maxDepth)
{
// Arrange
string folderPath = GenerateFolderPath(maxDepth);
List<DocImportRecord> records = AllSampleDocFileNames.Select(fileName => new DocImportRecord
{
ControlNumber = GenerateControlNumber(),
File = ResourceFileHelper.GetDocsResourceFilePath(fileName),
Folder = folderPath,
}).ToList();
kCura.Relativity.DataReaderClient.ImportBulkArtifactJob job = this.ArrangeImportJob(records);
// Act
job.Execute();
// Assert - the import job is successful.
this.AssertImportSuccess();
// Assert - all max depth folders were created.
IEnumerable<string> folders = SplitFolderPath(folderPath);
this.AssertDistinctFolders(folders.ToArray());
}
protected override void OnSetup()
{
base.OnSetup();
Relativity.DataExchange.AppSettings.Instance.CreateFoldersInWebApi = this.serverSideFolders;
}
}
}