-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductionImportTests.cs
153 lines (136 loc) · 6.56 KB
/
ProductionImportTests.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// ----------------------------------------------------------------------------
// <copyright file="ProductionImportTests.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data;
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 production images and validates the results.
/// </summary>
/// <remarks>
/// This test requires the Relativity.Productions.Client package but hasn't yet been published to nuget.org.
/// </remarks>
[TestFixture]
public class ProductionImportTests : ImageImportTestsBase
{
/// <summary>
/// The first document control number.
/// </summary>
private const string FIRST_DOCUMENT_CONTROL_NUMBER = "EDRM-Sample-000001";
/// <summary>
/// The second document control number.
/// </summary>
private const string SECOND_DOCUMENT_CONTROL_NUMBER = "EDRM-Sample-001002";
/// <summary>
/// The total number of images for the first imported document.
/// </summary>
/// <remarks>
/// The last digits in <see cref="SECOND_DOCUMENT_CONTROL_NUMBER"/> must be updated if this value is changed.
/// </remarks>
private const int TOTAL_IMAGES_FOR_FIRST_DOCUMENT = 1001;
[Test]
public void ShouldImportTheProductionImages()
{
// Arrange
IList<string> controlNumbers = new List<string> { FIRST_DOCUMENT_CONTROL_NUMBER, SECOND_DOCUMENT_CONTROL_NUMBER };
this.ImportDocuments(controlNumbers);
string productionSetName = GenerateProductionSetName();
int productionId = this.CreateProduction(productionSetName, BatesPrefix);
// Act
this.ImportProduction(productionId);
// Assert - the job completed and the report matches the expected values.
Assert.That(this.PublishedJobReport, Is.Not.Null);
Assert.That(this.PublishedJobReport.EndTime, Is.GreaterThan(this.PublishedJobReport.StartTime));
Assert.That(this.PublishedJobReport.ErrorRowCount, Is.Zero);
Assert.That(this.PublishedJobReport.StartTime, Is.GreaterThan(this.StartTime));
Assert.That(this.PublishedJobReport.TotalRows, Is.EqualTo(this.DataSource.Rows.Count));
// Assert - the events match the expected values.
Assert.That(this.PublishedErrors.Count, Is.Zero);
Assert.That(this.PublishedFatalException, Is.Null);
Assert.That(this.PublishedMessages.Count, Is.Positive);
Assert.That(this.PublishedProcessProgress.Count, Is.Positive);
Assert.That(this.PublishedProgressRows.Count, Is.Positive);
// Assert - the first and last bates numbers match the expected values.
Tuple<string, string> batesNumbers = this.QueryProductionBatesNumbers(productionId);
string expectedFirstBatesValue = FIRST_DOCUMENT_CONTROL_NUMBER;
string expectedLastBatesValue = SECOND_DOCUMENT_CONTROL_NUMBER;
Assert.That(batesNumbers.Item1, Is.EqualTo(expectedFirstBatesValue));
Assert.That(batesNumbers.Item2, Is.EqualTo(expectedLastBatesValue));
// Assert the field values match the expected values.
IList<Relativity.Services.Objects.DataContracts.RelativityObject> documents = this.QueryDocuments();
Assert.That(documents, Is.Not.Null);
Relativity.Services.Objects.DataContracts.RelativityObject firstDocument = SearchRelativityObject(
documents,
WellKnownFields.ControlNumber,
FIRST_DOCUMENT_CONTROL_NUMBER);
Assert.That(firstDocument, Is.Not.Null);
Relativity.Services.Objects.DataContracts.RelativityObject secondDocument = SearchRelativityObject(
documents,
WellKnownFields.ControlNumber,
SECOND_DOCUMENT_CONTROL_NUMBER);
Assert.That(secondDocument, Is.Not.Null);
foreach (var document in new[] { firstDocument, secondDocument })
{
Relativity.Services.Objects.DataContracts.Choice hasImagesField = GetChoiceField(
document,
WellKnownFields.HasImages);
Assert.That(hasImagesField, Is.Not.Null);
Assert.That(hasImagesField.Name, Is.Not.Null);
Assert.That(hasImagesField.Name, Is.EqualTo("No"));
bool hasNativeField = GetBooleanFieldValue(document, WellKnownFields.HasNative);
Assert.That(hasNativeField, Is.False);
int? relativityImageCount = GetInt32FieldValue(document, WellKnownFields.RelativityImageCount);
Assert.That(relativityImageCount, Is.Null);
}
// Assert that importing doesn't add a file record.
IList<FileDto> firstDocumentImages = this.QueryImageFileInfo(firstDocument.ArtifactID).ToList();
Assert.That(firstDocumentImages.Count, Is.Zero);
IList<FileDto> secondDocumentImages = this.QueryImageFileInfo(secondDocument.ArtifactID).ToList();
Assert.That(secondDocumentImages.Count, Is.Zero);
}
private void ImportProduction(int productionId)
{
kCura.Relativity.ImportAPI.ImportAPI importApi = this.CreateImportApiObject();
IEnumerable<kCura.Relativity.ImportAPI.Data.ProductionSet> productionSets =
importApi.GetProductionSets(this.TestParameters.WorkspaceId).ToList();
Assert.That(productionSets.Count, Is.GreaterThan(0));
kCura.Relativity.ImportAPI.Data.ProductionSet productionSet =
productionSets.FirstOrDefault(x => x.ArtifactID == productionId);
Assert.That(productionSet, Is.Not.Null);
kCura.Relativity.DataReaderClient.ImageImportBulkArtifactJob job =
importApi.NewProductionImportJob(productionSet.ArtifactID);
this.ConfigureJobSettings(job);
job.Settings.NativeFileCopyMode = kCura.Relativity.DataReaderClient.NativeFileCopyModeEnum.DoNotImportNativeFiles;
this.ConfigureJobEvents(job);
this.DataSource.Columns.AddRange(new[]
{
new DataColumn(this.IdentifierFieldName, typeof(string)),
new DataColumn(WellKnownFields.BatesNumber, typeof(string)),
new DataColumn(WellKnownFields.FileLocation, typeof(string)),
});
DataRow row;
for (int i = 1; i <= TOTAL_IMAGES_FOR_FIRST_DOCUMENT; i++)
{
row = this.DataSource.NewRow();
row[this.IdentifierFieldName] = FIRST_DOCUMENT_CONTROL_NUMBER;
row[WellKnownFields.BatesNumber] = $"EDRM-Sample-{i:D6}";
row[WellKnownFields.FileLocation] = ResourceFileHelper.GetImagesResourceFilePath(SampleProductionImage1FileName);
this.DataSource.Rows.Add(row);
}
row = this.DataSource.NewRow();
row[this.IdentifierFieldName] = SECOND_DOCUMENT_CONTROL_NUMBER;
row[WellKnownFields.BatesNumber] = SECOND_DOCUMENT_CONTROL_NUMBER;
row[WellKnownFields.FileLocation] = ResourceFileHelper.GetImagesResourceFilePath(SampleProductionImage1FileName);
this.DataSource.Rows.Add(row);
job.SourceData.SourceData = this.DataSource;
job.Execute();
}
}
}