Exemple #1
0
        public async Task ReturnEmptyDictionaryForEmptyInput()
        {
            var expected = new Dictionary <string, SentimentResult>();
            var sut      = TextAnalyticsTestHelper.BuildSut(GetMessage());

            var result = await sut.GetBatchSentimentAsync(new Dictionary <string, string>());

            CollectionAssert.AreEqual(expected, result.ToList());
        }
Exemple #2
0
        public async Task DecodeResponse()
        {
            var expected = KeyPhraseResult.Build(new[] { "wonderful hotel", "unique decor", "friendly staff" });

            var sut    = TextAnalyticsTestHelper.BuildSut(GetMessage());
            var result = await sut.GetKeyPhrasesAsync(Input);

            Assert.AreEqual(expected, result);
        }
Exemple #3
0
        public async Task ReturnBadRequestIfEmptyInput()
        {
            var expected = KeyPhraseResult.Build(Constants.KeyPhraseNullInputErrorText);
            var sut      = TextAnalyticsTestHelper.BuildSut(TextAnalyticsTestHelper.GetErrorMessage(Error));

            var result = await sut.GetKeyPhrasesAsync(null);

            Assert.AreEqual(expected, result);
        }
Exemple #4
0
        public async Task DecodeResponse()
        {
            var expected = SentimentResult.Build(1M);
            var sut      = TextAnalyticsTestHelper.BuildSut(GetMessage());

            var result = await sut.GetSentimentAsync(Input);

            Assert.AreEqual(expected, result);
        }
Exemple #5
0
        public async Task ReturnBadRequestIfEmptyInput()
        {
            var expected = SentimentResult.Build(Constants.SentimentNullInputErrorText);
            var sut      = TextAnalyticsTestHelper.BuildSut(GetMessage());

            var result = await sut.GetSentimentAsync(null);

            Assert.AreEqual(expected, result);
        }
Exemple #6
0
        public async Task ReturnFailureOnBadResult()
        {
            var error    = new ErrorMessageGenerator().GenerateError(HttpStatusCode.BadRequest, Error);
            var expected = KeyPhraseResult.Build(error);

            var sut    = TextAnalyticsTestHelper.BuildSut(TextAnalyticsTestHelper.GetErrorMessage(Error));
            var result = await sut.GetKeyPhrasesAsync(Input);

            Assert.AreEqual(expected, result);
        }
Exemple #7
0
        public async Task UrlEncodeInput()
        {
            var expected = $"{Constants.KeyPhraseRequest}{HttpUtility.UrlEncode(Input)}";
            var request  = "";

            var requestor = TextAnalyticsTestHelper.BuildMockRequestorForGet(s => request = s, GetMessage());
            var sut       = TextAnalyticsTestHelper.BuildSut(requestor.Object);
            await sut.GetKeyPhrasesAsync(Input);

            Assert.AreEqual(expected, request);
        }
Exemple #8
0
        public async Task ConvertDictionaryToPostBody()
        {
            const string Expected =
                @"{""Inputs"":[{""Id"":""1"",""Text"":""This is the first request""},{""Id"":""2"",""Text"":""This is the second request""},{""Id"":""3"",""Text"":""This is the third request""},{""Id"":""4"",""Text"":""this should cause an error""},]}";
            var request = "";

            var requestor = TextAnalyticsTestHelper.BuildMockRequestorForPost((req, body) => request = body, GetMessage());
            var sut       = TextAnalyticsTestHelper.BuildSut(requestor.Object);
            await sut.GetBatchSentimentAsync(this._input);

            Assert.AreEqual(Expected, request);
        }
Exemple #9
0
        public void ThrowIfOverBatchLimit()
        {
            ConfigurationManager.AppSettings[Constants.BatchLimitConfigKey] = "10";
            var sut = TextAnalyticsTestHelper.BuildSut(GetMessage());

            var requests = new Dictionary <string, string>();

            for (var i = 0; i < 11; i++)
            {
                requests.Add(i.ToString(), "this is text");
            }

            AssertEx.TaskThrows <InvalidOperationException>(() => sut.GetBatchSentimentAsync(requests));
        }
Exemple #10
0
        public async Task DecodeResponse()
        {
            var expected = new Dictionary <string, SentimentResult>
            {
                { "1", SentimentResult.Build(0.9549767M) },
                { "2", SentimentResult.Build(0.7767222M) },
                { "3", SentimentResult.Build(0.8988889M) },
                { "4", SentimentResult.Build("Record cannot be null/empty") }
            };
            var sut = TextAnalyticsTestHelper.BuildSut(GetMessage());

            var result = await sut.GetBatchSentimentAsync(this._input);

            CollectionAssert.AreEquivalent(expected, result.ToList());
        }
Exemple #11
0
        public async Task DecodeResponse()
        {
            var expected = new Dictionary <string, KeyPhraseResult>
            {
                { "1", KeyPhraseResult.Build(new[] { "unique decor", "friendly staff", "wonderful hotel" }) },
                { "2", KeyPhraseResult.Build(new[] { "amazing build conference", "interesting talks" }) },
                { "3", KeyPhraseResult.Build(new[] { "hours", "traffic", "airport" }) },
                { "4", KeyPhraseResult.Build("Record cannot be null/empty") }
            };
            var sut = TextAnalyticsTestHelper.BuildSut(GetMessage());

            var result = await sut.GetBatchKeyPhrasesAsync(this._input);

            CollectionAssert.AreEquivalent(expected, result.ToList());
        }
Exemple #12
0
        public async Task ReturnAllFailureOnBadResult()
        {
            var err      = new ErrorMessageGenerator().GenerateError(HttpStatusCode.BadRequest, Error);
            var expected = new Dictionary <string, SentimentResult>
            {
                { "1", SentimentResult.Build(err) },
                { "2", SentimentResult.Build(err) },
                { "3", SentimentResult.Build(err) },
                { "4", SentimentResult.Build(err) }
            };

            var sut    = TextAnalyticsTestHelper.BuildSut(TextAnalyticsTestHelper.GetErrorMessage(Error));
            var result = await sut.GetBatchSentimentAsync(this._input);

            CollectionAssert.AreEqual(expected, result.ToList());
        }