test: 支持Appveyor数据库单元测试
This commit is contained in:
parent
9f7e559f1b
commit
66edea15b2
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.Mvc.Testing.Handlers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
@ -91,6 +92,24 @@ namespace Bootstrap.Admin
|
|||
{
|
||||
base.ConfigureWebHost(builder);
|
||||
|
||||
var config = new ConfigurationBuilder();
|
||||
config.AddJsonFile(TestHelper.RetrievePath("UnitTest\\appsettings.json"), false, true);
|
||||
config.AddEnvironmentVariables();
|
||||
var con = config.Build();
|
||||
|
||||
if (con.GetValue("Appveyor", false))
|
||||
{
|
||||
TestHelper.SQLServerConnectionString = con.GetConnectionString("sqlserver-app");
|
||||
TestHelper.MySqlConnectionString = con.GetConnectionString("mysql-app");
|
||||
TestHelper.NpgSqlConnectionString = con.GetConnectionString("npgsql-app");
|
||||
}
|
||||
else
|
||||
{
|
||||
TestHelper.SQLServerConnectionString = con.GetConnectionString("sqlserver");
|
||||
TestHelper.MySqlConnectionString = con.GetConnectionString("mysql");
|
||||
TestHelper.NpgSqlConnectionString = con.GetConnectionString("npgsql");
|
||||
}
|
||||
TestHelper.SQLiteConnectionString = con.GetConnectionString("sqlite");
|
||||
TestHelper.ConfigureWebHost(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using System.Collections.Generic;
|
||||
using Longbow.Web.Mvc;
|
||||
using System.Net.Http;
|
||||
using Xunit;
|
||||
|
||||
|
@ -12,8 +12,8 @@ namespace Bootstrap.Admin.Api
|
|||
[Fact]
|
||||
public async void Login_Get()
|
||||
{
|
||||
var users = await Client.GetAsJsonAsync<IEnumerable<LoginUser>>();
|
||||
Assert.NotEmpty(users);
|
||||
var users = await Client.GetAsJsonAsync<QueryData<LoginUser>>();
|
||||
Assert.NotEmpty(users.rows);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Bootstrap.Admin.Api.SQLite
|
||||
{
|
||||
[Collection("SQLiteContext")]
|
||||
public class AppsTest : Api.CategoryTest
|
||||
public class AppsTest : Api.AppsTest
|
||||
{
|
||||
public AppsTest(SQLiteBAWebHost factory) : base(factory) { }
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Bootstrap.Admin.Api
|
|||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
var resp = await Client.GetAsJsonAsync<IEnumerable<ICacheCorsItem>>();
|
||||
var resp = await Client.GetAsJsonAsync<IEnumerable<CacheCorsItem>>();
|
||||
Assert.NotNull(resp);
|
||||
}
|
||||
|
||||
|
@ -40,5 +40,33 @@ namespace Bootstrap.Admin.Api
|
|||
ids = dict.RetrieveDicts().Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id);
|
||||
dict.Delete(ids);
|
||||
}
|
||||
|
||||
internal class CacheCorsItem : ICacheCorsItem
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Desc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Self { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@ namespace UnitTest
|
|||
{
|
||||
public static class TestHelper
|
||||
{
|
||||
public static string SQLServerConnectionString { get; set; }
|
||||
|
||||
public static string SQLiteConnectionString { get; set; }
|
||||
|
||||
public static string MySqlConnectionString { get; set; }
|
||||
|
||||
public static string NpgSqlConnectionString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得当前工程解决方案目录
|
||||
/// </summary>
|
||||
|
@ -45,17 +53,15 @@ namespace UnitTest
|
|||
}
|
||||
}
|
||||
|
||||
private const string SqlConnectionString = "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa";
|
||||
private const string SQLiteConnectionString = "Data Source=UnitTest.db;";
|
||||
private const string MySqlConnectionString = "Server=localhost;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;allowPublicKeyRetrieval=true";
|
||||
private const string NpgSqlConnectionString = "Server=localhost;Database=UnitTest;User ID=argozhang;Password=sa;";
|
||||
|
||||
public static void ConfigureWebHost(IWebHostBuilder builder, DatabaseProviderType providerName = DatabaseProviderType.SqlServer)
|
||||
{
|
||||
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
|
||||
new KeyValuePair<string, string>("ConnectionStrings:ba", SqlConnectionString),
|
||||
new KeyValuePair<string, string>("DB:0:Enabled", "true")
|
||||
}));
|
||||
if (providerName == DatabaseProviderType.SqlServer)
|
||||
{
|
||||
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
|
||||
new KeyValuePair<string, string>("ConnectionStrings:ba", SQLServerConnectionString),
|
||||
new KeyValuePair<string, string>("DB:0:Enabled", "true")
|
||||
}));
|
||||
}
|
||||
|
||||
if (providerName == DatabaseProviderType.SQLite)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"sqlite": "Data Source=UnitTest.db;",
|
||||
"sqlserver": "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa",
|
||||
"mysql": "Server=localhost;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;allowPublicKeyRetrieval=true",
|
||||
"sqlserver-app": "Data Source=(local)\\SQL2014;Initial Catalog=BootstrapAdmin;User ID=sa;Password=Password12!",
|
||||
"mysql-app": "Server=localhost;Database=BootstrapAdmin;Uid=root;Pwd=Password12!;SslMode=none;allowPublicKeyRetrieval=true"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue