Skip to content

Commit d77f0da

Browse files
author
Salah Mostafa
authored
[CLU] Added live tests (#24308)
* Added live tests and recorded them * Minor changes * Changed asserting for deepstack test. * minor change
1 parent a7a1ba6 commit d77f0da

File tree

9 files changed

+649
-0
lines changed

9 files changed

+649
-0
lines changed

sdk/cognitivelanguage/Azure.AI.Language.Conversations/tests/ConversationAnalysisClientLiveTests.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using Azure.AI.Language.Conversations.Models;
8+
using Azure.Core.TestFramework;
9+
using NUnit.Framework;
10+
411
namespace Azure.AI.Language.Conversations.Tests
512
{
613
public class ConversationAnalysisClientLiveTests : ConversationAnalysisTestBase<ConversationAnalysisClient>
@@ -9,5 +16,81 @@ public ConversationAnalysisClientLiveTests(bool isAsync, ConversationAnalysisCli
916
: base(isAsync, serviceVersion, null /* RecordedTestMode.Record /* to record */)
1017
{
1118
}
19+
private static string EnglishText = "We'll have 2 plates of seared salmon nigiri.";
20+
private static string SpanishText = "Tendremos 2 platos de nigiri de salmón braseado.";
21+
private static List<string> ExpectedOutput = new List<string>()
22+
{
23+
"2 plates",
24+
"seared salmon nigiri"
25+
};
26+
27+
[RecordedTest]
28+
public async Task AnalyzeConversation()
29+
{
30+
AnalyzeConversationOptions options = new AnalyzeConversationOptions(
31+
TestEnvironment.ProjectName,
32+
TestEnvironment.DeploymentName,
33+
EnglishText);
34+
35+
Response<AnalyzeConversationResult> response = await Client.AnalyzeConversationAsync(options);
36+
37+
Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order"));
38+
Assert.That(response.Value.Prediction.ProjectKind, Is.EqualTo(ProjectKind.Conversation));
39+
}
40+
41+
[RecordedTest]
42+
public async Task AnalyzeConversationWithLanguage()
43+
{
44+
AnalyzeConversationOptions options = new AnalyzeConversationOptions(
45+
TestEnvironment.ProjectName,
46+
TestEnvironment.DeploymentName,
47+
SpanishText)
48+
{
49+
Language = "es"
50+
};
51+
52+
Response<AnalyzeConversationResult> response = await Client.AnalyzeConversationAsync(options);
53+
54+
Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order"));
55+
Assert.That(response.Value.Prediction.ProjectKind, Is.EqualTo(ProjectKind.Conversation));
56+
}
57+
58+
[RecordedTest]
59+
public async Task AnalyzeConversationsDeepstack()
60+
{
61+
AnalyzeConversationOptions options = new AnalyzeConversationOptions(
62+
TestEnvironment.ProjectName,
63+
TestEnvironment.DeploymentName,
64+
EnglishText);
65+
66+
Response<AnalyzeConversationResult> response = await Client.AnalyzeConversationAsync(options);
67+
68+
DeepstackPrediction deepstackPrediction = response.Value.Prediction as DeepstackPrediction;
69+
70+
Assert.That(response.Value.Prediction.ProjectKind, Is.EqualTo(ProjectKind.Conversation));
71+
72+
Assert.That(deepstackPrediction.TopIntent, Is.EqualTo("Order"));
73+
74+
IList<string> entitiesText = deepstackPrediction.Entities.Select(entity => entity.Text).ToList();
75+
Assert.That(entitiesText, Has.Count.EqualTo(2));
76+
Assert.That(entitiesText, Is.EquivalentTo(ExpectedOutput));
77+
}
78+
79+
[RecordedTest]
80+
public void AnalyzeConversationsInvalidArgument()
81+
{
82+
AnalyzeConversationOptions options = new AnalyzeConversationOptions(
83+
TestEnvironment.ProjectName,
84+
TestEnvironment.DeploymentName,
85+
"");
86+
87+
RequestFailedException ex = Assert.ThrowsAsync<RequestFailedException>(async () =>
88+
{
89+
await Client.AnalyzeConversationAsync(options);
90+
});
91+
92+
Assert.That(ex.Status, Is.EqualTo(400));
93+
Assert.That(ex.ErrorCode, Is.EqualTo("InvalidArgument"));
94+
}
1295
}
1396
}

sdk/cognitivelanguage/Azure.AI.Language.Conversations/tests/SessionRecords/ConversationAnalysisClientLiveTests/AnalyzeConversation.json

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/cognitivelanguage/Azure.AI.Language.Conversations/tests/SessionRecords/ConversationAnalysisClientLiveTests/AnalyzeConversationAsync.json

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/cognitivelanguage/Azure.AI.Language.Conversations/tests/SessionRecords/ConversationAnalysisClientLiveTests/AnalyzeConversationWithLanguage.json

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/cognitivelanguage/Azure.AI.Language.Conversations/tests/SessionRecords/ConversationAnalysisClientLiveTests/AnalyzeConversationWithLanguageAsync.json

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)