Skip to content

Commit 196c86a

Browse files
committed
feat(Services): move Connector to base service to support unit testing
1 parent 3ab6811 commit 196c86a

File tree

13 files changed

+690
-1377
lines changed

13 files changed

+690
-1377
lines changed

Scripts/Services/Assistant/V1/AssistantService.cs

Lines changed: 136 additions & 271 deletions
Large diffs are not rendered by default.

Scripts/Services/Assistant/V2/AssistantService.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public AssistantService(string versionDate) : this(versionDate, ConfigBasedAuthe
7272
public AssistantService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId)
7373
{
7474
Authenticator = authenticator;
75+
7576
if (string.IsNullOrEmpty(versionDate))
7677
{
7778
throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of AssistantService");
@@ -81,7 +82,6 @@ public AssistantService(string versionDate, Authenticator authenticator) : base(
8182
VersionDate = versionDate;
8283
}
8384

84-
8585
if (string.IsNullOrEmpty(GetServiceUrl()))
8686
{
8787
SetServiceUrl(defaultServiceUrl);
@@ -132,13 +132,10 @@ public bool CreateSession(Callback<SessionResponse> callback, string assistantId
132132

133133
req.OnResponse = OnCreateSessionResponse;
134134

135-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions", assistantId), GetServiceUrl());
136-
if (connector == null)
137-
{
138-
return false;
139-
}
135+
Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions", assistantId);
136+
Authenticator.Authenticate(Connector);
140137

141-
return connector.Send(req);
138+
return Connector.Send(req);
142139
}
143140

144141
private void OnCreateSessionResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -211,13 +208,10 @@ public bool DeleteSession(Callback<object> callback, string assistantId, string
211208

212209
req.OnResponse = OnDeleteSessionResponse;
213210

214-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId), GetServiceUrl());
215-
if (connector == null)
216-
{
217-
return false;
218-
}
211+
Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId);
212+
Authenticator.Authenticate(Connector);
219213

220-
return connector.Send(req);
214+
return Connector.Send(req);
221215
}
222216

223217
private void OnDeleteSessionResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -305,13 +299,10 @@ public bool Message(Callback<MessageResponse> callback, string assistantId, stri
305299

306300
req.OnResponse = OnMessageResponse;
307301

308-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId), GetServiceUrl());
309-
if (connector == null)
310-
{
311-
return false;
312-
}
302+
Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId);
303+
Authenticator.Authenticate(Connector);
313304

314-
return connector.Send(req);
305+
return Connector.Send(req);
315306
}
316307

317308
private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response resp)

Scripts/Services/CompareComply/V1/CompareComplyService.cs

Lines changed: 37 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public CompareComplyService(string versionDate) : this(versionDate, ConfigBasedA
7272
public CompareComplyService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId)
7373
{
7474
Authenticator = authenticator;
75+
7576
if (string.IsNullOrEmpty(versionDate))
7677
{
7778
throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of CompareComplyService");
@@ -81,7 +82,6 @@ public CompareComplyService(string versionDate, Authenticator authenticator) : b
8182
VersionDate = versionDate;
8283
}
8384

84-
8585
if (string.IsNullOrEmpty(GetServiceUrl()))
8686
{
8787
SetServiceUrl(defaultServiceUrl);
@@ -140,13 +140,10 @@ public bool ConvertToHtml(Callback<HTMLReturn> callback, System.IO.MemoryStream
140140

141141
req.OnResponse = OnConvertToHtmlResponse;
142142

143-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/html_conversion", GetServiceUrl());
144-
if (connector == null)
145-
{
146-
return false;
147-
}
143+
Connector.URL = GetServiceUrl() + "/v1/html_conversion";
144+
Authenticator.Authenticate(Connector);
148145

149-
return connector.Send(req);
146+
return Connector.Send(req);
150147
}
151148

152149
private void OnConvertToHtmlResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -225,13 +222,10 @@ public bool ClassifyElements(Callback<ClassifyReturn> callback, System.IO.Memory
225222

226223
req.OnResponse = OnClassifyElementsResponse;
227224

228-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/element_classification", GetServiceUrl());
229-
if (connector == null)
230-
{
231-
return false;
232-
}
225+
Connector.URL = GetServiceUrl() + "/v1/element_classification";
226+
Authenticator.Authenticate(Connector);
233227

234-
return connector.Send(req);
228+
return Connector.Send(req);
235229
}
236230

237231
private void OnClassifyElementsResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -310,13 +304,10 @@ public bool ExtractTables(Callback<TableReturn> callback, System.IO.MemoryStream
310304

311305
req.OnResponse = OnExtractTablesResponse;
312306

313-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/tables", GetServiceUrl());
314-
if (connector == null)
315-
{
316-
return false;
317-
}
307+
Connector.URL = GetServiceUrl() + "/v1/tables";
308+
Authenticator.Authenticate(Connector);
318309

319-
return connector.Send(req);
310+
return Connector.Send(req);
320311
}
321312

322313
private void OnExtractTablesResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -413,13 +404,10 @@ public bool CompareDocuments(Callback<CompareReturn> callback, System.IO.MemoryS
413404

414405
req.OnResponse = OnCompareDocumentsResponse;
415406

416-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/comparison", GetServiceUrl());
417-
if (connector == null)
418-
{
419-
return false;
420-
}
407+
Connector.URL = GetServiceUrl() + "/v1/comparison";
408+
Authenticator.Authenticate(Connector);
421409

422-
return connector.Send(req);
410+
return Connector.Send(req);
423411
}
424412

425413
private void OnCompareDocumentsResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -500,13 +488,10 @@ public bool AddFeedback(Callback<FeedbackReturn> callback, FeedbackDataInput fee
500488

501489
req.OnResponse = OnAddFeedbackResponse;
502490

503-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/feedback", GetServiceUrl());
504-
if (connector == null)
505-
{
506-
return false;
507-
}
491+
Connector.URL = GetServiceUrl() + "/v1/feedback";
492+
Authenticator.Authenticate(Connector);
508493

509-
return connector.Send(req);
494+
return Connector.Send(req);
510495
}
511496

512497
private void OnAddFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -672,13 +657,10 @@ public bool ListFeedback(Callback<FeedbackList> callback, string feedbackType =
672657

673658
req.OnResponse = OnListFeedbackResponse;
674659

675-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/feedback", GetServiceUrl());
676-
if (connector == null)
677-
{
678-
return false;
679-
}
660+
Connector.URL = GetServiceUrl() + "/v1/feedback";
661+
Authenticator.Authenticate(Connector);
680662

681-
return connector.Send(req);
663+
return Connector.Send(req);
682664
}
683665

684666
private void OnListFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -751,13 +733,10 @@ public bool GetFeedback(Callback<GetFeedback> callback, string feedbackId, strin
751733

752734
req.OnResponse = OnGetFeedbackResponse;
753735

754-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/feedback/{0}", feedbackId), GetServiceUrl());
755-
if (connector == null)
756-
{
757-
return false;
758-
}
736+
Connector.URL = GetServiceUrl() + string.Format("/v1/feedback/{0}", feedbackId);
737+
Authenticator.Authenticate(Connector);
759738

760-
return connector.Send(req);
739+
return Connector.Send(req);
761740
}
762741

763742
private void OnGetFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -830,13 +809,10 @@ public bool DeleteFeedback(Callback<FeedbackDeleted> callback, string feedbackId
830809

831810
req.OnResponse = OnDeleteFeedbackResponse;
832811

833-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/feedback/{0}", feedbackId), GetServiceUrl());
834-
if (connector == null)
835-
{
836-
return false;
837-
}
812+
Connector.URL = GetServiceUrl() + string.Format("/v1/feedback/{0}", feedbackId);
813+
Authenticator.Authenticate(Connector);
838814

839-
return connector.Send(req);
815+
return Connector.Send(req);
840816
}
841817

842818
private void OnDeleteFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -969,13 +945,10 @@ public bool CreateBatch(Callback<BatchStatus> callback, string function, System.
969945

970946
req.OnResponse = OnCreateBatchResponse;
971947

972-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/batches", GetServiceUrl());
973-
if (connector == null)
974-
{
975-
return false;
976-
}
948+
Connector.URL = GetServiceUrl() + "/v1/batches";
949+
Authenticator.Authenticate(Connector);
977950

978-
return connector.Send(req);
951+
return Connector.Send(req);
979952
}
980953

981954
private void OnCreateBatchResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -1037,13 +1010,10 @@ public bool ListBatches(Callback<Batches> callback)
10371010

10381011
req.OnResponse = OnListBatchesResponse;
10391012

1040-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/batches", GetServiceUrl());
1041-
if (connector == null)
1042-
{
1043-
return false;
1044-
}
1013+
Connector.URL = GetServiceUrl() + "/v1/batches";
1014+
Authenticator.Authenticate(Connector);
10451015

1046-
return connector.Send(req);
1016+
return Connector.Send(req);
10471017
}
10481018

10491019
private void OnListBatchesResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -1108,13 +1078,10 @@ public bool GetBatch(Callback<BatchStatus> callback, string batchId)
11081078

11091079
req.OnResponse = OnGetBatchResponse;
11101080

1111-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/batches/{0}", batchId), GetServiceUrl());
1112-
if (connector == null)
1113-
{
1114-
return false;
1115-
}
1081+
Connector.URL = GetServiceUrl() + string.Format("/v1/batches/{0}", batchId);
1082+
Authenticator.Authenticate(Connector);
11161083

1117-
return connector.Send(req);
1084+
return Connector.Send(req);
11181085
}
11191086

11201087
private void OnGetBatchResponse(RESTConnector.Request req, RESTConnector.Response resp)
@@ -1195,13 +1162,10 @@ public bool UpdateBatch(Callback<BatchStatus> callback, string batchId, string a
11951162

11961163
req.OnResponse = OnUpdateBatchResponse;
11971164

1198-
RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/batches/{0}", batchId), GetServiceUrl());
1199-
if (connector == null)
1200-
{
1201-
return false;
1202-
}
1165+
Connector.URL = GetServiceUrl() + string.Format("/v1/batches/{0}", batchId);
1166+
Authenticator.Authenticate(Connector);
12031167

1204-
return connector.Send(req);
1168+
return Connector.Send(req);
12051169
}
12061170

12071171
private void OnUpdateBatchResponse(RESTConnector.Request req, RESTConnector.Response resp)

0 commit comments

Comments
 (0)