feature:添加集成测试
This commit is contained in:
45
Api/Ewide.Test/AuthTest.cs
Normal file
45
Api/Ewide.Test/AuthTest.cs
Normal file
@@ -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<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) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Api/Ewide.Test/CustomWebApplicationFactory.cs
Normal file
18
Api/Ewide.Test/CustomWebApplicationFactory.cs
Normal file
@@ -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<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
|
||||||
|
{
|
||||||
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||||
|
{
|
||||||
|
builder.UseEnvironment("Testing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
Api/Ewide.Test/Ewide.Test.csproj
Normal file
28
Api/Ewide.Test/Ewide.Test.csproj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Ewide.Web.Entry\Ewide.Web.Entry.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ewide.Database.Migrations",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ewide.Web.Entry", "Ewide.Web.Entry\Ewide.Web.Entry.csproj", "{9826E365-EEE9-4721-A738-B02AB64D47E5}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ewide.Web.Entry", "Ewide.Web.Entry\Ewide.Web.Entry.csproj", "{9826E365-EEE9-4721-A738-B02AB64D47E5}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ewide.Test", "Ewide.Test\Ewide.Test.csproj", "{DECE4796-6B13-4607-9C27-C1FE093D4DC8}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{9826E365-EEE9-4721-A738-B02AB64D47E5}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user