add integration tests
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using server.Models;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace server.integrationTests
|
||||
{
|
||||
[TestClass]
|
||||
public class CharacterEndpointsTests
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly JsonSerializerOptions _serializerOptions;
|
||||
public TestContext? TestContext { get; set; }
|
||||
|
||||
public CharacterEndpointsTests()
|
||||
{
|
||||
var webAppFactory = new WebApplicationFactory<Program>();
|
||||
|
||||
_httpClient = webAppFactory.CreateDefaultClient();
|
||||
|
||||
_serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetCharacters_AllCharacters_Returns200StatusWithCharacters()
|
||||
{
|
||||
var response = await _httpClient.GetAsync("/api/characters");
|
||||
var data = await response.Content.ReadAsStringAsync();
|
||||
var characters = JsonSerializer.Deserialize<List<Character>>(data, _serializerOptions);
|
||||
|
||||
Assert.IsNotNull(characters);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\server\server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user