-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
TextAnalyticsClientTests.cs
170 lines (148 loc) · 10.7 KB
/
TextAnalyticsClientTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Azure.Core;
using Azure.Core.TestFramework;
using Azure.Identity;
using Moq;
using NUnit.Framework;
namespace Azure.AI.TextAnalytics.Tests
{
public class TextAnalyticsClientTests : ClientTestBase
{
public TextAnalyticsClientTests(bool isAsync)
: base(isAsync)
{
TextAnalyticsClientOptions options = new TextAnalyticsClientOptions()
{
Transport = new MockTransport(),
};
Client = InstrumentClient(new TextAnalyticsClient(new Uri("http://localhost"), new DefaultAzureCredential(), options));
}
public TextAnalyticsClient Client { get; set; }
[Test]
public void CreateClientArgumentValidation()
{
var uri = new Uri("http://localhost");
Assert.Throws<ArgumentNullException>(() => new TextAnalyticsClient(null, new AzureKeyCredential("apiKey")));
Assert.Throws<ArgumentNullException>(() => new TextAnalyticsClient(uri, (AzureKeyCredential)null));
Assert.Throws<ArgumentNullException>(() => new TextAnalyticsClient(uri, (TokenCredential)null));
Assert.Throws<ArgumentNullException>(() => new TextAnalyticsClient(null, new DefaultAzureCredential()));
}
[Test]
[TestCase(null)]
[TestCase("")]
public void CreateClientAllowsMissingDefaultLanguage(string defaultLanguage)
{
var uri = new Uri("http://localhost");
var options = new TextAnalyticsClientOptions { DefaultLanguage = defaultLanguage };
Assert.DoesNotThrow(() => new TextAnalyticsClient(uri, new AzureKeyCredential("apiKey"), options));
Assert.DoesNotThrow(() => new TextAnalyticsClient(uri, Mock.Of<TokenCredential>(), options));
}
[Test]
[TestCase(null)]
[TestCase("")]
public void CreateClientAllowsMissingDefaultCountryHint(string defaultCountryHint)
{
var uri = new Uri("http://localhost");
var options = new TextAnalyticsClientOptions { DefaultCountryHint = defaultCountryHint };
Assert.DoesNotThrow(() => new TextAnalyticsClient(uri, new AzureKeyCredential("apiKey"), options));
Assert.DoesNotThrow(() => new TextAnalyticsClient(uri, Mock.Of<TokenCredential>(), options));
}
[Test]
public void DetectLanguageArgumentValidation()
{
Assert.ThrowsAsync<ArgumentException>(() => Client.DetectLanguageAsync(""));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.DetectLanguageAsync(null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.DetectLanguageBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.DetectLanguageBatchAsync((DetectLanguageInput[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.DetectLanguageBatchAsync(Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentException>(() => Client.DetectLanguageBatchAsync(Array.Empty<DetectLanguageInput>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.DetectLanguageBatchAsync(null, new TextAnalyticsRequestOptions()));
}
[Test]
public void RecognizeEntitiesArgumentValidation()
{
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizeEntitiesAsync(""));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeEntitiesAsync(null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeEntitiesBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeEntitiesBatchAsync((TextDocumentInput[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizeEntitiesBatchAsync(Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizeEntitiesBatchAsync(Array.Empty<TextDocumentInput>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeEntitiesBatchAsync(null, new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeEntitiesBatchAsync((string[])null, options: new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeEntitiesBatchAsync(null, null, new TextAnalyticsRequestOptions()));
}
[Test]
public void RecognizePiiEntitiesArgumentValidation()
{
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizePiiEntitiesAsync(""));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizePiiEntitiesAsync(null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizePiiEntitiesBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizePiiEntitiesBatchAsync((TextDocumentInput[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizePiiEntitiesBatchAsync(Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizePiiEntitiesBatchAsync(Array.Empty<TextDocumentInput>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizePiiEntitiesBatchAsync(null, new RecognizePiiEntitiesOptions()));
}
[Test]
public void AnalyzeSentimentArgumentValidation()
{
Assert.ThrowsAsync<ArgumentException>(() => Client.AnalyzeSentimentAsync(""));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentAsync(null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.AnalyzeSentimentBatchAsync(Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentException>(() => Client.AnalyzeSentimentBatchAsync(Array.Empty<TextDocumentInput>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync(null, new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync(null, new AnalyzeSentimentOptions()));
// Variations to ensure call-compatibility after adding method-specific options class to parameters.
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync(null, options: new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync(null, null, new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync(null, new AnalyzeSentimentOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AnalyzeSentimentBatchAsync(null, null, new AnalyzeSentimentOptions()));
}
[Test]
public void ExtractKeyPhrasesArgumentValidation()
{
Assert.ThrowsAsync<ArgumentException>(() => Client.ExtractKeyPhrasesAsync(""));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractKeyPhrasesAsync(null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractKeyPhrasesBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractKeyPhrasesBatchAsync((TextDocumentInput[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.ExtractKeyPhrasesBatchAsync(Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentException>(() => Client.ExtractKeyPhrasesBatchAsync(Array.Empty<TextDocumentInput>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractKeyPhrasesBatchAsync((string[])null, options: new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractKeyPhrasesBatchAsync((TextDocumentInput[])null, options: new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractKeyPhrasesBatchAsync(null, null, new TextAnalyticsRequestOptions()));
}
[Test]
public void RecognizeLinkedEntitiesArgumentValidation()
{
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizeLinkedEntitiesAsync(""));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeLinkedEntitiesAsync(null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizeLinkedEntitiesBatchAsync(Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentException>(() => Client.RecognizeLinkedEntitiesBatchAsync(Array.Empty<TextDocumentInput>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeLinkedEntitiesBatchAsync(null, new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null, options: new TextAnalyticsRequestOptions()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.RecognizeLinkedEntitiesBatchAsync(null, null, new TextAnalyticsRequestOptions()));
}
[Test]
public void ExtractiveSummarizeArgumentValidation()
{
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractiveSummarizeAsync(WaitUntil.Completed, (string[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.ExtractiveSummarizeAsync(WaitUntil.Completed, Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.ExtractiveSummarizeAsync(WaitUntil.Completed, (TextDocumentInput[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.ExtractiveSummarizeAsync(WaitUntil.Completed, Array.Empty<TextDocumentInput>()));
}
[Test]
public void AbstractiveSummarizeArgumentValidation()
{
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AbstractiveSummarizeAsync(WaitUntil.Completed, (string[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.AbstractiveSummarizeAsync(WaitUntil.Completed, Array.Empty<string>()));
Assert.ThrowsAsync<ArgumentNullException>(() => Client.AbstractiveSummarizeAsync(WaitUntil.Completed, (TextDocumentInput[])null));
Assert.ThrowsAsync<ArgumentException>(() => Client.AbstractiveSummarizeAsync(WaitUntil.Completed, Array.Empty<TextDocumentInput>()));
}
}
}