Skip to content

Commit be823ee

Browse files
Implement RawResultItem
1 parent 8e8e7c5 commit be823ee

File tree

6 files changed

+166
-4
lines changed

6 files changed

+166
-4
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using RestSharp;
5+
6+
namespace Regula.DocumentReader.WebClient.Model
7+
{
8+
public class RawResultItem : ResultItem, IDictionary<string, object>
9+
{
10+
private readonly Dictionary<string, object> _members;
11+
12+
public RawResultItem()
13+
{
14+
_members = new Dictionary<string, object>();
15+
}
16+
17+
public void Add(string key, object value)
18+
{
19+
_members.Add(key, value);
20+
}
21+
22+
public bool ContainsKey(string key)
23+
{
24+
return _members.ContainsKey(key);
25+
}
26+
27+
public ICollection<string> Keys => _members.Keys;
28+
29+
public bool Remove(string key)
30+
{
31+
return _members.Remove(key);
32+
}
33+
34+
public bool TryGetValue(string key, out object value)
35+
{
36+
return _members.TryGetValue(key, out value);
37+
}
38+
39+
public ICollection<object> Values => _members.Values;
40+
41+
public object this[string key]
42+
{
43+
get => _members[key];
44+
set => _members[key] = value;
45+
}
46+
47+
public void Add(KeyValuePair<string, object> item)
48+
{
49+
_members.Add(item.Key, item.Value);
50+
}
51+
52+
public void Clear()
53+
{
54+
_members.Clear();
55+
}
56+
57+
public bool Contains(KeyValuePair<string, object> item)
58+
{
59+
return _members.TryGetValue(item.Key, out object value) && value == item.Value;
60+
}
61+
62+
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
63+
{
64+
if (array == null) throw new ArgumentNullException(nameof(array));
65+
66+
int num = Count;
67+
foreach (var kvp in this)
68+
{
69+
array[arrayIndex++] = kvp;
70+
if (--num <= 0) return;
71+
}
72+
}
73+
74+
public int Count => _members.Count;
75+
76+
public bool IsReadOnly => false;
77+
78+
public bool Remove(KeyValuePair<string, object> item)
79+
{
80+
return _members.Remove(item.Key);
81+
}
82+
83+
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
84+
{
85+
return _members.GetEnumerator();
86+
}
87+
88+
IEnumerator IEnumerable.GetEnumerator()
89+
{
90+
return _members.GetEnumerator();
91+
}
92+
93+
public override string ToString()
94+
{
95+
return SimpleJson.SerializeObject(this);
96+
}
97+
}
98+
}

src/Regula.DocumentReader.WebClient/Model/ResultItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace Regula.DocumentReader.WebClient.Model
3232
[JsonSubtypes.KnownSubType(typeof(ChosenDocumentTypeResult), Result.DOCUMENT_TYPE)]
3333
[JsonSubtypes.KnownSubType(typeof(TextResult), Result.TEXT)]
3434
[JsonSubtypes.KnownSubType(typeof(GraphicsResult), Result.VISUAL_GRAPHICS)]
35-
public partial class ResultItem : IEquatable<ResultItem>, IValidatableObject
35+
[JsonSubtypes.FallBackSubType(typeof(RawResultItem))]
36+
public partial class ResultItem : IEquatable<ResultItem>, IValidatableObject
3637
{
3738
/// <summary>
3839
/// Initializes a new instance of the <see cref="ResultItem" /> class.

src/Regula.DocumentReader.WebClient/Regula.DocumentReader.WebClient.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Product>DocumentReader WebClient</Product>
77
<PackageTags>regula document processing id card rfid ocr barcode ipi</PackageTags>
88
<PackageId>Regula.DocumentReader.WebClient</PackageId>
9-
<PackageVersion>5.2.0</PackageVersion>
10-
<Version>1.0.1</Version>
9+
<PackageVersion>5.2.1</PackageVersion>
10+
<Version>5.2.1</Version>
1111
</PropertyGroup>
1212
<ItemGroup>
1313
<PackageReference Include="JsonSubTypes" Version="1.7.0" />

src/Regula.DocumentReader.WebClientTest/Regula.DocumentReader.WebClientTest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<None Update="response.json">
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</None>
20+
<None Update="raw_response.json">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</None>
2023
</ItemGroup>
2124

2225
<ItemGroup>

src/Regula.DocumentReader.WebClientTest/ResponseTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Collections.Generic;
12
using System.IO;
23
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
35
using NUnit.Framework;
46
using Regula.DocumentReader.WebClient.Model;
57
using Regula.DocumentReader.WebClient.Model.Ext;
@@ -28,7 +30,15 @@ public void ShouldProcessValidResponse()
2830
[Test]
2931
public void ShouldProcessRawResultType()
3032
{
31-
Assert.Fail();
33+
var response = GetResponseFromFile("raw_response.json");
34+
var rawResultItem = response.OriginalResponse.ContainerList.List[0] as IDictionary<string, object>;
35+
36+
Assert.IsNotNull(rawResultItem);
37+
Assert.AreEqual(6, rawResultItem.Count);
38+
39+
var jsonObj = rawResultItem["Raw"] as JObject;
40+
Assert.IsNotNull(jsonObj);
41+
Assert.AreEqual(0, (int)jsonObj["overallStatus"]);
3242
}
3343

3444
private static RecognitionResponse GetResponseFromFile(string fileName)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"ChipPage": 2,
3+
"ContainerList": {
4+
"Count": 4,
5+
"List": [
6+
{
7+
"Raw": {
8+
"detailsOptical": {
9+
"docType": 1,
10+
"expiry": 0,
11+
"imageQA": 1,
12+
"mrz": 0,
13+
"overallStatus": 0,
14+
"pagesCount": 2,
15+
"security": 2,
16+
"text": 0
17+
},
18+
"detailsRFID": {
19+
"AA": 2,
20+
"BAC": 2,
21+
"CA": 2,
22+
"PA": 2,
23+
"PACE": 2,
24+
"TA": 2,
25+
"overallStatus": 2
26+
},
27+
"optical": 0,
28+
"overallStatus": 0,
29+
"portrait": 2,
30+
"rfid": 2,
31+
"stopList": 2
32+
},
33+
"buf_length": 80,
34+
"light": 0,
35+
"list_idx": 0,
36+
"page_idx": 0,
37+
"result_type": 0
38+
}
39+
]
40+
},
41+
"ProcessingFinished": 1,
42+
"TransactionInfo": {
43+
"ComputerName": "SATSUKEVICH877",
44+
"DateTime": "2020-09-17T13:27:46.296Z",
45+
"TransactionID": "c08681b6-80b1-4070-b6b8-efb80ec38f9c",
46+
"UserName": "SYSTEM"
47+
},
48+
"elapsedTime": 391,
49+
"morePagesAvailable": 0
50+
}

0 commit comments

Comments
 (0)