2019-01-21 17:33:20 +08:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Testing.Handlers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using UnitTest;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin
|
|
|
|
|
{
|
2019-01-24 17:58:06 +08:00
|
|
|
|
[CollectionDefinition("SQLServerContext")]
|
2019-01-21 17:33:20 +08:00
|
|
|
|
public class BootstrapAdminTestContext : ICollectionFixture<BAWebHost>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 17:58:06 +08:00
|
|
|
|
[CollectionDefinition("SQLiteContext")]
|
|
|
|
|
public class SQLiteContext : ICollectionFixture<SQLiteBAWebHost>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[CollectionDefinition("MySqlContext")]
|
|
|
|
|
public class MySqlContext : ICollectionFixture<MySqlBAWebHost>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MySqlBAWebHost : BAWebHost
|
|
|
|
|
{
|
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
base.ConfigureWebHost(builder);
|
|
|
|
|
|
|
|
|
|
TestHelper.ConfigureWebHost(builder, Longbow.Data.DatabaseProviderType.MySql);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SQLiteBAWebHost : BAWebHost
|
|
|
|
|
{
|
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
base.ConfigureWebHost(builder);
|
|
|
|
|
|
|
|
|
|
TestHelper.ConfigureWebHost(builder, Longbow.Data.DatabaseProviderType.SQLite);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-21 17:33:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BAWebHost : WebApplicationFactory<Startup>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
static BAWebHost()
|
|
|
|
|
{
|
|
|
|
|
// Copy license
|
|
|
|
|
TestHelper.CopyLicense();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BAWebHost()
|
|
|
|
|
{
|
|
|
|
|
var client = CreateClient("Account/Login");
|
|
|
|
|
var login = client.LoginAsync();
|
|
|
|
|
login.Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得已经登录的HttpClient
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="baseAddress"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public HttpClient CreateClient(string baseAddress) => CreateDefaultClient(new Uri($"http://localhost/{baseAddress}/"), new RedirectHandler(7), new CookieContainerHandler(_cookie));
|
|
|
|
|
|
|
|
|
|
private readonly CookieContainer _cookie = new CookieContainer();
|
|
|
|
|
|
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
base.ConfigureWebHost(builder);
|
|
|
|
|
|
|
|
|
|
TestHelper.ConfigureWebHost(builder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|