更新工程:Bootstrap.Admin增加Postgresql支持

This commit is contained in:
Argo-Surface 2019-01-20 17:10:47 +08:00
parent 384be45a5b
commit d209d30f05
3 changed files with 41 additions and 12 deletions

View File

@ -20,6 +20,13 @@
{
"Enabled": true
},
{
"Enabled": true,
"ProviderName": "Sqlite",
"ConnectionStrings": {
"ba": "Data Source=BootstrapAdmin.db;"
}
},
{
"Enabled": true,
"ProviderName": "MySql",
@ -29,9 +36,9 @@
},
{
"Enabled": true,
"ProviderName": "Sqlite",
"ProviderName": "Npgsql",
"ConnectionStrings": {
"ba": "Data Source=BootstrapAdmin.db;"
"ba": "Server=localhost;Database=BootstrapAdmin;User ID=argozhang;Password=argo@163.com;"
}
},
{

View File

@ -1,5 +1,6 @@
//#define SQLite
//#define MySQL
//#define Npgsql
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System;
@ -57,28 +58,38 @@ namespace UnitTest
if (!File.Exists(dbFile)) File.Copy(dbPath, dbFile);
}
private const string SqlConnectionStrings = "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa";
private const string SQLiteConnectionStrings = "Data Source=UnitTest.db;";
private const string MySqlConnectionStrings = "Server=localhost;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;";
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;";
private const string NpgSqlConnectionString = "Server=localhost;Database=UnitTest;User ID=argozhang;Password=sa;";
public static void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("ConnectionStrings:ba", SqlConnectionStrings),
new KeyValuePair<string, string>("ConnectionStrings:ba", SqlConnectionString),
new KeyValuePair<string, string>("DB:0:Enabled", "true")
}));
#if SQLite
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("DB:1:Enabled", "false"),
new KeyValuePair<string, string>("DB:2:ConnectionStrings:ba", SQLiteConnectionStrings)
new KeyValuePair<string, string>("DB:1:Enabled", "true"),
new KeyValuePair<string, string>("DB:1:ConnectionStrings:ba", SQLiteConnectionString)
}));
#endif
#if MySQL
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("DB:1:ConnectionStrings:ba", MySqlConnectionStrings)
new KeyValuePair<string, string>("DB:2:Enabled", "true"),
new KeyValuePair<string, string>("DB:2:ConnectionStrings:ba", MySqlConnectionString)
}));
#endif
#if Npgsql
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("DB:3:Enabled", "true"),
new KeyValuePair<string, string>("DB:3:ConnectionStrings:ba", NpgSqlConnectionString)
}));
#endif
}
@ -86,16 +97,20 @@ namespace UnitTest
public static IConfiguration CreateConfiguraton()
{
var config = new ConfigurationBuilder().AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("ConnectionStrings:ba", SqlConnectionStrings),
new KeyValuePair<string, string>("ConnectionStrings:ba", SqlConnectionString),
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("DB:1:Enabled", "false"),
new KeyValuePair<string, string>("DB:1:ProviderName", "SQLite"),
new KeyValuePair<string, string>("DB:1:ConnectionStrings:ba", SQLiteConnectionStrings),
new KeyValuePair<string, string>("DB:1:ConnectionStrings:ba", SQLiteConnectionString),
new KeyValuePair<string, string>("DB:2:Enabled", "false"),
new KeyValuePair<string, string>("DB:2:ProviderName", "MySql"),
new KeyValuePair<string, string>("DB:2:ConnectionStrings:ba", MySqlConnectionStrings),
new KeyValuePair<string, string>("DB:2:ConnectionStrings:ba", MySqlConnectionString),
new KeyValuePair<string, string>("DB:3:Enabled", "false"),
new KeyValuePair<string, string>("DB:3:ProviderName", "NPgsql"),
new KeyValuePair<string, string>("DB:3:ConnectionStrings:ba", NpgSqlConnectionString),
new KeyValuePair<string, string>("LongbowCache:Enabled", "false")
});
@ -111,6 +126,12 @@ namespace UnitTest
new KeyValuePair<string, string>("DB:2:Enabled", "true")
});
#endif
#if Npgsql
config.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("DB:3:Enabled", "true")
});
#endif
return config.Build();
}
}

View File

@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="Npgsql" Version="4.0.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>