Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics
{
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Rest;

/// <summary>
/// Allows authentication to the API using a basic apiKey mechanism
/// </summary>
public class ApiKeyServiceClientCredentials : ServiceClientCredentials
{
private readonly string subscriptionKey;

/// <summary>
/// Creates a new instance of the ApiKeyServiceClientCredentails class
/// </summary>
/// <param name="subscriptionKey">The subscription key to authenticate and authorize as</param>
public ApiKeyServiceClientCredentials(string subscriptionKey)
{
if (string.IsNullOrWhiteSpace(subscriptionKey))
throw new ArgumentNullException("subscriptionKey");

this.subscriptionKey = subscriptionKey;
}

/// <summary>
/// Add the Basic Authentication Header to each outgoing request
/// </summary>
/// <param name="request">The outgoing request</param>
/// <param name="cancellationToken">A token to cancel the operation</param>
public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request == null)
throw new ArgumentNullException("request");

request.Headers.Add("Ocp-Apim-Subscription-Key", this.subscriptionKey);

return Task.FromResult<object>(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using System.Net.Http;

namespace Language.Tests
{
public abstract class BaseTests
{
public static bool IsTestTenant = false;
private static string SubscriptionKey = "";
private static string Region = null;

static BaseTests()
{
// Retrieve the configuration information.

Region = "WestUS";
}
private static string SubscriptionKey = "000";

protected ITextAnalyticsAPI GetClient(DelegatingHandler handler)
{
ITextAnalyticsAPI client;
client = new TextAnalyticsAPI(handlers: handler);
client.SubscriptionKey = SubscriptionKey;

return client;
return new TextAnalyticsAPI(new ApiKeyServiceClientCredentials(SubscriptionKey), handlers: handler)
{
AzureRegion = AzureRegions.Westus
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<PropertyGroup>
<Description>Microsoft.Azure.CognitiveServices.Language.Tests Class Library</Description>
<AssemblyName>Microsoft.Azure.CognitiveServices.Language.Tests</AssemblyName>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no changes required to this file

<Version>1.0.0-preview</Version>
<Version>1.0.1-preview</Version>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"Entries": [
{
"RequestUri": "/text/analytics/v2.0/entities",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjAvZW50aXRpZXM=",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"Microsoft released Windows 10\"\r\n }\r\n ]\r\n}",
"RequestHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"123"
],
"Ocp-Apim-Subscription-Key": [
""
],
"User-Agent": [
"FxVersion/4.6.25211.01",
"Microsoft.CognitiveServices.Language.TextAnalytics.TextAnalyticsAPI/1.0.0"
]
},
"ResponseBody": "{ \"documents\": [{\"id\": \"1\", \"entities\": [ { \"name\": \"Windows 10\", \"matches\": [ { \"text\": \"Windows 10\", \"offset\": 19, \"length\": 10 } ], \"wikipediaLanguage\": \"en\", \"wikipediaId\": \"Windows 10\", \"wikipediaUrl\": \"https://en.wikipedia.org/wiki/Windows_10\", \"bingId\": \"5f9fbd03-49c4-39ef-cc95-de83ab897b94\" }, { \"name\": \"Microsoft\", \"matches\": [ { \"text\": \"Microsoft\", \"offset\": 0, \"length\": 9 } ], \"wikipediaLanguage\": \"en\", \"wikipediaId\": \"Microsoft\", \"wikipediaUrl\": \"https://en.wikipedia.org/wiki/Microsoft\", \"bingId\": \"a093e9b9-90f5-a3d5-c4b8-5855e1b01f85\" } ] }\r\n ],\r\n \"errors\": []\r\n}",
"ResponseHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Date": [
"Wed, 30 Aug 2017 02:11:17 GMT"
],
"Transfer-Encoding": [
"chunked"
],
"x-ms-transaction-count": [
"1"
],
"x-aml-ta-request-id": [
"460baaca-7f57-42c1-8cc7-8852957d05b9"
],
"X-Content-Type-Options": [
"nosniff"
],
"apim-request-id": [
"3f09b1c9-fe3b-46bb-badf-98108c599825"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains; preload"
]
},
"StatusCode": 200
}
],
"Names": {},
"Variables": {}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
using Language.Tests;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics;

using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using System.Collections.Generic;
using System.Threading.Tasks;

using Xunit;

namespace Language.TextAnalytics.Tests
namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests
{
public class DetectLanguageTests : BaseTests
{
[Fact]
public void DetectLanguage()
public async Task DetectLanguage()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
HttpMockServer.Initialize(this.GetType().FullName, "DetectLanguage");
ITextAnalyticsAPI client = GetClient(HttpMockServer.CreateInstance());
LanguageBatchResult result = client.DetectLanguage(
LanguageBatchResult result = await client.DetectLanguageAsync(
new BatchInput(
new List<Input>()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Language.Tests;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests
{
public class EntitiesTests : BaseTests
{
[Fact]
public async Task Entities()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
HttpMockServer.Initialize(this.GetType().FullName, "Entities");
ITextAnalyticsAPI client = GetClient(HttpMockServer.CreateInstance());
EntitiesBatchResult result = await client.EntitiesAsync(
new MultiLanguageBatchInput(
new List<MultiLanguageInput>()
{
new MultiLanguageInput()
{
Id ="id",
Text ="Microsoft released Windows 10",
Language ="en"
}
}));

Assert.Equal("Windows 10", result.Documents[0].Entities[0].Name);
Assert.Equal("5f9fbd03-49c4-39ef-cc95-de83ab897b94", result.Documents[0].Entities[0].BingId);
context.Stop();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
using Language.Tests;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics;

using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using System.Collections.Generic;
using System.Threading.Tasks;

using Xunit;

namespace Language.TextAnalytics.Tests
namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests
{
public class KeyPhrasesTests : BaseTests
{
[Fact]
public void KeyPhrases()
public async Task KeyPhrases()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
HttpMockServer.Initialize(this.GetType().FullName, "KeyPhrases");
ITextAnalyticsAPI client = GetClient(HttpMockServer.CreateInstance());
KeyPhraseBatchResult result = client.KeyPhrases(
KeyPhraseBatchResult result = await client.KeyPhrasesAsync(
new MultiLanguageBatchInput(
new List<MultiLanguageInput>()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
using Language.Tests;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics;

using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

using System.Collections.Generic;
using System.Threading.Tasks;

using Xunit;

namespace Language.TextAnalytics.Tests
namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests
{
public class SentimentTests : BaseTests
{
[Fact]
public void Sentiment()
public async Task Sentiment()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
HttpMockServer.Initialize(this.GetType().FullName, "Sentiment");
ITextAnalyticsAPI client = GetClient(HttpMockServer.CreateInstance());
SentimentBatchResult result = client.Sentiment(
SentimentBatchResult result = await client.SentimentAsync(
new MultiLanguageBatchInput(
new List<MultiLanguageInput>()
{
Expand Down
Loading