diff --git a/Api/Ewide.Test/AuthTest.cs b/Api/Ewide.Test/AuthTest.cs new file mode 100644 index 0000000..6236d82 --- /dev/null +++ b/Api/Ewide.Test/AuthTest.cs @@ -0,0 +1,45 @@ +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> + { + private readonly CustomWebApplicationFactory _factory; + private readonly HttpClient _client; + private readonly ITestOutputHelper _output; + public AuthTest(CustomWebApplicationFactory 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>(body).Success) ; + } + } +} diff --git a/Api/Ewide.Test/CustomWebApplicationFactory.cs b/Api/Ewide.Test/CustomWebApplicationFactory.cs new file mode 100644 index 0000000..f71226b --- /dev/null +++ b/Api/Ewide.Test/CustomWebApplicationFactory.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ewide.Test +{ + public class CustomWebApplicationFactory : WebApplicationFactory where TStartup : class + { + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + builder.UseEnvironment("Testing"); + } + } +} diff --git a/Api/Ewide.Test/Ewide.Test.csproj b/Api/Ewide.Test/Ewide.Test.csproj new file mode 100644 index 0000000..7e1a428 --- /dev/null +++ b/Api/Ewide.Test/Ewide.Test.csproj @@ -0,0 +1,28 @@ + + + + net5.0 + + false + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Api/Ewide.sln b/Api/Ewide.sln index f167482..c48a622 100644 --- a/Api/Ewide.sln +++ b/Api/Ewide.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ewide.Database.Migrations", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ewide.Web.Entry", "Ewide.Web.Entry\Ewide.Web.Entry.csproj", "{9826E365-EEE9-4721-A738-B02AB64D47E5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Test", "Ewide.Test\Ewide.Test.csproj", "{DECE4796-6B13-4607-9C27-C1FE093D4DC8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {9826E365-EEE9-4721-A738-B02AB64D47E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {9826E365-EEE9-4721-A738-B02AB64D47E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {9826E365-EEE9-4721-A738-B02AB64D47E5}.Release|Any CPU.Build.0 = Release|Any CPU + {DECE4796-6B13-4607-9C27-C1FE093D4DC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DECE4796-6B13-4607-9C27-C1FE093D4DC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DECE4796-6B13-4607-9C27-C1FE093D4DC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DECE4796-6B13-4607-9C27-C1FE093D4DC8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE