Skip to content

Commit acc8901

Browse files
committed
Model constructors improved
1 parent 321b154 commit acc8901

File tree

79 files changed

+1109
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1109
-137
lines changed

Aspose.Email-Cloud.Tests/Tests/TestFixture.cs

Lines changed: 44 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public async Task SyncTest()
8181
public async Task HierarchicalTest()
8282
{
8383
var calendarFile = await CreateCalendar();
84-
var request = new GetCalendarRequest(calendarFile, folder, StorageName);
85-
var calendar = await emailApi.GetCalendarAsync(request);
84+
var calendar = await emailApi.GetCalendarAsync(
85+
new GetCalendarRequest(calendarFile, folder, StorageName));
8686
Assert.AreEqual("CALENDAR", calendar.Name);
8787
Assert.GreaterOrEqual(
8888
calendar.InternalProperties
@@ -104,15 +104,15 @@ public async Task StreamTest()
104104
var calendarFile = await CreateCalendar();
105105
var newFileName = $"{Guid.NewGuid().ToString()}.ics";
106106
var newPath = $"{folder}/{newFileName}";
107-
var request = new DownloadFileRequest($"{folder}/{calendarFile}", StorageName);
108-
using (var stream = await emailApi.DownloadFileAsync(request))
107+
using (var stream = await emailApi.DownloadFileAsync(
108+
new DownloadFileRequest($"{folder}/{calendarFile}", StorageName)))
109109
{
110110
var uploadRequest = new UploadFileRequest(newPath, stream, StorageName);
111111
await emailApi.UploadFileAsync(uploadRequest);
112112
}
113113

114-
var existRequest = new ObjectExistsRequest(newPath, StorageName);
115-
var newFileExist = await emailApi.ObjectExistsAsync(existRequest);
114+
var newFileExist = await emailApi.ObjectExistsAsync(
115+
new ObjectExistsRequest(newPath, StorageName));
116116
Assert.IsTrue(newFileExist.Exists);
117117
Assert.IsFalse(newFileExist.IsFolder);
118118
}
@@ -128,19 +128,11 @@ public async Task ContactFormatTest()
128128
foreach (var format in new[] {"vcard", "msg"})
129129
{
130130
var extension = format == "vcard" ? ".vcf" : ".msg";
131-
var request = new CreateContactRequest
132-
{
133-
format = format,
134-
name = $"{Guid.NewGuid().ToString()}{extension}",
135-
request = new HierarchicalObjectRequest
136-
{
137-
StorageFolder = new StorageFolderLocation {Storage = StorageName, FolderPath = folder},
138-
HierarchicalObject = new HierarchicalObject
139-
{Name = "CONTACT", InternalProperties = new List<BaseObject>()}
140-
}
141-
};
142-
await emailApi.CreateContactAsync(request);
143-
var contactExist = await IsFileExist(request.name);
131+
var name = $"{Guid.NewGuid().ToString()}{extension}";
132+
await emailApi.CreateContactAsync(new CreateContactRequest(format, name,
133+
new HierarchicalObjectRequest(new HierarchicalObject("CONTACT", null, new List<BaseObject>()),
134+
new StorageFolderLocation(StorageName, folder))));
135+
var contactExist = await IsFileExist(name);
144136
Assert.IsTrue(contactExist);
145137
}
146138
}
@@ -156,8 +148,7 @@ public async Task DateTimeTest()
156148
{
157149
var startDate = DateTime.UtcNow.Date.AddDays(1).AddHours(12);
158150
var calendarFile = await CreateCalendar(startDate);
159-
var request = new GetCalendarRequest(calendarFile, folder, StorageName);
160-
var calendar = await emailApi.GetCalendarAsync(request);
151+
var calendar = await emailApi.GetCalendarAsync(new GetCalendarRequest(calendarFile, folder, StorageName));
161152
var startDateProperty = calendar.InternalProperties
162153
.First(property => property.Name == "STARTDATE");
163154
var factStartDate = DateTime
@@ -184,9 +175,7 @@ public async Task AiNameGenderizeTest()
184175
public async Task AiNameFormatTest()
185176
{
186177
var result = await emailApi.AiNameFormatAsync(
187-
new AiNameFormatRequest(
188-
"Mr. John Michael Cane",
189-
format:"%t%L%f%m"));
178+
new AiNameFormatRequest("Mr. John Michael Cane", format: "%t%L%f%m"));
190179
Assert.AreEqual("Mr. Cane J. M.", result.Name);
191180
}
192181

@@ -209,8 +198,7 @@ public async Task AiNameExpandTest()
209198
const string name = "Smith Bobby";
210199
var result = await emailApi.AiNameExpandAsync(
211200
new AiNameExpandRequest(name));
212-
var expandedNames = result
213-
.Names
201+
var expandedNames = result.Names
214202
.Select(weightedName => weightedName.Name)
215203
.ToList();
216204
Assert.Contains("Mr. Smith", expandedNames);
@@ -267,27 +255,10 @@ public async Task AiBcrParseStorageTest()
267255
await emailApi.CreateFolderAsync(new CreateFolderRequest(outFolderPath, StorageName));
268256
// 2) Call business card recognition action
269257
var result = await emailApi.AiBcrParseStorageAsync(new AiBcrParseStorageRequest(
270-
new AiBcrParseStorageRq
271-
{
272-
Images = new List<AiBcrImageStorageFile>
273-
{
274-
new AiBcrImageStorageFile
275-
{
276-
File = new StorageFileLocation
277-
{
278-
Storage = StorageName,
279-
FileName = fileName,
280-
FolderPath = folder
281-
},
282-
IsSingle = true
283-
}
284-
},
285-
OutFolder = new StorageFolderLocation
286-
{
287-
Storage = StorageName,
288-
FolderPath = outFolderPath
289-
}
290-
}));
258+
new AiBcrParseStorageRq(null,
259+
new List<AiBcrImageStorageFile>
260+
{new AiBcrImageStorageFile(true, new StorageFileLocation(StorageName, folder, fileName))},
261+
new StorageFolderLocation(StorageName, outFolderPath))));
291262
//Check that only one file produced
292263
Assert.True(result.Value.Count == 1);
293264
// 3) Get file name from recognition result
@@ -296,13 +267,13 @@ public async Task AiBcrParseStorageTest()
296267
// 4) Download VCard file, produced by recognition method, check it contains text "Thomas"
297268
using (var contactFileStream = await emailApi.DownloadFileAsync(new DownloadFileRequest(
298269
$"{contactFile.FolderPath}/{contactFile.FileName}", contactFile.Storage)))
299-
using(var memoryStream = new MemoryStream())
270+
using (var memoryStream = new MemoryStream())
300271
{
301272
contactFileStream.CopyTo(memoryStream);
302273
var contactFileContent = Encoding.UTF8.GetString(memoryStream.ToArray());
303274
Assert.True(contactFileContent.Contains("Thomas"));
304275
}
305-
276+
306277
// 5) Get VCard object properties list, check that there are 3 properties or more
307278
var contactProperties = await emailApi.GetContactPropertiesAsync(new GetContactPropertiesRequest(
308279
"vcard", contactFile.FileName, contactFile.FolderPath, contactFile.Storage));
@@ -316,25 +287,14 @@ public async Task AiBcrParseStorageTest()
316287
[Test]
317288
public async Task AiBcrParseTest()
318289
{
319-
var result = await emailApi.AiBcrParseAsync(
320-
new AiBcrParseRequest(
321-
new AiBcrBase64Rq
322-
{
323-
Images = new List<AiBcrBase64Image>
324-
{
325-
new AiBcrBase64Image
326-
{
327-
Base64Data = FileToBase64(BcrAiTestFilePath),
328-
IsSingle = true
329-
}
330-
}
331-
}));
290+
var result = await emailApi.AiBcrParseAsync(new AiBcrParseRequest(new AiBcrBase64Rq(null,
291+
new List<AiBcrBase64Image> {new AiBcrBase64Image(true, FileToBase64(BcrAiTestFilePath))})));
332292
Assert.AreEqual(1, result.Value.Count);
333293
Assert.True(result.Value
334294
.First()
335295
.InternalProperties
336296
.Where(property => property.Type == nameof(PrimitiveObject))
337-
.Select(property => (PrimitiveObject)property)
297+
.Select(property => (PrimitiveObject) property)
338298
.Any(property => property.Value?.Contains("Thomas") ?? false));
339299
}
340300

@@ -357,49 +317,31 @@ private async Task<string> CreateCalendar(DateTime? startDate = null)
357317
var fileName = $"{Guid.NewGuid().ToString()}.ics";
358318
startDate = startDate ?? DateTime.UtcNow.Date.AddDays(1).AddHours(12);
359319
var endDate = startDate.Value.AddHours(1);
360-
var request = new CreateCalendarRequest
361-
{
362-
name = fileName,
363-
request = new HierarchicalObjectRequest
364-
{
365-
HierarchicalObject = new HierarchicalObject
366-
{
367-
Name = "CALENDAR", InternalProperties = new List<BaseObject>
320+
var request = new CreateCalendarRequest(fileName,
321+
new HierarchicalObjectRequest(
322+
new HierarchicalObject("CALENDAR", null,
323+
new List<BaseObject>
368324
{
369-
new PrimitiveObject {Name = "LOCATION", Value = "location"},
370-
new PrimitiveObject {Name = "STARTDATE", Value = startDate.Value.ToString("u")},
371-
new PrimitiveObject {Name = "ENDDATE", Value = endDate.ToString("u")},
372-
new HierarchicalObject
373-
{
374-
Name = "ORGANIZER", InternalProperties = new List<BaseObject>
325+
new PrimitiveObject("LOCATION", null, "location"),
326+
new PrimitiveObject("STARTDATE", null, startDate.Value.ToString("u")),
327+
new PrimitiveObject("ENDDATE", null, endDate.ToString("u")),
328+
new HierarchicalObject("ORGANIZER", null,
329+
new List<BaseObject>
375330
{
376-
new PrimitiveObject {Name = "ADDRESS", Value = "organizer@am.ru"},
377-
new PrimitiveObject {Name = "DISPLAYNAME", Value = "Piu Man"}
378-
}
379-
},
380-
new HierarchicalObject
381-
{
382-
Name = "ATTENDEES", InternalProperties = new List<BaseObject>
331+
new PrimitiveObject("ADDRESS", null, "organizer@am.ru"),
332+
new PrimitiveObject("DISPLAYNAME", null, "Piu Man")
333+
}),
334+
new HierarchicalObject("ATTENDEES", null,
335+
new List<BaseObject>
383336
{
384-
new IndexedHierarchicalObject
385-
{
386-
Index = 0, Name = "ATTENDEE", InternalProperties = new List<BaseObject>
337+
new IndexedHierarchicalObject("ATTENDEE", null, 0,
338+
new List<BaseObject>
387339
{
388-
new PrimitiveObject {Name = "ADDRESS", Value = "attendee@am.ru"},
389-
new PrimitiveObject {Name = "DISPLAYNAME", Value = "Attendee Name"}
390-
}
391-
}
392-
}
393-
}
394-
}
395-
},
396-
StorageFolder = new StorageFolderLocation
397-
{
398-
Storage = "First Storage",
399-
FolderPath = folder
400-
}
401-
}
402-
};
340+
new PrimitiveObject("ADDRESS", null, "attendee@am.ru"),
341+
new PrimitiveObject("DISPLAYNAME", null, "Attendee Name")
342+
})
343+
})
344+
}), new StorageFolderLocation(StorageName, folder)));
403345
await emailApi.CreateCalendarAsync(request);
404346
return fileName;
405347
}

Model/AccountBaseRequest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ public class AccountBaseRequest
5252
/// </summary>
5353
public StorageFolderLocation StorageFolder { get; set; }
5454

55+
/// <summary>AccountBaseRequest constructor</summary>
56+
public AccountBaseRequest() {}
57+
58+
/// <summary>AccountBaseRequest constructor</summary>
59+
/// <param name="firstAccount">First account storage file name for receiving emails (or universal one) </param>
60+
/// <param name="secondAccount">Second account storage file name for sending emails (ignored if first is universal) </param>
61+
/// <param name="storageFolder">Storage folder location of account files </param>
62+
public AccountBaseRequest(string firstAccount, string secondAccount, StorageFolderLocation storageFolder)
63+
{
64+
FirstAccount = firstAccount;
65+
SecondAccount = secondAccount;
66+
StorageFolder = storageFolder;
67+
}
5568
/// <summary>
5669
/// Get the string presentation of the object
5770
/// </summary>

Model/AddAttachmentRequest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ public class AddAttachmentRequest
4747
/// </summary>
4848
public StorageFolderLocation AttachmentFolder { get; set; }
4949

50+
/// <summary>AddAttachmentRequest constructor</summary>
51+
public AddAttachmentRequest() {}
52+
53+
/// <summary>AddAttachmentRequest constructor</summary>
54+
/// <param name="documentFolder">Storage folder location of document </param>
55+
/// <param name="attachmentFolder">Storage folder location of an attachment </param>
56+
public AddAttachmentRequest(StorageFolderLocation documentFolder, StorageFolderLocation attachmentFolder)
57+
{
58+
DocumentFolder = documentFolder;
59+
AttachmentFolder = attachmentFolder;
60+
}
5061
/// <summary>
5162
/// Get the string presentation of the object
5263
/// </summary>

Model/AiBcrBase64Image.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public class AiBcrBase64Image : AiBcrImage
4242
/// </summary>
4343
public string Base64Data { get; set; }
4444

45+
/// <summary>AiBcrBase64Image constructor</summary>
46+
public AiBcrBase64Image() {}
47+
48+
/// <summary>AiBcrBase64Image constructor</summary>
49+
/// <param name="isSingle">Determines that image contains single VCard or more </param>
50+
/// <param name="base64Data">Image data in base64 </param>
51+
public AiBcrBase64Image(bool? isSingle, string base64Data)
52+
{
53+
IsSingle = isSingle;
54+
Base64Data = base64Data;
55+
}
4556
/// <summary>
4657
/// Get the string presentation of the object
4758
/// </summary>
@@ -50,6 +61,7 @@ public override string ToString()
5061
{
5162
var sb = new StringBuilder();
5263
sb.Append("class AiBcrBase64Image {\n");
64+
sb.Append(" IsSingle: ").Append(this.IsSingle).Append("\n");
5365
sb.Append(" Base64Data: ").Append(this.Base64Data).Append("\n");
5466
sb.Append("}\n");
5567
return sb.ToString();

Model/AiBcrBase64Rq.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public class AiBcrBase64Rq : AiBcrRq
4242
/// </summary>
4343
public List<AiBcrBase64Image> Images { get; set; }
4444

45+
/// <summary>AiBcrBase64Rq constructor</summary>
46+
public AiBcrBase64Rq() {}
47+
48+
/// <summary>AiBcrBase64Rq constructor</summary>
49+
/// <param name="options">Recognition options </param>
50+
/// <param name="images">Images to recognize </param>
51+
public AiBcrBase64Rq(AiBcrOptions options, List<AiBcrBase64Image> images)
52+
{
53+
Options = options;
54+
Images = images;
55+
}
4556
/// <summary>
4657
/// Get the string presentation of the object
4758
/// </summary>
@@ -50,6 +61,7 @@ public override string ToString()
5061
{
5162
var sb = new StringBuilder();
5263
sb.Append("class AiBcrBase64Rq {\n");
64+
sb.Append(" Options: ").Append(this.Options).Append("\n");
5365
sb.Append(" Images: ").Append(this.Images).Append("\n");
5466
sb.Append("}\n");
5567
return sb.ToString();

Model/AiBcrImage.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public class AiBcrImage
4242
/// </summary>
4343
public bool? IsSingle { get; set; }
4444

45+
/// <summary>AiBcrImage constructor</summary>
46+
public AiBcrImage() {}
47+
48+
/// <summary>AiBcrImage constructor</summary>
49+
/// <param name="isSingle">Determines that image contains single VCard or more </param>
50+
public AiBcrImage(bool? isSingle)
51+
{
52+
IsSingle = isSingle;
53+
}
4554
/// <summary>
4655
/// Get the string presentation of the object
4756
/// </summary>

Model/AiBcrImageStorageFile.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public class AiBcrImageStorageFile : AiBcrImage
4242
/// </summary>
4343
public StorageFileLocation File { get; set; }
4444

45+
/// <summary>AiBcrImageStorageFile constructor</summary>
46+
public AiBcrImageStorageFile() {}
47+
48+
/// <summary>AiBcrImageStorageFile constructor</summary>
49+
/// <param name="isSingle">Determines that image contains single VCard or more </param>
50+
/// <param name="file">Image location </param>
51+
public AiBcrImageStorageFile(bool? isSingle, StorageFileLocation file)
52+
{
53+
IsSingle = isSingle;
54+
File = file;
55+
}
4556
/// <summary>
4657
/// Get the string presentation of the object
4758
/// </summary>
@@ -50,6 +61,7 @@ public override string ToString()
5061
{
5162
var sb = new StringBuilder();
5263
sb.Append("class AiBcrImageStorageFile {\n");
64+
sb.Append(" IsSingle: ").Append(this.IsSingle).Append("\n");
5365
sb.Append(" File: ").Append(this.File).Append("\n");
5466
sb.Append("}\n");
5567
return sb.ToString();

Model/AiBcrOcrData.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ public class AiBcrOcrData
5757
/// </summary>
5858
public List<AiBcrOcrDataPart> Data { get; set; }
5959

60+
/// <summary>AiBcrOcrData constructor</summary>
61+
public AiBcrOcrData() {}
62+
63+
/// <summary>AiBcrOcrData constructor</summary>
64+
/// <param name="id">Image identifier </param>
65+
/// <param name="image">Image with possible pre-processing in Base64 </param>
66+
/// <param name="details">Additional details from OCR engine </param>
67+
/// <param name="data">OCR results </param>
68+
public AiBcrOcrData(string id, string image, Dictionary<string, string> details, List<AiBcrOcrDataPart> data)
69+
{
70+
Id = id;
71+
Image = image;
72+
Details = details;
73+
Data = data;
74+
}
6075
/// <summary>
6176
/// Get the string presentation of the object
6277
/// </summary>

0 commit comments

Comments
 (0)