Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Sep 24, 2019
1 parent 0ae6bc9 commit 894d4be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TypeScriptToolsVersion>3.4</TypeScriptToolsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.1">
Expand Down
47 changes: 29 additions & 18 deletions tests/AngularWebpackVisualStudio_Tests/ThingsController_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,51 @@
using AngularWebpackVisualStudio;
using AngularWebpackVisualStudio.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Xunit;

namespace AngularWebpackVisualStudio_Tests
{
public class ThingsController_Tests
{
private readonly HttpClient _client;
public ThingsController_Tests()
{
var hostBuilder = new WebHostBuilder();

// Arrange
var server = new TestServer(hostBuilder.UseStartup<Startup>());
_client = server.CreateClient();
public class ThingsController_Tests : IClassFixture<WebApplicationFactory<AngularWebpackVisualStudio.Startup>>
{
private readonly WebApplicationFactory<AngularWebpackVisualStudio.Startup> _factory;

public ThingsController_Tests(WebApplicationFactory<AngularWebpackVisualStudio.Startup> factory)
{
_factory = factory;
}

//public ThingsController_Tests()
//{
// var hostBuilder = new WebHostBuilder();

// // Arrange
// var server = new TestServer(hostBuilder.UseStartup<Startup>());
// _client = server.CreateClient();
//}

[Fact]
public async Task Should_Add_One_Thing_Then_Return_The_Result()
{
var values = new Dictionary<string, string>
{
{"Id", "1"},
{ "Name", "NetCore"}
{
// Arrange
var client = _factory.CreateClient();

Thing thing = new Thing
{
Id = 1,
Name = "thingname"
};

var jsonString = JsonConvert.SerializeObject(values);
var jsonString = JsonConvert.SerializeObject(thing);
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
var response = await _client.PostAsync("/api/things", content);
var response = await client.PostAsync("/api/things", content);

response.EnsureSuccessStatusCode();

var responseGet = await _client.GetAsync("/api/things");
var responseGet = await client.GetAsync("/api/things");
responseGet.EnsureSuccessStatusCode();
var resultsInString = await responseGet.Content.ReadAsStringAsync();
var restulsInThingsArray = JsonConvert.DeserializeObject<Thing[]>(resultsInString);
Expand Down

0 comments on commit 894d4be

Please sign in to comment.