Skip to content

Commit

Permalink
Added additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenknox committed Jan 5, 2019
1 parent 6307359 commit 2545080
Show file tree
Hide file tree
Showing 25 changed files with 698 additions and 267 deletions.
57 changes: 57 additions & 0 deletions TwitterSentiment.Tests/TextAnalyticsClientShould.cs
@@ -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);
}

}
}
1 change: 1 addition & 0 deletions TwitterSentiment.Tests/TwitterSentiment.Tests.csproj
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="nsubstitute" Version="3.1.0" />
<PackageReference Include="shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
@@ -1,13 +1,14 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v2.1",
"signature": "ce6517d1848610fe5ec96103061072ba7512f57d"
"signature": "61e267463def7ad90c303fb8be2812d2f60fc3cc"
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v2.1": {
"TwitterSentiment.Tests/1.0.0": {
"dependencies": {
"Microsoft.Extensions.Configuration": "2.1.1",
"Microsoft.NET.Test.Sdk": "15.9.0",
"TwitterSentiment": "1.0.0",
"NSubstitute": "3.1.0",
Expand Down Expand Up @@ -96,6 +97,47 @@
}
}
},
"Microsoft.Extensions.Configuration/2.1.1": {
"dependencies": {
"Microsoft.Extensions.Configuration.Abstractions": "2.1.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Configuration.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.Configuration.Abstractions/2.1.1": {
"dependencies": {
"Microsoft.Extensions.Primitives": "2.1.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Configuration.Abstractions.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.Configuration.Binder/2.1.1": {
"dependencies": {
"Microsoft.Extensions.Configuration": "2.1.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Configuration.Binder.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions/2.1.1": {
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.DependencyModel/1.0.3": {
"dependencies": {
"Microsoft.DotNet.PlatformAbstractions": "1.0.3",
Expand All @@ -111,6 +153,65 @@
}
}
},
"Microsoft.Extensions.Http/2.1.1": {
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.1.1",
"Microsoft.Extensions.Logging": "2.1.1",
"Microsoft.Extensions.Options": "2.1.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Http.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.Logging/2.1.1": {
"dependencies": {
"Microsoft.Extensions.Configuration.Binder": "2.1.1",
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.1.1",
"Microsoft.Extensions.Logging.Abstractions": "2.1.1",
"Microsoft.Extensions.Options": "2.1.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.Logging.Abstractions/2.1.1": {
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Logging.Abstractions.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.Options/2.1.1": {
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.1.1",
"Microsoft.Extensions.Primitives": "2.1.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Options.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.Extensions.Primitives/2.1.1": {
"dependencies": {
"System.Memory": "4.5.1",
"System.Runtime.CompilerServices.Unsafe": "4.5.1"
},
"runtime": {
"lib/netstandard2.0/Microsoft.Extensions.Primitives.dll": {
"assemblyVersion": "2.1.1.0",
"fileVersion": "2.1.1.18157"
}
}
},
"Microsoft.NET.Test.Sdk/15.9.0": {
"dependencies": {
"Microsoft.CodeCoverage": "15.9.0",
Expand Down Expand Up @@ -760,6 +861,7 @@
"System.Runtime": "4.3.0"
}
},
"System.Memory/4.5.1": {},
"System.ObjectModel/4.3.0": {
"dependencies": {
"System.Collections": "4.3.0",
Expand Down Expand Up @@ -872,6 +974,14 @@
}
},
"System.Runtime/4.3.0": {},
"System.Runtime.CompilerServices.Unsafe/4.5.1": {
"runtime": {
"lib/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"assemblyVersion": "4.0.4.0",
"fileVersion": "0.0.0.0"
}
}
},
"System.Runtime.Extensions/4.3.0": {
"dependencies": {
"System.Runtime": "4.3.0"
Expand Down Expand Up @@ -1154,7 +1264,8 @@
},
"TwitterSentiment/1.0.0": {
"dependencies": {
"Microsoft.AspNet.WebApi.Client": "5.2.7"
"Microsoft.AspNet.WebApi.Client": "5.2.7",
"Microsoft.Extensions.Http": "2.1.1"
},
"runtime": {
"TwitterSentiment.dll": {}
Expand Down Expand Up @@ -1203,13 +1314,76 @@
"path": "microsoft.dotnet.platformabstractions/1.0.3",
"hashPath": "microsoft.dotnet.platformabstractions.1.0.3.nupkg.sha512"
},
"Microsoft.Extensions.Configuration/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-LjVKO6P2y52c5ZhTLX/w8zc5H4Y3J/LJsgqTBj49TtFq/hAtVNue/WA0F6/7GMY90xhD7K0MDZ4qpOeWXbLvzg==",
"path": "microsoft.extensions.configuration/2.1.1",
"hashPath": "microsoft.extensions.configuration.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.Configuration.Abstractions/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-VfuZJNa0WUshZ/+8BFZAhwFKiKuu/qOUCFntfdLpHj7vcRnsGHqd3G2Hse78DM+pgozczGM63lGPRLmy+uhUOA==",
"path": "microsoft.extensions.configuration.abstractions/2.1.1",
"hashPath": "microsoft.extensions.configuration.abstractions.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.Configuration.Binder/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-fcLCTS03poWE4v9tSNBr3pWn0QwGgAn1vzqHXlXgvqZeOc7LvQNzaWcKRQZTdEc3+YhQKwMsOtm3VKSA2aWQ8w==",
"path": "microsoft.extensions.configuration.binder/2.1.1",
"hashPath": "microsoft.extensions.configuration.binder.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.DependencyInjection.Abstractions/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-MgYpU5cwZohUMKKg3sbPhvGG+eAZ/59E9UwPwlrUkyXU+PGzqwZg9yyQNjhxuAWmoNoFReoemeCku50prYSGzA==",
"path": "microsoft.extensions.dependencyinjection.abstractions/2.1.1",
"hashPath": "microsoft.extensions.dependencyinjection.abstractions.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.DependencyModel/1.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Z3o19EnheuegmvgpCzwoSlnCWxYA6qIUhvKJ7ifKHHvU7U+oYR/gliLiL3LVYOOeGMEEzkpJ5W67sOcXizGtlw==",
"path": "microsoft.extensions.dependencymodel/1.0.3",
"hashPath": "microsoft.extensions.dependencymodel.1.0.3.nupkg.sha512"
},
"Microsoft.Extensions.Http/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-mDh9zlNwbdvb3BXjJejdcdovI5nsJZ4y0IU84QPFS9OB0q3e8BUVknTKr1Mub1nWQGEt6ZZDkP5vYf0KM7wVRw==",
"path": "microsoft.extensions.http/2.1.1",
"hashPath": "microsoft.extensions.http.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.Logging/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-hh+mkOAQDTp6XH80xJt3+wwYVzkbwYQl9XZRCz4Um0JjP/o7N9vHM3rZ6wwwtr+BBe/L6iBO2sz0px6OWBzqZQ==",
"path": "microsoft.extensions.logging/2.1.1",
"hashPath": "microsoft.extensions.logging.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.Logging.Abstractions/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-XRzK7ZF+O6FzdfWrlFTi1Rgj2080ZDsd46vzOjadHUB0Cz5kOvDG8vI7caa5YFrsHQpcfn0DxtjS4E46N4FZsA==",
"path": "microsoft.extensions.logging.abstractions/2.1.1",
"hashPath": "microsoft.extensions.logging.abstractions.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.Options/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-V7lXCU78lAbzaulCGFKojcCyG8RTJicEbiBkPJjFqiqXwndEBBIehdXRMWEVU3UtzQ1yDvphiWUL9th6/4gJ7w==",
"path": "microsoft.extensions.options/2.1.1",
"hashPath": "microsoft.extensions.options.2.1.1.nupkg.sha512"
},
"Microsoft.Extensions.Primitives/2.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-scJ1GZNIxMmjpENh0UZ8XCQ6vzr/LzeF9WvEA51Ix2OQGAs9WPgPu8ABVUdvpKPLuor/t05gm6menJK3PwqOXg==",
"path": "microsoft.extensions.primitives/2.1.1",
"hashPath": "microsoft.extensions.primitives.2.1.1.nupkg.sha512"
},
"Microsoft.NET.Test.Sdk/15.9.0": {
"type": "package",
"serviceable": true,
Expand Down Expand Up @@ -1455,6 +1629,13 @@
"path": "system.linq.queryable/4.3.0",
"hashPath": "system.linq.queryable.4.3.0.nupkg.sha512"
},
"System.Memory/4.5.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-sDJYJpGtTgx+23Ayu5euxG5mAXWdkDb4+b0rD0Cab0M1oQS9H0HXGPriKcqpXuiJDTV7fTp/d+fMDJmnr6sNvA==",
"path": "system.memory/4.5.1",
"hashPath": "system.memory.4.5.1.nupkg.sha512"
},
"System.ObjectModel/4.3.0": {
"type": "package",
"serviceable": true,
Expand Down Expand Up @@ -1539,6 +1720,13 @@
"path": "system.runtime/4.3.0",
"hashPath": "system.runtime.4.3.0.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/4.5.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Zh8t8oqolRaFa9vmOZfdQm/qKejdqz0J9kr7o2Fu0vPeoH3BL1EOXipKWwkWtLT1JPzjByrF19fGuFlNbmPpiw==",
"path": "system.runtime.compilerservices.unsafe/4.5.1",
"hashPath": "system.runtime.compilerservices.unsafe.4.5.1.nupkg.sha512"
},
"System.Runtime.Extensions/4.3.0": {
"type": "package",
"serviceable": true,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
20c77591648a5d8c2d62fca27b02847c61cc7b00
3a2632902872736462e821697aecd093ef825818
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
{
"version": 1,
"dgSpecHash": "Wb9E0k5ZLo4QOBej1INfgalhV1Wu749w9DdJcqxE85iRNg+IBSEdLwEvMgCgKLv7ASr9WLb0Affgbvop6uAhtQ==",
"dgSpecHash": "PKE6miY9XCgapVjzrrrEXfmdfxstWprd5WQ3/KZvGkFZ65b52ka2P2rNI7JGS79zaPptkPrg4tBcCIv3nVZgxA==",
"success": true
}
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">c:\Users\Steven\Source\TwitterSentiment\TwitterSentiment.Tests\obj\project.assets.json</ProjectAssetsFile>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">C:\Users\Steven\Source\TwitterSentiment\TwitterSentiment.Tests\obj\project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Steven\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
Expand Down

0 comments on commit 2545080

Please sign in to comment.