diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln index 696b979c..24020a88 100644 --- a/BootstrapAdmin.sln +++ b/BootstrapAdmin.sln @@ -54,7 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MySQL", "MySQL", "{084E2E94 DatabaseScripts\MySQL\install.sql = DatabaseScripts\MySQL\install.sql EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTest", "UniTest\UniTest.csproj", "{1019D84F-2D0E-4976-947E-10AB16A4E53F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTest", "UnitTest\UniTest.csproj", "{CFE75C48-F9D5-403A-8419-D07939BBD769}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -82,10 +82,10 @@ Global {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Debug|Any CPU.Build.0 = Debug|Any CPU {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.ActiveCfg = Release|Any CPU {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.Build.0 = Release|Any CPU - {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Release|Any CPU.Build.0 = Release|Any CPU + {CFE75C48-F9D5-403A-8419-D07939BBD769}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFE75C48-F9D5-403A-8419-D07939BBD769}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFE75C48-F9D5-403A-8419-D07939BBD769}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFE75C48-F9D5-403A-8419-D07939BBD769}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UniTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs b/UnitTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs similarity index 66% rename from UniTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs rename to UnitTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs index 11b94996..a378e5ed 100644 --- a/UniTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs +++ b/UnitTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs @@ -1,15 +1,26 @@ -using Microsoft.Extensions.Configuration; +#define SQLite +//#define MySQL + +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; +#if SQLite +using System; +using System.IO; +using UniTest; +#endif + namespace Bootstrap.DataAccess { public class BootstrapAdminStartup { + private readonly string DBFile; + public BootstrapAdminStartup() { var sqlConnectionStrings = "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa"; - var mysqlConnectionStrings = "Server=10.211.55.2;Database=BA;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"; + var mysqlConnectionStrings = "Server=.;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"; var config = new ConfigurationBuilder().AddInMemoryCollection(new KeyValuePair[] { new KeyValuePair("ConnectionStrings:ba", sqlConnectionStrings), new KeyValuePair("DB:0:Enabled", "false"), @@ -23,11 +34,24 @@ namespace Bootstrap.DataAccess new KeyValuePair("DB:2:ConnectionStrings:ba", mysqlConnectionStrings), new KeyValuePair("LongbowCache:Enabled", "false") }).Build(); + var sc = new ServiceCollection(); sc.AddSingleton(config); sc.AddConfigurationManager(config); sc.AddCacheManager(config); sc.AddDbAdapter(); + +#if SQLite + config["DB:1:Enabled"] = "true"; + + // Copy File + var dbPath = TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}DB{Path.DirectorySeparatorChar}UnitTest.db"); + DBFile = Path.Combine(AppContext.BaseDirectory, "UnitTest.db"); + if (!File.Exists(DBFile)) File.Copy(dbPath, DBFile); + +#elif MySQL + config["DB:2:Enabled"]= "true"; +#endif } } } diff --git a/UniTest/Bootstrap.DataAccess/DictsTest.cs b/UnitTest/Bootstrap.DataAccess/DictsTest.cs similarity index 100% rename from UniTest/Bootstrap.DataAccess/DictsTest.cs rename to UnitTest/Bootstrap.DataAccess/DictsTest.cs diff --git a/UniTest/Bootstrap.DataAccess/ExceptionsTest.cs b/UnitTest/Bootstrap.DataAccess/ExceptionsTest.cs similarity index 93% rename from UniTest/Bootstrap.DataAccess/ExceptionsTest.cs rename to UnitTest/Bootstrap.DataAccess/ExceptionsTest.cs index ddfa809a..5153fd59 100644 --- a/UniTest/Bootstrap.DataAccess/ExceptionsTest.cs +++ b/UnitTest/Bootstrap.DataAccess/ExceptionsTest.cs @@ -17,6 +17,7 @@ namespace Bootstrap.DataAccess public void Retrieves_Ok() { Exceptions excep = new Exceptions(); + excep.Log(new Exception("UnitTest"), null); Assert.NotEmpty(excep.Retrieves()); } diff --git a/UniTest/Bootstrap.DataAccess/GroupsTest.cs b/UnitTest/Bootstrap.DataAccess/GroupsTest.cs similarity index 100% rename from UniTest/Bootstrap.DataAccess/GroupsTest.cs rename to UnitTest/Bootstrap.DataAccess/GroupsTest.cs diff --git a/UniTest/Bootstrap.DataAccess/LogsTest.cs b/UnitTest/Bootstrap.DataAccess/LogsTest.cs similarity index 68% rename from UniTest/Bootstrap.DataAccess/LogsTest.cs rename to UnitTest/Bootstrap.DataAccess/LogsTest.cs index 49b1c1b0..8493ba0c 100644 --- a/UniTest/Bootstrap.DataAccess/LogsTest.cs +++ b/UnitTest/Bootstrap.DataAccess/LogsTest.cs @@ -21,7 +21,15 @@ namespace Bootstrap.DataAccess [Fact] public void Retrieves_Ok() { - var log = new Log(); + var log = new Log() + { + UserName = "UnitTest", + ClientAgent = "UnitTest-Agent", + ClientIp = "::", + CRUD = "UnitTest", + RequestUrl = "~/Home/Index" + }; + log.Save(log); Assert.NotEmpty(log.Retrieves()); } } diff --git a/UniTest/Bootstrap.DataAccess/MenusTest.cs b/UnitTest/Bootstrap.DataAccess/MenusTest.cs similarity index 100% rename from UniTest/Bootstrap.DataAccess/MenusTest.cs rename to UnitTest/Bootstrap.DataAccess/MenusTest.cs diff --git a/UniTest/Bootstrap.DataAccess/MessagesTest.cs b/UnitTest/Bootstrap.DataAccess/MessagesTest.cs similarity index 100% rename from UniTest/Bootstrap.DataAccess/MessagesTest.cs rename to UnitTest/Bootstrap.DataAccess/MessagesTest.cs diff --git a/UniTest/Bootstrap.DataAccess/RolesTest.cs b/UnitTest/Bootstrap.DataAccess/RolesTest.cs similarity index 100% rename from UniTest/Bootstrap.DataAccess/RolesTest.cs rename to UnitTest/Bootstrap.DataAccess/RolesTest.cs diff --git a/UniTest/Bootstrap.DataAccess/TasksTest.cs b/UnitTest/Bootstrap.DataAccess/TasksTest.cs similarity index 100% rename from UniTest/Bootstrap.DataAccess/TasksTest.cs rename to UnitTest/Bootstrap.DataAccess/TasksTest.cs diff --git a/UniTest/Bootstrap.DataAccess/UsersTest.cs b/UnitTest/Bootstrap.DataAccess/UsersTest.cs similarity index 94% rename from UniTest/Bootstrap.DataAccess/UsersTest.cs rename to UnitTest/Bootstrap.DataAccess/UsersTest.cs index db1678e4..2536c298 100644 --- a/UniTest/Bootstrap.DataAccess/UsersTest.cs +++ b/UnitTest/Bootstrap.DataAccess/UsersTest.cs @@ -138,5 +138,13 @@ namespace Bootstrap.DataAccess var u = new User(); Assert.True(u.SaveByRoleId("1", new string[] { "1", "2" })); } + + [Fact] + public void RetrieveUserByUserName_Ok() + { + var u = new User(); + var usr = u.RetrieveUserByUserName("Admin"); + Assert.Equal("Administrator", usr.DisplayName); + } } } diff --git a/UniTest/DB/UnitTest.db b/UnitTest/DB/UnitTest.db similarity index 100% rename from UniTest/DB/UnitTest.db rename to UnitTest/DB/UnitTest.db diff --git a/UnitTest/TestHelper.cs b/UnitTest/TestHelper.cs new file mode 100644 index 00000000..7c55244d --- /dev/null +++ b/UnitTest/TestHelper.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; + +namespace UniTest +{ + public static class TestHelper + { + /// + /// 获得当前工程解决方案目录 + /// + /// + public static string RetrieveSolutionPath() + { + var dirSeparator = Path.DirectorySeparatorChar; + var paths = AppContext.BaseDirectory.SpanSplit($"{dirSeparator}.vs{dirSeparator}"); + return paths.Count > 1 ? paths[0] : Path.Combine(AppContext.BaseDirectory, $"..{dirSeparator}..{dirSeparator}..{dirSeparator}..{dirSeparator}"); + } + + /// + /// + /// + /// + /// + public static string RetrievePath(string folder) + { + var soluFolder = RetrieveSolutionPath(); + return Path.Combine(soluFolder, folder); + } + } +} diff --git a/UniTest/UniTest.csproj b/UnitTest/UniTest.csproj similarity index 68% rename from UniTest/UniTest.csproj rename to UnitTest/UniTest.csproj index 22026dd4..182f1333 100644 --- a/UniTest/UniTest.csproj +++ b/UnitTest/UniTest.csproj @@ -6,9 +6,13 @@ + - + + all + runtime; build; native; contentfiles; analyzers +