private void OnAddDocument(DocumentAccepted resp, Dictionary <string, object> customData) { Log.Debug("TestDiscovery.OnAddDocument()", "Discovery - Add document Response: {0}", customData["json"].ToString()); _createdDocumentID = resp.document_id; Test(resp != null); _addDocumentTested = true; }
public IEnumerator TestAddDocument() { Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to AddDocument..."); DocumentAccepted addDocumentResponse = null; using (FileStream fs = File.OpenRead(addDocumentFile)) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); service.AddDocument( callback: (DetailedResponse <DocumentAccepted> response, IBMError error) => { Log.Debug("DiscoveryServiceV1IntegrationTests", "AddDocument result: {0}", response.Response); addDocumentResponse = response.Result; documentId = addDocumentResponse.DocumentId; Assert.IsNotNull(addDocumentResponse); Assert.IsNotNull(documentId); Assert.IsNull(error); }, projectId: projectId, collectionId: collectionId, file: ms, fileContentType: Utility.GetMimeType(Path.GetExtension(addDocumentFile)), filename: Path.GetFileName(addDocumentFile) ); while (addDocumentResponse == null) { yield return(null); } } } }
private void OnAddDocument(DocumentAccepted resp, string data) { Log.Debug("ExampleDiscoveryV1", "Discovery - Add document Response: {0}", data); _createdDocumentID = resp.document_id; Test(resp != null); _addDocumentTested = true; }
public DocumentAccepted UpdateDocument(string environmentId, string collectionId, string documentId, string configurationId = null, System.IO.Stream file = null, string metadata = null, string configuration = null) { if (string.IsNullOrEmpty(environmentId)) { throw new ArgumentNullException(nameof(environmentId)); } if (string.IsNullOrEmpty(collectionId)) { throw new ArgumentNullException(nameof(collectionId)); } if (string.IsNullOrEmpty(documentId)) { throw new ArgumentNullException(nameof(documentId)); } if (string.IsNullOrEmpty(VersionDate)) { throw new ArgumentNullException("versionDate cannot be null. Use 'DISCOVERY_VERSION_DATE_2016_12_01'"); } DocumentAccepted result = null; try { var formData = new MultipartFormDataContent(); if (file != null) { var fileContent = new ByteArrayContent((file as Stream).ReadAllBytes()); formData.Add(fileContent, "file"); } if (metadata != null) { var metadataContent = new StringContent(metadata, Encoding.UTF8, HttpMediaType.TEXT_PLAIN); formData.Add(metadataContent, "metadata"); } if (configuration != null) { var configurationContent = new StringContent(configuration, Encoding.UTF8, HttpMediaType.TEXT_PLAIN); formData.Add(configurationContent, "configuration"); } result = this.Client.WithAuthentication(this.UserName, this.Password) .PostAsync($"{this.Endpoint}/v1/environments/{environmentId}/collections/{collectionId}/documents/{documentId}") .WithArgument("version", VersionDate) .WithArgument("configuration_id", configurationId) .WithBodyContent(formData) .As <DocumentAccepted>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
private void OnUpdateDocument(DocumentAccepted resp, string data) { if (resp != null) { Log.Debug("ExampleDiscoveryV1", "Updated Document {0} {1}", resp.document_id, resp.status); TestQuery(); } else { Log.Debug("ExampleDiscoveryV1", "resp is null, {0}", data); } }
private void OnAddDocument(DocumentAccepted resp, string data) { if (resp != null) { Log.Debug("ExampleDiscoveryV1", "Added Document {0} {1}", resp.document_id, resp.status); m_CreatedDocumentID = resp.document_id; TestGetDocument(); } else { Log.Debug("ExampleDiscoveryV1", "resp is null, {0}", data); } }
public IEnumerator TestUpdateDocument() { Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to UpdateDocument..."); DocumentAccepted updateDocumentResponse = null; service.UpdateDocument( callback: (DetailedResponse <DocumentAccepted> response, IBMError error) => { Log.Debug("DiscoveryServiceV2IntegrationTests", "UpdateDocument result: {0}", response.Response); updateDocumentResponse = response.Result; Assert.IsNotNull(updateDocumentResponse); Assert.IsNull(error); }, projectId: projectId, collectionId: collectionId, documentId: documentId, filename: "update-file-name" ); while (updateDocumentResponse == null) { yield return(null); } }
private void OnUpdateDocument(DocumentAccepted resp, Dictionary <string, object> customData) { Log.Debug("TestDiscovery.OnUpdateDocument()", "Discovery - Update document Response: {0}", customData["json"].ToString()); Test(resp != null); _updateDocumentTested = true; }
//[UnityTest, Order(103)] public IEnumerator TestDeleteTrainingQuery() { Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to DeleteTrainingQuery..."); DocumentAccepted addDocumentResponse = null; string documentId = ""; string queryId = ""; using (FileStream fs = File.OpenRead(addDocumentFile)) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); service.AddDocument( callback: (DetailedResponse <DocumentAccepted> response, IBMError error) => { Log.Debug("DiscoveryServiceV1IntegrationTests", "AddDocument result: {0}", response.Response); addDocumentResponse = response.Result; documentId = addDocumentResponse.DocumentId; Assert.IsNotNull(addDocumentResponse); Assert.IsNotNull(documentId); Assert.IsNull(error); }, projectId: projectId, collectionId: collectionId, file: ms, fileContentType: Utility.GetMimeType(Path.GetExtension(addDocumentFile)), filename: Path.GetFileName(addDocumentFile) ); while (addDocumentResponse == null) { yield return(null); } } } TrainingExample trainingExample = new TrainingExample() { CollectionId = collectionId, DocumentId = documentId, Relevance = 1L }; TrainingQuery trainingQueryResponse = null; service.CreateTrainingQuery( callback: (DetailedResponse <TrainingQuery> response, IBMError error) => { Log.Debug("DiscoveryServiceV2IntegrationTests", "CreateTrainingQuery result: {0}", response.Response); trainingQueryResponse = response.Result; queryId = trainingQueryResponse.QueryId; Assert.IsNotNull(trainingQueryResponse); Assert.IsNull(error); }, projectId: projectId, examples: new List <TrainingExample>() { trainingExample }, filter: "entities.text:IBM", naturalLanguageQuery: "This is an example of a query" ); while (trainingQueryResponse == null) { yield return(null); } bool deleteTrainingQueryResponse = false; service.DeleteTrainingQuery( callback: (DetailedResponse <object> response, IBMError error) => { Assert.IsNull(error); deleteTrainingQueryResponse = true; }, projectId: projectId, queryId: queryId ); while (!deleteTrainingQueryResponse) { yield return(null); } DeleteDocumentResponse deleteDocumentResponse = null; service.DeleteDocument( callback: (DetailedResponse <DeleteDocumentResponse> response, IBMError error) => { Log.Debug("DiscoveryServiceV2IntegrationTests", "DeleteDocument result: {0}", response.Response); deleteDocumentResponse = response.Result; Assert.IsNotNull(deleteDocumentResponse); Assert.IsNull(error); }, projectId: projectId, collectionId: collectionId, documentId: documentId ); while (deleteDocumentResponse == null) { yield return(null); } }
private void OnUpdateDocument(DocumentAccepted resp, string data) { Log.Debug("ExampleDiscoveryV1", "Discovery - Update document Response: {0}", data); Test(resp != null); _updateDocumentTested = true; }