Пример #1
0
        public async Task <IList <Detection> > DetectLanguages(IEnumerable <string> words)
        {
            TranslationClient client = await TranslationClient.CreateAsync();

            var detections = await client.DetectLanguagesAsync(words);

            return(detections);
        }
        public async Task NullArgumentAsyncChecks()
        {
            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.DetectLanguageAsync(null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.DetectLanguagesAsync(null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateTextAsync((string)null, "en"));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateTextAsync((IEnumerable <string>)null, "en"));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateHtmlAsync((string)null, "en"));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateHtmlAsync((IEnumerable <string>)null, "en"));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateTextAsync("text", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateTextAsync(new[] { "text" }, null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateHtmlAsync("html", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => ThrowingServiceClient.TranslateHtmlAsync(new[] { "html" }, null));
        }
        public async Task DetectLanguagesAsync()
        {
            // Snippet: DetectLanguagesAsync(IEnumerable<string>, CancellationToken)
            TranslationClient client  = TranslationClient.Create();
            IList <Detection> results = await client.DetectLanguagesAsync(new[] { "It is raining.", "Il pleut." });

            foreach (var result in results)
            {
                Console.WriteLine($"Text: {result.Text}; language: {result.Language}; confidence {result.Confidence}");
            }
            // End snippet

            Assert.Equal("en", results[0].Language);
            Assert.Equal("It is raining.", results[0].Text);
            Assert.Equal("fr", results[1].Language);
            Assert.Equal("Il pleut.", results[1].Text);
        }