Skip to content

Commit

Permalink
feat(Services): move Connector to base service to support unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mamoonraja committed Nov 12, 2019
1 parent 3ab6811 commit 196c86a
Show file tree
Hide file tree
Showing 13 changed files with 690 additions and 1,377 deletions.
407 changes: 136 additions & 271 deletions Scripts/Services/Assistant/V1/AssistantService.cs

Large diffs are not rendered by default.

29 changes: 10 additions & 19 deletions Scripts/Services/Assistant/V2/AssistantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public AssistantService(string versionDate) : this(versionDate, ConfigBasedAuthe
public AssistantService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId)
{
Authenticator = authenticator;

if (string.IsNullOrEmpty(versionDate))
{
throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of AssistantService");
Expand All @@ -81,7 +82,6 @@ public AssistantService(string versionDate, Authenticator authenticator) : base(
VersionDate = versionDate;
}


if (string.IsNullOrEmpty(GetServiceUrl()))
{
SetServiceUrl(defaultServiceUrl);
Expand Down Expand Up @@ -132,13 +132,10 @@ public bool CreateSession(Callback<SessionResponse> callback, string assistantId

req.OnResponse = OnCreateSessionResponse;

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

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnDeleteSessionResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId), GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId);
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnMessageResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId), GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId);
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response resp)
Expand Down
110 changes: 37 additions & 73 deletions Scripts/Services/CompareComply/V1/CompareComplyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public CompareComplyService(string versionDate) : this(versionDate, ConfigBasedA
public CompareComplyService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId)
{
Authenticator = authenticator;

if (string.IsNullOrEmpty(versionDate))
{
throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of CompareComplyService");
Expand All @@ -81,7 +82,6 @@ public CompareComplyService(string versionDate, Authenticator authenticator) : b
VersionDate = versionDate;
}


if (string.IsNullOrEmpty(GetServiceUrl()))
{
SetServiceUrl(defaultServiceUrl);
Expand Down Expand Up @@ -140,13 +140,10 @@ public bool ConvertToHtml(Callback<HTMLReturn> callback, System.IO.MemoryStream

req.OnResponse = OnConvertToHtmlResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/html_conversion", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/html_conversion";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnClassifyElementsResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/element_classification", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/element_classification";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnExtractTablesResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/tables", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/tables";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnCompareDocumentsResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/comparison", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/comparison";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnAddFeedbackResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/feedback", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/feedback";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnListFeedbackResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/feedback", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/feedback";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnGetFeedbackResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/feedback/{0}", feedbackId), GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + string.Format("/v1/feedback/{0}", feedbackId);
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnDeleteFeedbackResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/feedback/{0}", feedbackId), GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + string.Format("/v1/feedback/{0}", feedbackId);
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnCreateBatchResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/batches", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/batches";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnListBatchesResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/batches", GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + "/v1/batches";
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnGetBatchResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/batches/{0}", batchId), GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + string.Format("/v1/batches/{0}", batchId);
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

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

req.OnResponse = OnUpdateBatchResponse;

RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/batches/{0}", batchId), GetServiceUrl());
if (connector == null)
{
return false;
}
Connector.URL = GetServiceUrl() + string.Format("/v1/batches/{0}", batchId);
Authenticator.Authenticate(Connector);

return connector.Send(req);
return Connector.Send(req);
}

private void OnUpdateBatchResponse(RESTConnector.Request req, RESTConnector.Response resp)
Expand Down
Loading

0 comments on commit 196c86a

Please sign in to comment.