public void UpdateExample_Success() { string updatedExample = _createdExample + "-updated"; Console.WriteLine(string.Format("\nCalling UpdateExample({0}, {1}, {2}, {3})...", _createdWorkspaceId, _createdIntent, _createdExample, updatedExample)); UpdateExample example = new UpdateExample() { Text = updatedExample }; var result = conversation.UpdateExample(_createdWorkspaceId, _createdIntent, _createdExample, example); Assert.IsNotNull(result); if (result != null) { Console.WriteLine(string.Format("example: {0}", result.ExampleText)); _createdExample = updatedExample; } else { Console.WriteLine("Result is null."); } }
public Example AtualizarExe(String WorkId, String Int, String Exe, String NExe) { UpdateExample updatedExample = new UpdateExample() { Text = NExe }; var result = _assistant.UpdateExample(WorkId, Int, Exe, updatedExample); return(result); }
public Example UpdateExample(string workspaceId, string intent, string text, UpdateExample body) { try { var result = AssistantRepository.UpdateExample(workspaceId, intent, text, body); return(result); } catch (Exception ex) { Logger.Error("AssistantService.UpdateExample failed", this, ex); } return(null); }
public void UpdateExample() { #region UpdateExample UpdateExample request = new UpdateExample() { Text = "Update_SDK_NET" }; #endregion ConversationService service = new ConversationService(_userName, _password); service.Endpoint = _endpoint; var results = service.UpdateExample(_workspace, "greetings", "Test_SDK_NET", request); Assert.IsNotNull(results); }
private void UpdateCounterExample() { string updatedCounterExampleText = _createdCounterExampleText + "-updated"; Console.WriteLine(string.Format("\nCalling UpdateCounterExample({0}, {1})...", _createdWorkspaceId, updatedCounterExampleText)); UpdateExample example = new UpdateExample() { Text = updatedCounterExampleText }; var result = _conversation.UpdateCounterexample(_createdWorkspaceId, _createdCounterExampleText, example); if (result != null) { Console.WriteLine(string.Format("CounterExample name: {0}, created: {1}", result.Text, result.Created)); _createdCounterExampleText = updatedCounterExampleText; } else { Console.WriteLine("Result is null."); } }
public ExampleResponse UpdateCounterexample(string workspaceId, string text, UpdateExample body) { if (string.IsNullOrEmpty(workspaceId)) { throw new ArgumentNullException(nameof(workspaceId)); } if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException(nameof(text)); } if (body == null) { throw new ArgumentNullException(nameof(body)); } if (string.IsNullOrEmpty(VersionDate)) { throw new ArgumentNullException("versionDate cannot be null. Use 'CONVERSATION_VERSION_DATE_2017_05_26'"); } ExampleResponse result = null; try { result = this.Client.WithAuthentication(this.UserName, this.Password) .PostAsync($"{this.Endpoint}/v1/workspaces/{workspaceId}/counterexamples/{text}") .WithArgument("version", VersionDate) .WithBody <UpdateExample>(body) .As <ExampleResponse>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; string credentialsFilepath = "../sdk-credentials/credentials.json"; // Load credentials file if it exists. If it doesn't exist, don't run the tests. if (File.Exists(credentialsFilepath)) { result = File.ReadAllText(credentialsFilepath); } else { yield break; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.GetCredentialByname("assistant-sdk")[0].Credentials; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); _workspaceId = credential.WorkspaceId.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); _service = new Assistant(credentials); _service.VersionDate = _assistantVersionDate; // List Workspaces _service.ListWorkspaces(OnListWorkspaces, OnFail); while (!_listWorkspacesTested) { yield return(null); } // Create Workspace CreateWorkspace workspace = new CreateWorkspace() { Name = _createdWorkspaceName, Description = _createdWorkspaceDescription, Language = _createdWorkspaceLanguage, LearningOptOut = true }; _service.CreateWorkspace(OnCreateWorkspace, OnFail, workspace); while (!_createWorkspaceTested) { yield return(null); } // Get Workspace _service.GetWorkspace(OnGetWorkspace, OnFail, _createdWorkspaceId); while (!_getWorkspaceTested) { yield return(null); } // Update Workspace UpdateWorkspace updateWorkspace = new UpdateWorkspace() { Name = _createdWorkspaceName + "-updated", Description = _createdWorkspaceDescription + "-updated", Language = _createdWorkspaceLanguage }; _service.UpdateWorkspace(OnUpdateWorkspace, OnFail, _createdWorkspaceId, updateWorkspace); while (!_updateWorkspaceTested) { yield return(null); } // Message with customerID // Create customData object Dictionary <string, object> customData = new Dictionary <string, object>(); // Create a dictionary of custom headers Dictionary <string, string> customHeaders = new Dictionary <string, string>(); // Add to the header dictionary customHeaders.Add("X-Watson-Metadata", "customer_id=" + _unitySdkTestCustomerID); // Add the header dictionary to the custom data object customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders); Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("text", _inputString); MessageRequest messageRequest = new MessageRequest() { Input = input }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest, null, customData); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString0; MessageRequest messageRequest0 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest0); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString1; MessageRequest messageRequest1 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest1); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString2; MessageRequest messageRequest2 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest2); while (!_messageTested) { yield return(null); } // List Intents _service.ListIntents(OnListIntents, OnFail, _createdWorkspaceId); while (!_listIntentsTested) { yield return(null); } // Create Intent CreateIntent createIntent = new CreateIntent() { Intent = _createdIntent, Description = _createdIntentDescription }; _service.CreateIntent(OnCreateIntent, OnFail, _createdWorkspaceId, createIntent); while (!_createIntentTested) { yield return(null); } // Get Intent _service.GetIntent(OnGetIntent, OnFail, _createdWorkspaceId, _createdIntent); while (!_getIntentTested) { yield return(null); } // Update Intents string updatedIntent = _createdIntent + "-updated"; string updatedIntentDescription = _createdIntentDescription + "-updated"; UpdateIntent updateIntent = new UpdateIntent() { Intent = updatedIntent, Description = updatedIntentDescription }; _service.UpdateIntent(OnUpdateIntent, OnFail, _createdWorkspaceId, _createdIntent, updateIntent); while (!_updateIntentTested) { yield return(null); } // List Examples _service.ListExamples(OnListExamples, OnFail, _createdWorkspaceId, updatedIntent); while (!_listExamplesTested) { yield return(null); } // Create Examples CreateExample createExample = new CreateExample() { Text = _createdExample }; _service.CreateExample(OnCreateExample, OnFail, _createdWorkspaceId, updatedIntent, createExample); while (!_createExampleTested) { yield return(null); } // Get Example _service.GetExample(OnGetExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample); while (!_getExampleTested) { yield return(null); } // Update Examples string updatedExample = _createdExample + "-updated"; UpdateExample updateExample = new UpdateExample() { Text = updatedExample }; _service.UpdateExample(OnUpdateExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample, updateExample); while (!_updateExampleTested) { yield return(null); } // List Entities _service.ListEntities(OnListEntities, OnFail, _createdWorkspaceId); while (!_listEntitiesTested) { yield return(null); } // Create Entities CreateEntity entity = new CreateEntity() { Entity = _createdEntity, Description = _createdEntityDescription }; _service.CreateEntity(OnCreateEntity, OnFail, _createdWorkspaceId, entity); while (!_createEntityTested) { yield return(null); } // Get Entity _service.GetEntity(OnGetEntity, OnFail, _createdWorkspaceId, _createdEntity); while (!_getEntityTested) { yield return(null); } // Update Entities string updatedEntity = _createdEntity + "-updated"; string updatedEntityDescription = _createdEntityDescription + "-updated"; UpdateEntity updateEntity = new UpdateEntity() { Entity = updatedEntity, Description = updatedEntityDescription }; _service.UpdateEntity(OnUpdateEntity, OnFail, _createdWorkspaceId, _createdEntity, updateEntity); while (!_updateEntityTested) { yield return(null); } // List Values _service.ListValues(OnListValues, OnFail, _createdWorkspaceId, updatedEntity); while (!_listValuesTested) { yield return(null); } // Create Values CreateValue value = new CreateValue() { Value = _createdValue }; _service.CreateValue(OnCreateValue, OnFail, _createdWorkspaceId, updatedEntity, value); while (!_createValueTested) { yield return(null); } // Get Value _service.GetValue(OnGetValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue); while (!_getValueTested) { yield return(null); } // Update Values string updatedValue = _createdValue + "-updated"; UpdateValue updateValue = new UpdateValue() { Value = updatedValue }; _service.UpdateValue(OnUpdateValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue, updateValue); while (!_updateValueTested) { yield return(null); } // List Synonyms _service.ListSynonyms(OnListSynonyms, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_listSynonymsTested) { yield return(null); } // Create Synonyms CreateSynonym synonym = new CreateSynonym() { Synonym = _createdSynonym }; _service.CreateSynonym(OnCreateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, synonym); while (!_createSynonymTested) { yield return(null); } // Get Synonym _service.GetSynonym(OnGetSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym); while (!_getSynonymTested) { yield return(null); } // Update Synonyms string updatedSynonym = _createdSynonym + "-updated"; UpdateSynonym updateSynonym = new UpdateSynonym() { Synonym = updatedSynonym }; _service.UpdateSynonym(OnUpdateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym, updateSynonym); while (!_updateSynonymTested) { yield return(null); } // List Dialog Nodes _service.ListDialogNodes(OnListDialogNodes, OnFail, _createdWorkspaceId); while (!_listDialogNodesTested) { yield return(null); } // Create Dialog Nodes CreateDialogNode createDialogNode = new CreateDialogNode() { DialogNode = _dialogNodeName, Description = _dialogNodeDesc }; _service.CreateDialogNode(OnCreateDialogNode, OnFail, _createdWorkspaceId, createDialogNode); while (!_createDialogNodeTested) { yield return(null); } // Get Dialog Node _service.GetDialogNode(OnGetDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName); while (!_getDialogNodeTested) { yield return(null); } // Update Dialog Nodes string updatedDialogNodeName = _dialogNodeName + "_updated"; string updatedDialogNodeDescription = _dialogNodeDesc + "_updated"; UpdateDialogNode updateDialogNode = new UpdateDialogNode() { DialogNode = updatedDialogNodeName, Description = updatedDialogNodeDescription }; _service.UpdateDialogNode(OnUpdateDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName, updateDialogNode); while (!_updateDialogNodeTested) { yield return(null); } // List Logs In Workspace _service.ListLogs(OnListLogs, OnFail, _createdWorkspaceId); while (!_listLogsInWorkspaceTested) { yield return(null); } // List All Logs var filter = "(language::en,request.context.metadata.deployment::deployment_1)"; _service.ListAllLogs(OnListAllLogs, OnFail, filter); while (!_listAllLogsTested) { yield return(null); } // List Counterexamples _service.ListCounterexamples(OnListCounterexamples, OnFail, _createdWorkspaceId); while (!_listCounterexamplesTested) { yield return(null); } // Create Counterexamples CreateCounterexample example = new CreateCounterexample() { Text = _createdCounterExampleText }; _service.CreateCounterexample(OnCreateCounterexample, OnFail, _createdWorkspaceId, example); while (!_createCounterexampleTested) { yield return(null); } // Get Counterexample _service.GetCounterexample(OnGetCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText); while (!_getCounterexampleTested) { yield return(null); } // Update Counterexamples string updatedCounterExampleText = _createdCounterExampleText + "-updated"; UpdateCounterexample updateCounterExample = new UpdateCounterexample() { Text = updatedCounterExampleText }; _service.UpdateCounterexample(OnUpdateCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText, updateCounterExample); while (!_updateCounterexampleTested) { yield return(null); } // Delete Counterexample _service.DeleteCounterexample(OnDeleteCounterexample, OnFail, _createdWorkspaceId, updatedCounterExampleText); while (!_deleteCounterexampleTested) { yield return(null); } // Delete Dialog Node _service.DeleteDialogNode(OnDeleteDialogNode, OnFail, _createdWorkspaceId, updatedDialogNodeName); while (!_deleteDialogNodeTested) { yield return(null); } // Delete Synonym _service.DeleteSynonym(OnDeleteSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, updatedSynonym); while (!_deleteSynonymTested) { yield return(null); } // Delete Value _service.DeleteValue(OnDeleteValue, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_deleteValueTested) { yield return(null); } // Delete Entity _service.DeleteEntity(OnDeleteEntity, OnFail, _createdWorkspaceId, updatedEntity); while (!_deleteEntityTested) { yield return(null); } // Delete Example _service.DeleteExample(OnDeleteExample, OnFail, _createdWorkspaceId, updatedIntent, updatedExample); while (!_deleteExampleTested) { yield return(null); } // Delete Intent _service.DeleteIntent(OnDeleteIntent, OnFail, _createdWorkspaceId, updatedIntent); while (!_deleteIntentTested) { yield return(null); } // Delete Workspace _service.DeleteWorkspace(OnDeleteWorkspace, OnFail, _createdWorkspaceId); while (!_deleteWorkspaceTested) { yield return(null); } // Delete User Data _service.DeleteUserData(OnDeleteUserData, OnFail, _unitySdkTestCustomerID); while (!_deleteUserDataTested) { yield return(null); } Log.Debug("TestAssistant.RunTest()", "Assistant examples complete."); yield break; }
private IEnumerator Examples() { // List Workspaces _service.ListWorkspaces(OnListWorkspaces, OnFail); while (!_listWorkspacesTested) { yield return(null); } // Create Workspace CreateWorkspace workspace = new CreateWorkspace() { Name = _createdWorkspaceName, Description = _createdWorkspaceDescription, Language = _createdWorkspaceLanguage, LearningOptOut = true }; _service.CreateWorkspace(OnCreateWorkspace, OnFail, workspace); while (!_createWorkspaceTested) { yield return(null); } // Get Workspace _service.GetWorkspace(OnGetWorkspace, OnFail, _createdWorkspaceId); while (!_getWorkspaceTested) { yield return(null); } // Update Workspace UpdateWorkspace updateWorkspace = new UpdateWorkspace() { Name = _createdWorkspaceName + "-updated", Description = _createdWorkspaceDescription + "-updated", Language = _createdWorkspaceLanguage }; _service.UpdateWorkspace(OnUpdateWorkspace, OnFail, _createdWorkspaceId, updateWorkspace); while (!_updateWorkspaceTested) { yield return(null); } // Message Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("text", _inputString); MessageRequest messageRequest = new MessageRequest() { Input = input }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString0; MessageRequest messageRequest0 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest0); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString1; MessageRequest messageRequest1 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest1); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString2; MessageRequest messageRequest2 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest2); while (!_messageTested) { yield return(null); } // List Intents _service.ListIntents(OnListIntents, OnFail, _createdWorkspaceId); while (!_listIntentsTested) { yield return(null); } // Create Intent CreateIntent createIntent = new CreateIntent() { Intent = _createdIntent, Description = _createdIntentDescription }; _service.CreateIntent(OnCreateIntent, OnFail, _createdWorkspaceId, createIntent); while (!_createIntentTested) { yield return(null); } // Get Intent _service.GetIntent(OnGetIntent, OnFail, _createdWorkspaceId, _createdIntent); while (!_getIntentTested) { yield return(null); } // Update Intents string updatedIntent = _createdIntent + "-updated"; string updatedIntentDescription = _createdIntentDescription + "-updated"; UpdateIntent updateIntent = new UpdateIntent() { Intent = updatedIntent, Description = updatedIntentDescription }; _service.UpdateIntent(OnUpdateIntent, OnFail, _createdWorkspaceId, _createdIntent, updateIntent); while (!_updateIntentTested) { yield return(null); } // List Examples _service.ListExamples(OnListExamples, OnFail, _createdWorkspaceId, updatedIntent); while (!_listExamplesTested) { yield return(null); } // Create Examples CreateExample createExample = new CreateExample() { Text = _createdExample }; _service.CreateExample(OnCreateExample, OnFail, _createdWorkspaceId, updatedIntent, createExample); while (!_createExampleTested) { yield return(null); } // Get Example _service.GetExample(OnGetExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample); while (!_getExampleTested) { yield return(null); } // Update Examples string updatedExample = _createdExample + "-updated"; UpdateExample updateExample = new UpdateExample() { Text = updatedExample }; _service.UpdateExample(OnUpdateExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample, updateExample); while (!_updateExampleTested) { yield return(null); } // List Entities _service.ListEntities(OnListEntities, OnFail, _createdWorkspaceId); while (!_listEntitiesTested) { yield return(null); } // Create Entities CreateEntity entity = new CreateEntity() { Entity = _createdEntity, Description = _createdEntityDescription }; _service.CreateEntity(OnCreateEntity, OnFail, _createdWorkspaceId, entity); while (!_createEntityTested) { yield return(null); } // Get Entity _service.GetEntity(OnGetEntity, OnFail, _createdWorkspaceId, _createdEntity); while (!_getEntityTested) { yield return(null); } // Update Entities string updatedEntity = _createdEntity + "-updated"; string updatedEntityDescription = _createdEntityDescription + "-updated"; UpdateEntity updateEntity = new UpdateEntity() { Entity = updatedEntity, Description = updatedEntityDescription }; _service.UpdateEntity(OnUpdateEntity, OnFail, _createdWorkspaceId, _createdEntity, updateEntity); while (!_updateEntityTested) { yield return(null); } // List Values _service.ListValues(OnListValues, OnFail, _createdWorkspaceId, updatedEntity); while (!_listValuesTested) { yield return(null); } // Create Values CreateValue value = new CreateValue() { Value = _createdValue }; _service.CreateValue(OnCreateValue, OnFail, _createdWorkspaceId, updatedEntity, value); while (!_createValueTested) { yield return(null); } // Get Value _service.GetValue(OnGetValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue); while (!_getValueTested) { yield return(null); } // Update Values string updatedValue = _createdValue + "-updated"; UpdateValue updateValue = new UpdateValue() { Value = updatedValue }; _service.UpdateValue(OnUpdateValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue, updateValue); while (!_updateValueTested) { yield return(null); } // List Synonyms _service.ListSynonyms(OnListSynonyms, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_listSynonymsTested) { yield return(null); } // Create Synonyms CreateSynonym synonym = new CreateSynonym() { Synonym = _createdSynonym }; _service.CreateSynonym(OnCreateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, synonym); while (!_createSynonymTested) { yield return(null); } // Get Synonym _service.GetSynonym(OnGetSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym); while (!_getSynonymTested) { yield return(null); } // Update Synonyms string updatedSynonym = _createdSynonym + "-updated"; UpdateSynonym updateSynonym = new UpdateSynonym() { Synonym = updatedSynonym }; _service.UpdateSynonym(OnUpdateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym, updateSynonym); while (!_updateSynonymTested) { yield return(null); } // List Dialog Nodes _service.ListDialogNodes(OnListDialogNodes, OnFail, _createdWorkspaceId); while (!_listDialogNodesTested) { yield return(null); } // Create Dialog Nodes CreateDialogNode createDialogNode = new CreateDialogNode() { DialogNode = _dialogNodeName, Description = _dialogNodeDesc }; _service.CreateDialogNode(OnCreateDialogNode, OnFail, _createdWorkspaceId, createDialogNode); while (!_createDialogNodeTested) { yield return(null); } // Get Dialog Node _service.GetDialogNode(OnGetDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName); while (!_getDialogNodeTested) { yield return(null); } // Update Dialog Nodes string updatedDialogNodeName = _dialogNodeName + "_updated"; string updatedDialogNodeDescription = _dialogNodeDesc + "_updated"; UpdateDialogNode updateDialogNode = new UpdateDialogNode() { DialogNode = updatedDialogNodeName, Description = updatedDialogNodeDescription }; _service.UpdateDialogNode(OnUpdateDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName, updateDialogNode); while (!_updateDialogNodeTested) { yield return(null); } // List Logs In Workspace _service.ListLogs(OnListLogs, OnFail, _createdWorkspaceId); while (!_listLogsInWorkspaceTested) { yield return(null); } // List All Logs var filter = "(language::en,request.context.metadata.deployment::deployment_1)"; _service.ListAllLogs(OnListAllLogs, OnFail, filter); while (!_listAllLogsTested) { yield return(null); } // List Counterexamples _service.ListCounterexamples(OnListCounterexamples, OnFail, _createdWorkspaceId); while (!_listCounterexamplesTested) { yield return(null); } // Create Counterexamples CreateCounterexample example = new CreateCounterexample() { Text = _createdCounterExampleText }; _service.CreateCounterexample(OnCreateCounterexample, OnFail, _createdWorkspaceId, example); while (!_createCounterexampleTested) { yield return(null); } // Get Counterexample _service.GetCounterexample(OnGetCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText); while (!_getCounterexampleTested) { yield return(null); } // Update Counterexamples string updatedCounterExampleText = _createdCounterExampleText + "-updated"; UpdateCounterexample updateCounterExample = new UpdateCounterexample() { Text = updatedCounterExampleText }; _service.UpdateCounterexample(OnUpdateCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText, updateCounterExample); while (!_updateCounterexampleTested) { yield return(null); } // Delete Counterexample _service.DeleteCounterexample(OnDeleteCounterexample, OnFail, _createdWorkspaceId, updatedCounterExampleText); while (!_deleteCounterexampleTested) { yield return(null); } // Delete Dialog Node _service.DeleteDialogNode(OnDeleteDialogNode, OnFail, _createdWorkspaceId, updatedDialogNodeName); while (!_deleteDialogNodeTested) { yield return(null); } // Delete Synonym _service.DeleteSynonym(OnDeleteSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, updatedSynonym); while (!_deleteSynonymTested) { yield return(null); } // Delete Value _service.DeleteValue(OnDeleteValue, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_deleteValueTested) { yield return(null); } // Delete Entity _service.DeleteEntity(OnDeleteEntity, OnFail, _createdWorkspaceId, updatedEntity); while (!_deleteEntityTested) { yield return(null); } // Delete Example _service.DeleteExample(OnDeleteExample, OnFail, _createdWorkspaceId, updatedIntent, updatedExample); while (!_deleteExampleTested) { yield return(null); } // Delete Intent _service.DeleteIntent(OnDeleteIntent, OnFail, _createdWorkspaceId, updatedIntent); while (!_deleteIntentTested) { yield return(null); } // Delete Workspace _service.DeleteWorkspace(OnDeleteWorkspace, OnFail, _createdWorkspaceId); while (!_deleteWorkspaceTested) { yield return(null); } Log.Debug("TestAssistant.RunTest()", "Assistant examples complete."); yield break; }
public ExampleResponse UpdateExample(string workspaceId, string intent, string text, UpdateExample request) { ExampleResponse result = null; if (string.IsNullOrEmpty(workspaceId)) { throw new ArgumentNullException("parameter: workspaceId"); } if (string.IsNullOrEmpty(intent)) { throw new ArgumentNullException("parameter: intent"); } if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("parameter: text"); } if (request == null) { throw new ArgumentNullException("parameter: request"); } try { result = this.Client.WithAuthentication(this.UserName, this.Password) .PostAsync($"{this.Endpoint}{PATH_CONVERSATION}/{workspaceId}/intents/{intent}/examples/{text}") .WithArgument("version", VERSION_DATE_2017_05_26) .WithHeader("accept", HttpMediaType.TEXT_HTML) .WithBody <UpdateExample>(request, MediaTypeHeaderValue.Parse(HttpMediaType.APPLICATION_JSON)) .As <ExampleResponse>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL"); var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME"); var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD"); using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword)) { while (!simpleGet.IsComplete) { yield return(null); } result = simpleGet.Result; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["conversation"]; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); //_workspaceId = credential.WorkspaceId.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); _service = new Assistant(credentials); _service.VersionDate = _assistantVersionDate; // List Workspaces _service.ListWorkspaces(OnListWorkspaces, OnFail); while (!_listWorkspacesTested) { yield return(null); } // Create Workspace CreateWorkspace workspace = new CreateWorkspace() { Name = _createdWorkspaceName, Description = _createdWorkspaceDescription, Language = _createdWorkspaceLanguage, LearningOptOut = true }; _service.CreateWorkspace(OnCreateWorkspace, OnFail, workspace); while (!_createWorkspaceTested) { yield return(null); } // Get Workspace _service.GetWorkspace(OnGetWorkspace, OnFail, _createdWorkspaceId); while (!_getWorkspaceTested) { yield return(null); } // Update Workspace UpdateWorkspace updateWorkspace = new UpdateWorkspace() { Name = _createdWorkspaceName + "-updated", Description = _createdWorkspaceDescription + "-updated", Language = _createdWorkspaceLanguage }; _service.UpdateWorkspace(OnUpdateWorkspace, OnFail, _createdWorkspaceId, updateWorkspace); while (!_updateWorkspaceTested) { yield return(null); } // Message Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("text", _inputString); MessageRequest messageRequest = new MessageRequest() { Input = input, AlternateIntents = true }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest); while (!_messageTested) { yield return(null); } // List Intents _service.ListIntents(OnListIntents, OnFail, _createdWorkspaceId); while (!_listIntentsTested) { yield return(null); } // Create Intent CreateIntent createIntent = new CreateIntent() { Intent = _createdIntent, Description = _createdIntentDescription }; _service.CreateIntent(OnCreateIntent, OnFail, _createdWorkspaceId, createIntent); while (!_createIntentTested) { yield return(null); } // Get Intent _service.GetIntent(OnGetIntent, OnFail, _createdWorkspaceId, _createdIntent); while (!_getIntentTested) { yield return(null); } // Update Intents string updatedIntent = _createdIntent + "-updated"; string updatedIntentDescription = _createdIntentDescription + "-updated"; UpdateIntent updateIntent = new UpdateIntent() { Intent = updatedIntent, Description = updatedIntentDescription }; _service.UpdateIntent(OnUpdateIntent, OnFail, _createdWorkspaceId, _createdIntent, updateIntent); while (!_updateIntentTested) { yield return(null); } // List Examples _service.ListExamples(OnListExamples, OnFail, _createdWorkspaceId, updatedIntent); while (!_listExamplesTested) { yield return(null); } // Create Examples CreateExample createExample = new CreateExample() { Text = _createdExample }; _service.CreateExample(OnCreateExample, OnFail, _createdWorkspaceId, updatedIntent, createExample); while (!_createExampleTested) { yield return(null); } // Get Example _service.GetExample(OnGetExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample); while (!_getExampleTested) { yield return(null); } // Update Examples string updatedExample = _createdExample + "-updated"; UpdateExample updateExample = new UpdateExample() { Text = updatedExample }; _service.UpdateExample(OnUpdateExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample, updateExample); while (!_updateExampleTested) { yield return(null); } // List Entities _service.ListEntities(OnListEntities, OnFail, _createdWorkspaceId); while (!_listEntitiesTested) { yield return(null); } // Create Entities CreateEntity entity = new CreateEntity() { Entity = _createdEntity, Description = _createdEntityDescription }; _service.CreateEntity(OnCreateEntity, OnFail, _createdWorkspaceId, entity); while (!_createEntityTested) { yield return(null); } // Get Entity _service.GetEntity(OnGetEntity, OnFail, _createdWorkspaceId, _createdEntity); while (!_getEntityTested) { yield return(null); } // Update Entities string updatedEntity = _createdEntity + "-updated"; string updatedEntityDescription = _createdEntityDescription + "-updated"; UpdateEntity updateEntity = new UpdateEntity() { Entity = updatedEntity, Description = updatedEntityDescription }; _service.UpdateEntity(OnUpdateEntity, OnFail, _createdWorkspaceId, _createdEntity, updateEntity); while (!_updateEntityTested) { yield return(null); } // List Values _service.ListValues(OnListValues, OnFail, _createdWorkspaceId, updatedEntity); while (!_listValuesTested) { yield return(null); } // Create Values CreateValue value = new CreateValue() { Value = _createdValue }; _service.CreateValue(OnCreateValue, OnFail, _createdWorkspaceId, updatedEntity, value); while (!_createValueTested) { yield return(null); } // Get Value _service.GetValue(OnGetValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue); while (!_getValueTested) { yield return(null); } // Update Values string updatedValue = _createdValue + "-updated"; UpdateValue updateValue = new UpdateValue() { Value = updatedValue }; _service.UpdateValue(OnUpdateValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue, updateValue); while (!_updateValueTested) { yield return(null); } // List Synonyms _service.ListSynonyms(OnListSynonyms, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_listSynonymsTested) { yield return(null); } // Create Synonyms CreateSynonym synonym = new CreateSynonym() { Synonym = _createdSynonym }; _service.CreateSynonym(OnCreateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, synonym); while (!_createSynonymTested) { yield return(null); } // Get Synonym _service.GetSynonym(OnGetSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym); while (!_getSynonymTested) { yield return(null); } // Update Synonyms string updatedSynonym = _createdSynonym + "-updated"; UpdateSynonym updateSynonym = new UpdateSynonym() { Synonym = updatedSynonym }; _service.UpdateSynonym(OnUpdateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym, updateSynonym); while (!_updateSynonymTested) { yield return(null); } // List Dialog Nodes _service.ListDialogNodes(OnListDialogNodes, OnFail, _createdWorkspaceId); while (!_listDialogNodesTested) { yield return(null); } // Create Dialog Nodes CreateDialogNode createDialogNode = new CreateDialogNode() { DialogNode = _dialogNodeName, Description = _dialogNodeDesc }; _service.CreateDialogNode(OnCreateDialogNode, OnFail, _createdWorkspaceId, createDialogNode); while (!_createDialogNodeTested) { yield return(null); } // Get Dialog Node _service.GetDialogNode(OnGetDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName); while (!_getDialogNodeTested) { yield return(null); } // Update Dialog Nodes string updatedDialogNodeName = _dialogNodeName + "_updated"; string updatedDialogNodeDescription = _dialogNodeDesc + "_updated"; UpdateDialogNode updateDialogNode = new UpdateDialogNode() { DialogNode = updatedDialogNodeName, Description = updatedDialogNodeDescription }; _service.UpdateDialogNode(OnUpdateDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName, updateDialogNode); while (!_updateDialogNodeTested) { yield return(null); } // List Logs In Workspace _service.ListLogs(OnListLogs, OnFail, _createdWorkspaceId); while (!_listLogsInWorkspaceTested) { yield return(null); } // List All Logs var filter = "(language::en,request.context.metadata.deployment::deployment_1)"; _service.ListAllLogs(OnListAllLogs, OnFail, filter); while (!_listAllLogsTested) { yield return(null); } // List Counterexamples _service.ListCounterexamples(OnListCounterexamples, OnFail, _createdWorkspaceId); while (!_listCounterexamplesTested) { yield return(null); } // Create Counterexamples CreateCounterexample example = new CreateCounterexample() { Text = _createdCounterExampleText }; _service.CreateCounterexample(OnCreateCounterexample, OnFail, _createdWorkspaceId, example); while (!_createCounterexampleTested) { yield return(null); } // Get Counterexample _service.GetCounterexample(OnGetCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText); while (!_getCounterexampleTested) { yield return(null); } // Update Counterexamples string updatedCounterExampleText = _createdCounterExampleText + "-updated"; UpdateCounterexample updateCounterExample = new UpdateCounterexample() { Text = updatedCounterExampleText }; _service.UpdateCounterexample(OnUpdateCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText, updateCounterExample); while (!_updateCounterexampleTested) { yield return(null); } // Delete Counterexample _service.DeleteCounterexample(OnDeleteCounterexample, OnFail, _createdWorkspaceId, updatedCounterExampleText); while (!_deleteCounterexampleTested) { yield return(null); } // Delete Dialog Node _service.DeleteDialogNode(OnDeleteDialogNode, OnFail, _createdWorkspaceId, updatedDialogNodeName); while (!_deleteDialogNodeTested) { yield return(null); } // Delete Synonym _service.DeleteSynonym(OnDeleteSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, updatedSynonym); while (!_deleteSynonymTested) { yield return(null); } // Delete Value _service.DeleteValue(OnDeleteValue, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_deleteValueTested) { yield return(null); } // Delete Entity _service.DeleteEntity(OnDeleteEntity, OnFail, _createdWorkspaceId, updatedEntity); while (!_deleteEntityTested) { yield return(null); } // Delete Example _service.DeleteExample(OnDeleteExample, OnFail, _createdWorkspaceId, updatedIntent, updatedExample); while (!_deleteExampleTested) { yield return(null); } // Delete Intent _service.DeleteIntent(OnDeleteIntent, OnFail, _createdWorkspaceId, updatedIntent); while (!_deleteIntentTested) { yield return(null); } // Delete Workspace _service.DeleteWorkspace(OnDeleteWorkspace, OnFail, _createdWorkspaceId); while (!_deleteWorkspaceTested) { yield return(null); } Log.Debug("TestAssistant.RunTest()", "Assistant examples complete."); yield break; }