Skip to content

Commit 717b47f

Browse files
committed
test(discovery-v2): update ITs
1 parent 19103e6 commit 717b47f

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

Tests/DiscoveryV2IntegrationTests.cs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using IBM.Cloud.SDK;
2424
using IBM.Cloud.SDK.Authentication;
2525
using IBM.Cloud.SDK.Authentication.Bearer;
26+
using IBM.Cloud.SDK.Authentication.Iam;
2627
using IBM.Cloud.SDK.Utilities;
2728
using IBM.Watson.Discovery.V2;
2829
using IBM.Watson.Discovery.V2.Model;
@@ -733,5 +734,125 @@ public IEnumerator TestDeleteProject()
733734
yield return null;
734735
}
735736
#endregion
737+
738+
#region QueryCollectionNotices
739+
//[UnityTest, Order(103)]
740+
public IEnumerator TestQueryCollectionNotices()
741+
{
742+
Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to QueryCollectionNotices...");
743+
bool queryCollectionNoticesResponse = false;
744+
745+
service.QueryCollectionNotices(
746+
callback: (DetailedResponse<QueryNoticesResponse> response, IBMError error) =>
747+
{
748+
Assert.IsNotNull(response.Result.Notices);
749+
Assert.IsNull(error);
750+
queryCollectionNoticesResponse = true;
751+
},
752+
projectId: projectId,
753+
collectionId: collectionId,
754+
naturalLanguageQuery: "warning"
755+
);
756+
757+
while (!queryCollectionNoticesResponse)
758+
yield return null;
759+
}
760+
#endregion
761+
762+
#region DeleteTrainingQuery
763+
//[UnityTest, Order(103)]
764+
public IEnumerator TestDeleteTrainingQuery()
765+
{
766+
Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to DeleteTrainingQuery...");
767+
768+
DocumentAccepted addDocumentResponse = null;
769+
string documentId = "";
770+
string queryId = "";
771+
772+
using (FileStream fs = File.OpenRead(addDocumentFile))
773+
{
774+
using (MemoryStream ms = new MemoryStream())
775+
{
776+
fs.CopyTo(ms);
777+
service.AddDocument(
778+
callback: (DetailedResponse<DocumentAccepted> response, IBMError error) =>
779+
{
780+
Log.Debug("DiscoveryServiceV1IntegrationTests", "AddDocument result: {0}", response.Response);
781+
addDocumentResponse = response.Result;
782+
documentId = addDocumentResponse.DocumentId;
783+
Assert.IsNotNull(addDocumentResponse);
784+
Assert.IsNotNull(documentId);
785+
Assert.IsNull(error);
786+
},
787+
projectId: projectId,
788+
collectionId: collectionId,
789+
file: ms,
790+
fileContentType: Utility.GetMimeType(Path.GetExtension(addDocumentFile)),
791+
filename: Path.GetFileName(addDocumentFile)
792+
);
793+
794+
while (addDocumentResponse == null)
795+
yield return null;
796+
}
797+
}
798+
799+
TrainingExample trainingExample = new TrainingExample()
800+
{
801+
CollectionId = collectionId,
802+
DocumentId = documentId,
803+
Relevance = 1L
804+
};
805+
TrainingQuery trainingQueryResponse = null;
806+
service.CreateTrainingQuery(
807+
callback: (DetailedResponse<TrainingQuery> response, IBMError error) =>
808+
{
809+
Log.Debug("DiscoveryServiceV2IntegrationTests", "CreateTrainingQuery result: {0}", response.Response);
810+
trainingQueryResponse = response.Result;
811+
queryId = trainingQueryResponse.QueryId;
812+
Assert.IsNotNull(trainingQueryResponse);
813+
Assert.IsNull(error);
814+
},
815+
projectId: projectId,
816+
examples: new List<TrainingExample>() { trainingExample },
817+
filter: "entities.text:IBM",
818+
naturalLanguageQuery: "This is an example of a query"
819+
);
820+
821+
while (trainingQueryResponse == null)
822+
yield return null;
823+
824+
bool deleteTrainingQueryResponse = false;
825+
826+
service.DeleteTrainingQuery(
827+
callback: (DetailedResponse<object> response, IBMError error) =>
828+
{
829+
Assert.IsNull(error);
830+
deleteTrainingQueryResponse = true;
831+
},
832+
projectId: projectId,
833+
queryId: queryId
834+
);
835+
836+
while (!deleteTrainingQueryResponse)
837+
yield return null;
838+
839+
DeleteDocumentResponse deleteDocumentResponse = null;
840+
service.DeleteDocument(
841+
callback: (DetailedResponse<DeleteDocumentResponse> response, IBMError error) =>
842+
{
843+
Log.Debug("DiscoveryServiceV2IntegrationTests", "DeleteDocument result: {0}", response.Response);
844+
deleteDocumentResponse = response.Result;
845+
Assert.IsNotNull(deleteDocumentResponse);
846+
Assert.IsNull(error);
847+
},
848+
projectId: projectId,
849+
collectionId: collectionId,
850+
documentId: documentId
851+
);
852+
853+
while (deleteDocumentResponse == null)
854+
yield return null;
855+
}
856+
#endregion
736857
}
737858
}

0 commit comments

Comments
 (0)