46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Ewide.Web.Entry;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using System;
|
|
using System.Net.Http;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
using Newtonsoft.Json;
|
|
using System.Threading.Tasks;
|
|
using Ewide.Core;
|
|
|
|
namespace Ewide.Test
|
|
{
|
|
public class AuthTest:IClassFixture<CustomWebApplicationFactory<Startup>>
|
|
{
|
|
private readonly CustomWebApplicationFactory<Startup> _factory;
|
|
private readonly HttpClient _client;
|
|
private readonly ITestOutputHelper _output;
|
|
public AuthTest(CustomWebApplicationFactory<Startup> factory, ITestOutputHelper output)
|
|
{
|
|
_factory = factory;
|
|
_client = _factory.CreateClient(new WebApplicationFactoryClientOptions
|
|
{
|
|
AllowAutoRedirect = false
|
|
}); ;
|
|
_output = output;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SuperAdmin_Login()
|
|
{
|
|
var loginUrl = "/login";
|
|
var res = await _client.PostAsync(loginUrl, new StringContent(
|
|
JsonConvert.SerializeObject(
|
|
new {
|
|
Account = "superAdmin",
|
|
Password = "123456" }
|
|
)
|
|
));
|
|
_output.WriteLine($"login status code {res.StatusCode}");
|
|
var body = await res.Content.ReadAsStringAsync();
|
|
_output.WriteLine($"body {body}");
|
|
Assert.True(JsonConvert.DeserializeObject<XnRestfulResult<object>>(body).Success) ;
|
|
}
|
|
}
|
|
}
|