using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.Mvc.Testing.Handlers;
using Microsoft.AspNetCore.TestHost;

using Xunit;

using XUnitDIStudy.Model;

namespace XUnitDIStudy.Test
{
    public class ControllerTest:IClassFixture<WebApplicationFactory<WebApp.Startup>>
    {
        private readonly WebApplicationFactory<WebApp.Startup> _factory;

        public ControllerTest(WebApplicationFactory<WebApp.Startup> factory)
        {
            _factory = factory;
        }


        [Fact]
        public async Task Test()
        {
            // Arrange
            var client = _factory.CreateClient();

            // Act
            var response = await client.GetAsync("/Default/GetAll");

            // Assert
            response.EnsureSuccessStatusCode(); // Status Code 200-299

            List<Student> result = System.Text.Json.JsonSerializer.Deserialize<List<Student>>(await response.Content.ReadAsStringAsync());

            Assert.NotNull(result);
            Assert.True(result.Count>0);
        }
    }
}