You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Moq;
using WebApiStudy.Model;
using WebApiStudy.WebApp;
namespace WebApiStudy.IntegrationTest
{
[Collection("GlobalTestServer")]
public class TestControllerTest
{
private TestServer _server;
private readonly HttpClient _client;
public TestControllerTest(TestServerFixture testServer)
{
_server = testServer.TestServer;
_client = _server.CreateClient();
}
[Fact]
public async Task Test()
{
var response = await _client.GetAsync("/api/values");
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
IList<string> list = JsonConvert.DeserializeObject<IList<string>>(responseString);
Assert.Equal(2, list.Count);
Assert.Contains("value1", list);
Assert.Contains("value2", list);
}
}
}