Skip to content

Commit 894d4be

Browse files
committed
fixing tests
1 parent 0ae6bc9 commit 894d4be

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/AngularWebpackVisualStudio/AngularWebpackVisualStudio.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<TypeScriptToolsVersion>3.4</TypeScriptToolsVersion>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.App" />
98
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
109
</ItemGroup>
1110
<ItemGroup>

tests/AngularWebpackVisualStudio_Tests/AngularWebpackVisualStudio_Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
<ItemGroup>
77
<PackageReference Include="Microsoft.AspNetCore.App" />
8+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
810
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
911
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
1012
<PackageReference Include="xunit.runner.console" Version="2.4.1">

tests/AngularWebpackVisualStudio_Tests/ThingsController_Tests.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,51 @@
55
using AngularWebpackVisualStudio;
66
using AngularWebpackVisualStudio.Models;
77
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Mvc.Testing;
89
using Microsoft.AspNetCore.TestHost;
10+
using Microsoft.Extensions.Hosting;
911
using Newtonsoft.Json;
1012
using Xunit;
1113

1214
namespace AngularWebpackVisualStudio_Tests
1315
{
14-
public class ThingsController_Tests
15-
{
16-
private readonly HttpClient _client;
17-
public ThingsController_Tests()
18-
{
19-
var hostBuilder = new WebHostBuilder();
20-
21-
// Arrange
22-
var server = new TestServer(hostBuilder.UseStartup<Startup>());
23-
_client = server.CreateClient();
16+
public class ThingsController_Tests : IClassFixture<WebApplicationFactory<AngularWebpackVisualStudio.Startup>>
17+
{
18+
private readonly WebApplicationFactory<AngularWebpackVisualStudio.Startup> _factory;
19+
20+
public ThingsController_Tests(WebApplicationFactory<AngularWebpackVisualStudio.Startup> factory)
21+
{
22+
_factory = factory;
2423
}
2524

25+
//public ThingsController_Tests()
26+
//{
27+
// var hostBuilder = new WebHostBuilder();
28+
29+
// // Arrange
30+
// var server = new TestServer(hostBuilder.UseStartup<Startup>());
31+
// _client = server.CreateClient();
32+
//}
33+
2634
[Fact]
2735
public async Task Should_Add_One_Thing_Then_Return_The_Result()
28-
{
29-
var values = new Dictionary<string, string>
30-
{
31-
{"Id", "1"},
32-
{ "Name", "NetCore"}
36+
{
37+
// Arrange
38+
var client = _factory.CreateClient();
39+
40+
Thing thing = new Thing
41+
{
42+
Id = 1,
43+
Name = "thingname"
3344
};
3445

35-
var jsonString = JsonConvert.SerializeObject(values);
46+
var jsonString = JsonConvert.SerializeObject(thing);
3647
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
37-
var response = await _client.PostAsync("/api/things", content);
48+
var response = await client.PostAsync("/api/things", content);
3849

3950
response.EnsureSuccessStatusCode();
4051

41-
var responseGet = await _client.GetAsync("/api/things");
52+
var responseGet = await client.GetAsync("/api/things");
4253
responseGet.EnsureSuccessStatusCode();
4354
var resultsInString = await responseGet.Content.ReadAsStringAsync();
4455
var restulsInThingsArray = JsonConvert.DeserializeObject<Thing[]>(resultsInString);

0 commit comments

Comments
 (0)