Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6307359
commit 2545080
Showing
25 changed files
with
698 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
using NSubstitute; | ||
using Shouldly; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Tests.Fakes; | ||
using TwitterSentiment; | ||
using Xunit; | ||
|
||
namespace Tests | ||
{ | ||
public class TextAnalyticsClientShould | ||
{ | ||
public TextAnalyticsClientShould() | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task Get_Sentiment_Analysis_Results_Using_TypedHttpClient() | ||
{ | ||
var document1 = new Document { Id = "1", Text = "This is a really negative tweet", Language = "en-gb" }; | ||
var document2 = new Document { Id = "2", Text = "This is a super positive great tweet", Language = "en-gb" }; | ||
var document3 = new Document { Id = "3", Text = "This is another really super positive amazing tweet", Language = "en-gb" }; | ||
|
||
var result1 = new DocumentAnalysis { Id = "1", Score = 0 }; | ||
var result2 = new DocumentAnalysis { Id = "2", Score = 0.7 }; | ||
var result3 = new DocumentAnalysis { Id = "3", Score = 0.9 }; | ||
|
||
var documents = new List<Document> { document1, document2, document3 }; | ||
var results = new AnalysisResult { Documents = new List<DocumentAnalysis> { result1, result2, result3 } }; | ||
|
||
var fakeConfiguration = Substitute.For<IConfiguration>(); | ||
|
||
var fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage() | ||
{ | ||
StatusCode = HttpStatusCode.OK, | ||
Content = new StringContent(JsonConvert.SerializeObject(results), Encoding.UTF8, "application/json") | ||
}); | ||
|
||
var fakeHttpClient = new HttpClient(fakeHttpMessageHandler); | ||
|
||
var sut = new TextAnalyticsClient(fakeConfiguration, fakeHttpClient); | ||
|
||
var result = await sut.AnalyzeSentiment(documents); | ||
|
||
result.Documents.Count.ShouldBe(3); | ||
result.Documents.ShouldContain(f=> f.Id == result1.Id && f.Score == result1.Score); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+3.5 KB
(140%)
TwitterSentiment.Tests/bin/Debug/netcoreapp2.1/TwitterSentiment.Tests.dll
Binary file not shown.
Binary file modified
BIN
+588 Bytes
(140%)
TwitterSentiment.Tests/bin/Debug/netcoreapp2.1/TwitterSentiment.Tests.pdb
Binary file not shown.
Binary file modified
BIN
+13 KB
(300%)
TwitterSentiment.Tests/bin/Debug/netcoreapp2.1/TwitterSentiment.dll
Binary file not shown.
Binary file modified
BIN
+4.24 KB
(510%)
TwitterSentiment.Tests/bin/Debug/netcoreapp2.1/TwitterSentiment.pdb
Binary file not shown.
Binary file modified
BIN
+3.47 KB
(110%)
TwitterSentiment.Tests/obj/Debug/netcoreapp2.1/TwitterSentiment.Tests.assets.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
...iment.Tests/obj/Debug/netcoreapp2.1/TwitterSentiment.Tests.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20c77591648a5d8c2d62fca27b02847c61cc7b00 | ||
3a2632902872736462e821697aecd093ef825818 |
Binary file modified
BIN
+17.8 KB
(120%)
...timent.Tests/obj/Debug/netcoreapp2.1/TwitterSentiment.Tests.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified
BIN
+3.5 KB
(140%)
TwitterSentiment.Tests/obj/Debug/netcoreapp2.1/TwitterSentiment.Tests.dll
Binary file not shown.
Binary file modified
BIN
+588 Bytes
(140%)
TwitterSentiment.Tests/obj/Debug/netcoreapp2.1/TwitterSentiment.Tests.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
TwitterSentiment.Tests/obj/TwitterSentiment.Tests.csproj.nuget.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": 1, | ||
"dgSpecHash": "Wb9E0k5ZLo4QOBej1INfgalhV1Wu749w9DdJcqxE85iRNg+IBSEdLwEvMgCgKLv7ASr9WLb0Affgbvop6uAhtQ==", | ||
"dgSpecHash": "PKE6miY9XCgapVjzrrrEXfmdfxstWprd5WQ3/KZvGkFZ65b52ka2P2rNI7JGS79zaPptkPrg4tBcCIv3nVZgxA==", | ||
"success": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.