-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRecognizeTests.cs
More file actions
90 lines (75 loc) · 3.01 KB
/
RecognizeTests.cs
File metadata and controls
90 lines (75 loc) · 3.01 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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Aspose.BarCode.Cloud.Sdk.Api;
using Aspose.BarCode.Cloud.Sdk.Interfaces;
using Aspose.BarCode.Cloud.Sdk.Model;
using NUnit.Framework;
namespace Aspose.BarCode.Cloud.Sdk.Tests
{
[TestFixture]
public class RecognizeTests : TestsBase
{
private IRecognizeApi _api;
[SetUp]
public void Init()
{
_api = new RecognizeApi(TestConfiguration);
}
[TearDown]
public void Cleanup()
{
}
[Test]
public async Task RecognizeBase64AsyncTest()
{
// Arrange
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");
byte[] buffer = new byte[image.Length];
_ = await image.ReadAsync(buffer, 0, buffer.Length);
// Act
BarcodeResponseList response = await _api.RecognizeBase64Async(
new RecognizeBase64Request()
{
RecognitionImageKind = RecognitionImageKind.ClearImage,
RecognitionMode = RecognitionMode.Normal,
BarcodeTypes = new List<DecodeBarcodeType> { DecodeBarcodeType.QR },
FileBase64 = Convert.ToBase64String(buffer)
}
);
// Assert
Assert.AreEqual(1, response.Barcodes.Count);
Assert.AreEqual(DecodeBarcodeType.QR.ToString(), response.Barcodes[0].Type);
Assert.AreEqual("Hello world!", response.Barcodes[0].BarcodeValue);
}
[Test]
public async Task RecognizeMultipartAsyncTest()
{
// Arrange
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");
// Act
BarcodeResponseList response = await _api.RecognizeMultipartAsync(DecodeBarcodeType.QR, image,
recognitionImageKind: RecognitionImageKind.ClearImage, recognitionMode: RecognitionMode.Normal);
// Assert
Assert.AreEqual(1, response.Barcodes.Count);
Assert.AreEqual(DecodeBarcodeType.QR.ToString(), response.Barcodes[0].Type);
Assert.AreEqual("Hello world!", response.Barcodes[0].BarcodeValue);
}
[Test]
public async Task RecognizeAsyncTest()
{
// Arrange
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");
// Act
BarcodeResponseList response = await _api.RecognizeAsync(DecodeBarcodeType.QR,
"https://products.aspose.app/barcode/scan/img/how-to/scan/step2.png",
recognitionImageKind: RecognitionImageKind.ClearImage,
recognitionMode: RecognitionMode.Normal);
// Assert
Assert.AreEqual(1, response.Barcodes.Count);
Assert.AreEqual(DecodeBarcodeType.QR.ToString(), response.Barcodes[0].Type);
Assert.AreEqual("http://en.m.wikipedia.org", response.Barcodes[0].BarcodeValue);
}
}
}