From 7932587c866d5bf0732fc1125310cfbf2f5f5048 Mon Sep 17 00:00:00 2001 From: "agile.zhou" Date: Mon, 15 Jan 2024 00:41:38 +0800 Subject: [PATCH] update AppServiceTests for oracle --- .../appsettings.Development.json | 2 +- .../oracle/AppServiceTests.cs | 373 +----------------- 2 files changed, 9 insertions(+), 366 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/appsettings.Development.json b/src/AgileConfig.Server.Apisite/appsettings.Development.json index 22ade014..6271b2e5 100644 --- a/src/AgileConfig.Server.Apisite/appsettings.Development.json +++ b/src/AgileConfig.Server.Apisite/appsettings.Development.json @@ -23,7 +23,7 @@ //"provider": "npgsql", //"conn": "Host=127.0.0.1;Database=agileconfig;Username=postgres;Password=123456" //"provider": "oracle", - //"conn": "user id=CLINIC;password=CLINIC;data source=192.168.0.91/orcl" + //"conn": "user id=x;password=x;data source=192.168.0.123/orcl" //"provider": "mysql", //"conn": "Database=agile_config;Data Source=192.168.0.125;User Id=root;Password=x;port=13306;Allow User Variables=true;", "provider": "mongodb", diff --git a/test/AgileConfig.Server.ServiceTests/oracle/AppServiceTests.cs b/test/AgileConfig.Server.ServiceTests/oracle/AppServiceTests.cs index 3f0a932b..9841894e 100644 --- a/test/AgileConfig.Server.ServiceTests/oracle/AppServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/oracle/AppServiceTests.cs @@ -2,380 +2,23 @@ using AgileConfig.Server.Service; using System; using System.Collections.Generic; -using System.Text; -using FreeSql; -using AgileConfig.Server.Data.Freesql; -using AgileConfig.Server.Data.Entity; -using System.Threading.Tasks; -using AgileConfig.Server.IService; -using System.Runtime.CompilerServices; +using AgileConfig.Server.ServiceTests.sqlite; namespace AgileConfig.Server.Service.Tests.oracle { [TestClass()] - public class AppServiceTests + public class AppServiceTests_oracle : AppServiceTests { - IFreeSql fsq = null; - FreeSqlContext freeSqlContext; - IAppService service = null; + string conn = "user id=x;password=x;data source=192.168.0.123/orcl"; - [TestInitialize] - public void TestInitialize() + public override Dictionary GetConfigurationData() { - string conn = "user id=CLINIC;password=CLINIC;data source=192.168.0.91/orcl"; - fsq = new FreeSqlBuilder() - .UseConnectionString(FreeSql.DataType.Oracle, conn) - .UseAutoSyncStructure(true) - .Build(); - FluentApi.Config(fsq); - freeSqlContext = new FreeSqlContext(fsq); - - // todo - - //service = new AppService(freeSqlContext); - fsq.Delete().Where("1=1"); - - Console.WriteLine("TestInitialize"); - } - [TestMethod()] - public async Task AddAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - var app = fsq.Select(new - { - Id = id - }).ToOne(); - - Assert.IsTrue(result); - Assert.IsNotNull(app); - - Assert.AreEqual(source.Id, app.Id); - Assert.AreEqual(source.Name, app.Name); - Assert.AreEqual(source.Secret, app.Secret); - // Assert.AreEqual(source.CreateTime, app.CreateTime); - // Assert.AreEqual(source.UpdateTime, app.UpdateTime); - Assert.AreEqual(source.Enabled, app.Enabled); - } - - [TestMethod()] - public async Task DeleteAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - Assert.IsTrue(result); - - var delResult = await service.DeleteAsync(source); - Assert.IsTrue(delResult); - - var app = fsq.Select(new - { - Id = id - }).ToOne(); - Assert.IsNull(app); + var dict = base.GetConfigurationData(); + dict["db:provider"] = "oracle"; + dict["db:conn"] = conn; + return dict; } - [TestMethod()] - public async Task DeleteAsyncTest1() - { - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - Assert.IsTrue(result); - - var delResult = await service.DeleteAsync(id); - Assert.IsTrue(delResult); - - var app = fsq.Select(new - { - Id = id - }).ToOne(); - Assert.IsNull(app); - - } - - [TestMethod()] - public async Task GetAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - Assert.IsTrue(result); - - var app = await service.GetAsync(id); - Assert.IsNotNull(app); - - Assert.AreEqual(source.Id, app.Id); - Assert.AreEqual(source.Name, app.Name); - Assert.AreEqual(source.Secret, app.Secret); - // Assert.AreEqual(source.CreateTime, app.CreateTime); - // Assert.AreEqual(source.UpdateTime, app.UpdateTime); - Assert.AreEqual(source.Enabled, app.Enabled); - } - - [TestMethod()] - public async Task GetAllAppsAsyncTest() - { - fsq.Delete().Where("1=1").ExecuteAffrows() ; - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - Assert.IsTrue(result); - var id1 = Guid.NewGuid().ToString(); - var source1 = new Data.Entity.App - { - Id = id1, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result1 = await service.AddAsync(source1); - Assert.IsTrue(result1); - - var apps = await service.GetAllAppsAsync(); - Assert.IsNotNull(apps); - Assert.AreEqual(2, apps.Count); - - - } - - [TestMethod()] - public async Task UpdateAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - Assert.IsTrue(result); - - source.Name = "new name"; - source.Secret = "new sec"; - source.CreateTime = DateTime.Now.AddDays(1); - source.UpdateTime = DateTime.Now.AddDays(1); - source.Enabled = false; - - var result1 = await service.UpdateAsync(source); - Assert.IsTrue(result1); - - var app = fsq.Select(new - { - Id = id - }).ToOne(); - - Assert.AreEqual(source.Id, app.Id); - Assert.AreEqual(source.Name, app.Name); - Assert.AreEqual(source.Secret, app.Secret); - // Assert.AreEqual(source.CreateTime, app.CreateTime); - // Assert.AreEqual(source.UpdateTime, app.UpdateTime); - Assert.AreEqual(source.Enabled, app.Enabled); - } - - [TestMethod()] - public async Task CountEnabledAppsAsyncTest() - { - fsq.Delete().Where("1=1").ExecuteAffrows(); - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true - }; - var result = await service.AddAsync(source); - Assert.IsTrue(result); - var id1 = Guid.NewGuid().ToString(); - var source1 = new Data.Entity.App - { - Id = id1, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = false - }; - var result1 = await service.AddAsync(source1); - Assert.IsTrue(result1); - - var count = await service.CountEnabledAppsAsync(); - Assert.AreEqual(1, count); - } - [TestMethod()] - public async Task GetAllInheritancedAppsAsyncTest() - { - fsq.Delete().Where("1=1").ExecuteAffrows(); - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true, - Type = AppType.PRIVATE - }; - var source1 = new Data.Entity.App - { - Id = Guid.NewGuid().ToString(), - Name = "xxx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true, - Type = AppType.PRIVATE - }; - var source2 = new Data.Entity.App - { - Id = Guid.NewGuid().ToString(), - Name = "xxxx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true, - Type = AppType.Inheritance - }; - var source3 = new Data.Entity.App - { - Id = Guid.NewGuid().ToString(), - Name = "xxxx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = false, - Type = AppType.Inheritance - }; - var result = await service.AddAsync(source); - await service.AddAsync(source1); - await service.AddAsync(source2); - await service.AddAsync(source3); - - Assert.IsTrue(result); - - var apps = await service.GetAllInheritancedAppsAsync(); - - Assert.AreEqual(2, apps.Count); - } - [TestMethod()] - public async Task GetInheritancedAppsAsyncTest() - { - fsq.Delete().Where("1=1").ExecuteAffrows(); - fsq.Delete().Where("1=1").ExecuteAffrows(); - - var id = Guid.NewGuid().ToString(); - var source = new Data.Entity.App - { - Id = id, - Name = "xx", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true, - Type = AppType.PRIVATE - }; - var source1 = new Data.Entity.App - { - Id = Guid.NewGuid().ToString(), - Name = "xx1", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true, - Type = AppType.Inheritance - }; - var source2 = new Data.Entity.App - { - Id = Guid.NewGuid().ToString(), - Name = "xx2", - Secret = "sec", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Enabled = true, - Type = AppType.Inheritance - }; - // - var appInher = new AppInheritanced(); - appInher.Id = Guid.NewGuid().ToString(); - appInher.AppId = source.Id; - appInher.InheritancedAppId = source1.Id; - appInher.Sort = 1; - var appInher1 = new AppInheritanced(); - appInher1.Id = Guid.NewGuid().ToString(); - appInher1.AppId = source.Id; - appInher1.InheritancedAppId = source2.Id; - appInher1.Sort = 2; - - var result = await service.AddAsync(source); - await service.AddAsync(source1); - await service.AddAsync(source2); - fsq.Insert(appInher).ExecuteAffrows(); - fsq.Insert(appInher1).ExecuteAffrows(); - - Assert.IsTrue(result); - - var apps = await service.GetInheritancedAppsAsync(source.Id); - - Assert.AreEqual(2, apps.Count); - } - [TestCleanup] - public void Clean() - { - freeSqlContext.Dispose(); - fsq.Dispose(); - } } } \ No newline at end of file