From d209d30f05b28a717a42a3b7a52c1fbf65a5f563 Mon Sep 17 00:00:00 2001 From: Argo-Surface Date: Sun, 20 Jan 2019 17:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=B7=A5=E7=A8=8B=EF=BC=9ABo?= =?UTF-8?q?otstrap.Admin=E5=A2=9E=E5=8A=A0Postgresql=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/appsettings.json | 11 +++++++-- UnitTest/TestHelper.cs | 41 ++++++++++++++++++++++++-------- UnitTest/UnitTest.csproj | 1 + 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json index 607412d6..831e6d9c 100644 --- a/Bootstrap.Admin/appsettings.json +++ b/Bootstrap.Admin/appsettings.json @@ -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;" } }, { diff --git a/UnitTest/TestHelper.cs b/UnitTest/TestHelper.cs index 2ef6cd25..2b875eb9 100644 --- a/UnitTest/TestHelper.cs +++ b/UnitTest/TestHelper.cs @@ -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[] { - new KeyValuePair("ConnectionStrings:ba", SqlConnectionStrings), + new KeyValuePair("ConnectionStrings:ba", SqlConnectionString), new KeyValuePair("DB:0:Enabled", "true") })); #if SQLite builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair[] { new KeyValuePair("DB:0:Enabled", "false"), - new KeyValuePair("DB:1:Enabled", "false"), - new KeyValuePair("DB:2:ConnectionStrings:ba", SQLiteConnectionStrings) + new KeyValuePair("DB:1:Enabled", "true"), + new KeyValuePair("DB:1:ConnectionStrings:ba", SQLiteConnectionString) })); #endif #if MySQL builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair[] { new KeyValuePair("DB:0:Enabled", "false"), - new KeyValuePair("DB:1:ConnectionStrings:ba", MySqlConnectionStrings) + new KeyValuePair("DB:2:Enabled", "true"), + new KeyValuePair("DB:2:ConnectionStrings:ba", MySqlConnectionString) + })); +#endif + +#if Npgsql + builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair[] { + new KeyValuePair("DB:0:Enabled", "false"), + new KeyValuePair("DB:3:Enabled", "true"), + new KeyValuePair("DB:3:ConnectionStrings:ba", NpgSqlConnectionString) })); #endif } @@ -86,16 +97,20 @@ namespace UnitTest public static IConfiguration CreateConfiguraton() { var config = new ConfigurationBuilder().AddInMemoryCollection(new KeyValuePair[] { - new KeyValuePair("ConnectionStrings:ba", SqlConnectionStrings), + new KeyValuePair("ConnectionStrings:ba", SqlConnectionString), new KeyValuePair("DB:0:Enabled", "false"), new KeyValuePair("DB:1:Enabled", "false"), new KeyValuePair("DB:1:ProviderName", "SQLite"), - new KeyValuePair("DB:1:ConnectionStrings:ba", SQLiteConnectionStrings), + new KeyValuePair("DB:1:ConnectionStrings:ba", SQLiteConnectionString), new KeyValuePair("DB:2:Enabled", "false"), new KeyValuePair("DB:2:ProviderName", "MySql"), - new KeyValuePair("DB:2:ConnectionStrings:ba", MySqlConnectionStrings), + new KeyValuePair("DB:2:ConnectionStrings:ba", MySqlConnectionString), + + new KeyValuePair("DB:3:Enabled", "false"), + new KeyValuePair("DB:3:ProviderName", "NPgsql"), + new KeyValuePair("DB:3:ConnectionStrings:ba", NpgSqlConnectionString), new KeyValuePair("LongbowCache:Enabled", "false") }); @@ -111,6 +126,12 @@ namespace UnitTest new KeyValuePair("DB:2:Enabled", "true") }); #endif + +#if Npgsql + config.AddInMemoryCollection(new KeyValuePair[] { + new KeyValuePair("DB:3:Enabled", "true") + }); +#endif return config.Build(); } } diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj index 1b9f1238..632beb33 100644 --- a/UnitTest/UnitTest.csproj +++ b/UnitTest/UnitTest.csproj @@ -11,6 +11,7 @@ + all