Ejemplo n.º 1
0
        // TODO: Make this test Sync once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696
        public async Task KnowledgeSources()
        {
            QuestionAnsweringProjectsClient client = Client;

            #region Snippet:QuestionAnsweringProjectsClient_UpdateSources_UpdateSample
            // Set request content parameters for updating our new project's sources
            string sourceUri       = "{KnowledgeSourceUri}";
            string testProjectName = "{ProjectName}";
#if !SNIPPET
            sourceUri       = "https://www.microsoft.com/en-in/software-download/faq";
            testProjectName = CreateTestProjectName();
            CreateProject(testProjectName);
#endif
            RequestContent updateSourcesRequestContent = RequestContent.Create(
                new[] {
                new {
                    op    = "add",
                    value = new
                    {
                        displayName          = "MicrosoftFAQ",
                        source               = sourceUri,
                        sourceUri            = sourceUri,
                        sourceKind           = "url",
                        contentStructureKind = "unstructured",
                        refresh              = false
                    }
                }
            });

#if SNIPPET
            Operation <BinaryData> updateSourcesOperation = client.UpdateSources(waitForCompletion: false, testProjectName, updateSourcesRequestContent);
            updateSourcesOperation.WaitForCompletion();
#else
            // TODO: Remove this region once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696
            Operation <BinaryData> updateSourcesOperation = InstrumentOperation(client.UpdateSources(WaitUntil.Started, testProjectName, updateSourcesRequestContent));
            await updateSourcesOperation.WaitForCompletionAsync();
#endif

            // Knowledge Sources can be retrieved as follows
            Pageable <BinaryData> sources = client.GetSources(testProjectName);
            Console.WriteLine("Sources: ");
            foreach (BinaryData source in sources)
            {
                Console.WriteLine(source);
            }
            #endregion

            Assert.True(updateSourcesOperation.HasCompleted);
            Assert.That(sources.Any(source => source.ToString().Contains(sourceUri)));

            #region Snippet:QuestionAnsweringProjectsClient_UpdateQnas

            string question = "{NewQuestion}";
            string answer   = "{NewAnswer}";
#if !SNIPPET
            question = "What is the easiest way to use azure services in my .NET project?";
            answer   = "Using Microsoft's Azure SDKs";
#endif
            RequestContent updateQnasRequestContent = RequestContent.Create(
                new[] {
                new {
                    op    = "add",
                    value = new
                    {
                        questions = new[]
                        {
                            question
                        },
                        answer = answer
                    }
                }
            });

            Operation <BinaryData> updateQnasOperation = Client.UpdateQnas(WaitUntil.Completed, testProjectName, updateQnasRequestContent);

            // QnAs can be retrieved as follows
            Pageable <BinaryData> qnas = Client.GetQnas(testProjectName);

            Console.WriteLine("Qnas: ");
            foreach (var qna in qnas)
            {
                Console.WriteLine(qna);
            }
            #endregion

            Assert.True(updateQnasOperation.HasCompleted);
            Assert.AreEqual(200, updateQnasOperation.GetRawResponse().Status);
            Assert.That(qnas.Any(qna => qna.ToString().Contains(question)));
            Assert.That(qnas.Any(qna => qna.ToString().Contains(answer)));

            #region Snippet:QuestionAnsweringProjectsClient_UpdateSynonyms
            RequestContent updateSynonymsRequestContent = RequestContent.Create(
                new
            {
                value = new[] {
                    new  {
                        alterations = new[]
                        {
                            "qnamaker",
                            "qna maker",
                        }
                    },
                    new  {
                        alterations = new[]
                        {
                            "qna",
                            "question and answer",
                        }
                    }
                }
            });

            Response updateSynonymsResponse = Client.UpdateSynonyms(testProjectName, updateSynonymsRequestContent);

            // Synonyms can be retrieved as follows
            Pageable <BinaryData> synonyms = Client.GetSynonyms(testProjectName);

            Console.WriteLine("Synonyms: ");
            foreach (BinaryData synonym in synonyms)
            {
                Console.WriteLine(synonym);
            }
            #endregion

            Assert.AreEqual(204, updateSynonymsResponse.Status);
            Assert.That(synonyms.Any(synonym => synonym.ToString().Contains("qnamaker")));
            Assert.That(synonyms.Any(synonym => synonym.ToString().Contains("qna maker")));

            #region Snippet:QuestionAnsweringProjectsClient_AddFeedback
            RequestContent addFeedbackRequestContent = RequestContent.Create(
                new
            {
                records = new[]
                {
                    new
                    {
                        userId       = "userX",
                        userQuestion = "{Follow-up Question}",
                        qnaId        = 1
                    }
                }
            });

            Response addFeedbackResponse = Client.AddFeedback(testProjectName, addFeedbackRequestContent);
            #endregion

            Assert.AreEqual(204, addFeedbackResponse.Status);

            DeleteProject(testProjectName);
        }
Ejemplo n.º 2
0
        // TODO: Make this test Sync once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696
        public async Task CreateAndDeploy()
        {
            QuestionAnsweringProjectsClient client = Client;

            #region Snippet:QuestionAnsweringProjectsClient_CreateProject
            // Set project name and request content parameters
            string newProjectName = "{ProjectName}";
#if !SNIPPET
            newProjectName = "newFAQ";
#endif
            RequestContent creationRequestContent = RequestContent.Create(
                new {
                description          = "This is the description for a test project",
                language             = "en",
                multilingualResource = false,
                settings             = new {
                    defaultAnswer = "No answer found for your question."
                }
            }
                );

            Response creationResponse = client.CreateProject(newProjectName, creationRequestContent);

            // Projects can be retrieved as follows
            Pageable <BinaryData> projects = client.GetProjects();

            Console.WriteLine("Projects: ");
            foreach (BinaryData project in projects)
            {
                Console.WriteLine(project);
            }
            #endregion

            Assert.AreEqual(201, creationResponse.Status);
            Assert.That(projects.Any(project => project.ToString().Contains(newProjectName)));

            #region Snippet:QuestionAnsweringProjectsClient_UpdateSources

            // Set request content parameters for updating our new project's sources
            string sourceUri = "{KnowledgeSourceUri}";
#if !SNIPPET
            sourceUri = "https://www.microsoft.com/en-in/software-download/faq";
#endif
            RequestContent updateSourcesRequestContent = RequestContent.Create(
                new[] {
                new {
                    op    = "add",
                    value = new
                    {
                        displayName          = "MicrosoftFAQ",
                        source               = sourceUri,
                        sourceUri            = sourceUri,
                        sourceKind           = "url",
                        contentStructureKind = "unstructured",
                        refresh              = false
                    }
                }
            });

#if SNIPPET
            Operation <BinaryData> updateSourcesOperation = client.UpdateSources(waitForCompletion: true, newProjectName, updateSourcesRequestContent);
#else
            // TODO: Remove this region once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696
            Operation <BinaryData> updateSourcesOperation = await client.UpdateSourcesAsync(waitForCompletion : false, newProjectName, updateSourcesRequestContent);

            await updateSourcesOperation.WaitForCompletionAsync();
#endif

            // Knowledge Sources can be retrieved as follows
            Pageable <BinaryData> sources = client.GetSources(newProjectName);
            Console.WriteLine("Sources: ");
            foreach (BinaryData source in sources)
            {
                Console.WriteLine(source);
            }
            #endregion

            Assert.True(updateSourcesOperation.HasCompleted);
            Assert.That(sources.Any(source => source.ToString().Contains(sourceUri)));

            #region Snippet:QuestionAnsweringProjectsClient_DeployProject
            // Set deployment name and start operation
            string newDeploymentName = "{DeploymentName}";
#if !SNIPPET
            newDeploymentName = "production";
#endif
#if SNIPPET
            Operation <BinaryData> deploymentOperation = client.DeployProject(waitForCompletion: true, newProjectName, newDeploymentName);
#else
            // TODO: Remove this region once slowdown bug is fixed. https://github.com/Azure/azure-sdk-for-net/issues/26696
            Operation <BinaryData> deploymentOperation = await client.DeployProjectAsync(waitForCompletion : false, newProjectName, newDeploymentName);

            await deploymentOperation.WaitForCompletionAsync();
#endif

            // Deployments can be retrieved as follows
            Pageable <BinaryData> deployments = client.GetDeployments(newProjectName);
            Console.WriteLine("Deployments: ");
            foreach (BinaryData deployment in deployments)
            {
                Console.WriteLine(deployment);
            }
            #endregion

            Assert.True(deploymentOperation.HasCompleted);
            Assert.That(deployments.Any(deployment => deployment.ToString().Contains(newDeploymentName)));

            DeleteProject(newProjectName);
        }