diff --git a/test/AgileConfig.Server.ServiceTests/mongodb/AppServiceTests.cs b/test/AgileConfig.Server.ServiceTests/mongodb/AppServiceTests.cs new file mode 100644 index 00000000..47a5711c --- /dev/null +++ b/test/AgileConfig.Server.ServiceTests/mongodb/AppServiceTests.cs @@ -0,0 +1,32 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using AgileConfig.Server.ServiceTests.sqlite; +using AgileConfig.Server.Data.Repository.Mongodb; + +namespace AgileConfig.Server.ServiceTests.mongodb +{ + [TestClass()] + public class AppServiceTests_mongo : AppServiceTests + { + public override void ClearData() + { + var repository = new AppRepository(conn); + var entities = repository.AllAsync().Result; + foreach (var entity in entities) + { + repository.DeleteAsync(entity).Wait(); + } + } + + string conn = "mongodb://192.168.0.125:27017/agile_config_1"; + + public override Dictionary GetConfigurationData() + { + var dict = base.GetConfigurationData(); + dict["db:provider"] = "mongodb"; + dict["db:conn"] = conn; + + return dict; + } + } +} \ No newline at end of file diff --git a/test/AgileConfig.Server.ServiceTests/mongodb/ConfigServiceTests.cs b/test/AgileConfig.Server.ServiceTests/mongodb/ConfigServiceTests.cs index b0f7f02e..c3a929f1 100644 --- a/test/AgileConfig.Server.ServiceTests/mongodb/ConfigServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/mongodb/ConfigServiceTests.cs @@ -1,929 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using AgileConfig.Server.Data.Abstraction; -using AgileConfig.Server.Data.Abstraction.DbProvider; -using AgileConfig.Server.Data.Entity; -using AgileConfig.Server.Data.Freesql; -using AgileConfig.Server.Data.Mongodb; -using AgileConfig.Server.Data.Repository.Mongodb; -using AgileConfig.Server.Data.Repository.Selector; -using AgileConfig.Server.IService; -using AgileConfig.Server.Service; -using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using AgileConfig.Server.Data.Repository.Mongodb; +using AgileConfig.Server.ServiceTests.sqlite; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace AgileConfig.Server.ServiceTests.mongodb; +using System.Collections.Generic; -[TestClass] -public class ConfigServiceTests : Basic +namespace AgileConfig.Server.ServiceTests.mongodb { - IConfigService service = null; - - - [TestInitialize] - public void TestInitialize() - { - service = GetService(); - } - - - [TestCleanup] - public void Clean() - { - } - - [TestMethod()] - public async Task AddAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var config = await ConfigRepository.GetAsync(id); - - - Assert.IsTrue(result); - Assert.IsNotNull(config); - - Assert.AreEqual(source.Id, config.Id); - Assert.AreEqual(source.Group, config.Group); - Assert.AreEqual(source.Key, config.Key); - Assert.AreEqual(source.Value, config.Value); - Assert.AreEqual(source.Description, config.Description); - Assert.AreEqual(source.AppId, config.AppId); - Assert.AreEqual(source.CreateTime.ToString("yyyy/MM/dd HH:mm:ss"), - config.CreateTime.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(source.UpdateTime?.ToString("yyyy/MM/dd HH:mm:ss"), - config.UpdateTime?.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(source.Status, config.Status); - Assert.AreEqual(source.OnlineStatus, config.OnlineStatus); - } - - [TestMethod()] - public async Task UpdateAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - - source.AppId = "1"; - source.Group = "1"; - source.Key = "1"; - source.Value = "1"; - source.Description = "1"; - source.CreateTime = DateTime.Now; - source.UpdateTime = DateTime.Now; - source.Status = ConfigStatus.Enabled; - source.OnlineStatus = OnlineStatus.WaitPublish; - - var result1 = await service.UpdateAsync(source, ""); - var config = await ConfigRepository.GetAsync(id); - - Assert.IsTrue(result1); - Assert.IsNotNull(config); - - Assert.AreEqual(source.Id, config.Id); - Assert.AreEqual(source.Group, config.Group); - Assert.AreEqual(source.Key, config.Key); - Assert.AreEqual(source.Value, config.Value); - Assert.AreEqual(source.Description, config.Description); - Assert.AreEqual(source.AppId, config.AppId); - Assert.AreEqual(source.CreateTime.ToString("yyyy/MM/dd HH:mm:ss"), - config.CreateTime.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(source.UpdateTime?.ToString("yyyy/MM/dd HH:mm:ss"), - config.UpdateTime?.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(source.Status, config.Status); - Assert.AreEqual(source.OnlineStatus, config.OnlineStatus); - } - - [TestMethod()] - public async Task UpdateAsyncListTest() + [TestClass()] + public class ConfigServiceTests_mongo : ConfigServiceTests { - var ids = Enumerable.Range(0, 10).ToDictionary(x => x, _ => Guid.NewGuid().ToString()); - var list = Enumerable.Range(0, 10).Select(x => new Config + public override void ClearData() { - AppId = "001", - Id = ids[x], - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }).ToList(); - - var result = await service.AddRangeAsync(list, ""); - Assert.IsTrue(result); - - foreach (var item in list) - { - var index = list.IndexOf(item); - item.AppId = "1" + index; - item.Group = "1" + index; - item.Key = "1" + index; - item.Value = "1" + index; - item.Description = "1"; - item.CreateTime = DateTime.Now; - item.UpdateTime = DateTime.Now; - item.Status = ConfigStatus.Enabled; - item.OnlineStatus = OnlineStatus.WaitPublish; + var repository = new ConfigRepository(conn); + var entities = repository.AllAsync().Result; + foreach (var entity in entities) + { + repository.DeleteAsync(entity).Wait(); + } } - var result1 = await service.UpdateAsync(list, ""); - var idsValue = ids.Select(x => x.Value).ToList(); - var dbConfigs = await ConfigRepository.QueryAsync(x => idsValue.Contains(x.Id)); + string conn = "mongodb://192.168.0.125:27017/agile_config_1"; - Assert.IsTrue(result1); - Assert.IsNotNull(dbConfigs); - Assert.IsTrue(dbConfigs.Count > 0); - - foreach (var item in list) + public override Dictionary GetConfigurationData() { - var current = dbConfigs.FirstOrDefault(x => x.Id == item.Id); - Assert.IsNotNull(current); + var dict = base.GetConfigurationData(); + dict["db:provider"] = "mongodb"; + dict["db:conn"] = conn; - Assert.AreEqual(item.Id, current.Id); - Assert.AreEqual(item.Group, current.Group); - Assert.AreEqual(item.Key, current.Key); - Assert.AreEqual(item.Value, current.Value); - Assert.AreEqual(item.Description, current.Description); - Assert.AreEqual(item.AppId, current.AppId); - Assert.AreEqual(item.CreateTime.ToString("yyyy/MM/dd HH:mm:ss"), - current.CreateTime.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(item.UpdateTime?.ToString("yyyy/MM/dd HH:mm:ss"), - current.UpdateTime?.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(item.Status, current.Status); - Assert.AreEqual(item.OnlineStatus, current.OnlineStatus); + return dict; } } - - [TestMethod()] - public async Task DeleteAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - - var result1 = await service.DeleteAsync(source, ""); - Assert.IsTrue(result1); - - var config = await ConfigRepository.GetAsync(id); - - Assert.IsNull(config); - } - - [TestMethod()] - public async Task DeleteAsyncTest1() - { - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - - var result1 = await service.DeleteAsync(id, ""); - Assert.IsTrue(result1); - - var config = await ConfigRepository.GetAsync(id); - - Assert.IsNull(config); - } - - [TestMethod()] - public async Task GetAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - - var config = await service.GetAsync(id, ""); - Assert.IsNotNull(config); - - Assert.AreEqual(source.Id, config.Id); - Assert.AreEqual(source.Group, config.Group); - Assert.AreEqual(source.Key, config.Key); - Assert.AreEqual(source.Value, config.Value); - Assert.AreEqual(source.Description, config.Description); - Assert.AreEqual(source.AppId, config.AppId); - Assert.AreEqual(source.CreateTime, config.CreateTime); - Assert.AreEqual(source.UpdateTime, config.UpdateTime); - Assert.AreEqual(source.Status, config.Status); - Assert.AreEqual(source.OnlineStatus, config.OnlineStatus); - } - - [TestMethod()] - public async Task GetAllConfigsAsyncTest() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - - var configs = await service.GetAllConfigsAsync(""); - Assert.IsNotNull(configs); - Assert.AreEqual(1, configs.Count); - } - - [TestMethod()] - public async Task GetByAppIdKeyTest() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var id2 = Guid.NewGuid().ToString(); - var source2 = new Config - { - AppId = "002", - Id = id2, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - var result2 = await service.AddAsync(source2, ""); - Assert.IsTrue(result2); - - var config = await service.GetByAppIdKeyEnv("001", "g", "k", "env"); - Assert.IsNotNull(config); - - var config1 = await service.GetByAppIdKeyEnv("002", "g", "k", "env"); - Assert.IsNull(config1); - } - - [TestMethod()] - public async Task GetByAppIdTest() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var id2 = Guid.NewGuid().ToString(); - var source2 = new Config - { - AppId = "002", - Id = id2, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - var result2 = await service.AddAsync(source2, ""); - Assert.IsTrue(result2); - - var configs = await service.GetByAppIdAsync("001", ""); - Assert.IsNotNull(configs); - Assert.AreEqual(1, configs.Count); - } - - [TestMethod()] - public async Task SearchTest() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "group", - Key = "key", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var id2 = Guid.NewGuid().ToString(); - var source2 = new Config - { - AppId = "002", - Id = id2, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - var result2 = await service.AddAsync(source2, ""); - Assert.IsTrue(result2); - - var configs = await service.Search("001", "", "", ""); - Assert.IsNotNull(configs); - Assert.AreEqual(1, configs.Count); - var configs1 = await service.Search("", "o", "", ""); - Assert.IsNotNull(configs1); - Assert.AreEqual(1, configs1.Count); - var configs2 = await service.Search("", "", "e", ""); - Assert.IsNotNull(configs2); - Assert.AreEqual(1, configs2.Count); - } - - [TestMethod()] - public async Task CountEnabledConfigsAsyncTest() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "group", - Key = "key", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var id2 = Guid.NewGuid().ToString(); - var source2 = new Config - { - AppId = "002", - Id = id2, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - var result2 = await service.AddAsync(source2, ""); - Assert.IsTrue(result2); - - var count = await service.CountEnabledConfigsAsync(); - Assert.AreEqual(1, count); - } - - [TestMethod()] - public async Task AppPublishedConfigsMd5Test() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "group", - Key = "key", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var id2 = Guid.NewGuid().ToString(); - var source2 = new Config - { - AppId = "002", - Id = id2, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - var result2 = await service.AddAsync(source2, ""); - Assert.IsTrue(result2); - - var md5 = await service.AppPublishedConfigsMd5("001", ""); - Assert.IsNotNull(md5); - } - - [TestMethod()] - public void AppPublishedConfigsMd5CacheTest() - { - } - - [TestMethod()] - public async Task GetPublishedConfigsByAppIdTest() - { - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "group", - Key = "key", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var id2 = Guid.NewGuid().ToString(); - var source2 = new Config - { - AppId = "002", - Id = id2, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - var result = await service.AddAsync(source, ""); - Assert.IsTrue(result); - var result1 = await service.AddAsync(source1, ""); - Assert.IsTrue(result1); - var result2 = await service.AddAsync(source2, ""); - Assert.IsTrue(result2); - - //var configs = await service.GetPublishedConfigsByAppId("001"); - //Assert.IsNotNull(configs); - //Assert.AreEqual(1, configs.Count); - } - - [TestMethod()] - public async Task AddRangeAsyncTest() - { - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Group = "group", - Key = "key", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Group = "g", - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online - }; - - var result = await service.AddRangeAsync(new List - { - source, - source1 - }, ""); - Assert.IsTrue(result); - - var config = await ConfigRepository.GetAsync(id); - Assert.IsNotNull(config); - var config1 = await ConfigRepository.GetAsync(id); - Assert.IsNotNull(config1); - } - - [TestMethod()] - public async Task GetPublishedConfigsByAppIdWithInheritanced_DictionaryTest() - { - var appAll = await AppRepository.AllAsync(); - await AppRepository.DeleteAsync(appAll); - - var all = await ConfigRepository.AllAsync(); - await ConfigRepository.DeleteAsync(all); - - var appInheritancedAll = await AppInheritancedRepository.AllAsync(); - await AppInheritancedRepository.DeleteAsync(appInheritancedAll); - - var app = new App(); - app.Id = "001"; - app.Name = "x"; - app.Enabled = true; - app.CreateTime = DateTime.Now; - app.UpdateTime = DateTime.Now; - app.Type = AppType.PRIVATE; - var app1 = new App(); - app1.Id = "002"; - app1.Name = "x"; - app1.Enabled = true; - app1.CreateTime = DateTime.Now; - app1.UpdateTime = DateTime.Now; - app.Type = AppType.Inheritance; - var id = Guid.NewGuid().ToString(); - var source = new Config - { - AppId = "001", - Id = id, - Key = "k", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var id1 = Guid.NewGuid().ToString(); - var source1 = new Config - { - AppId = "001", - Id = id1, - Key = "k1", - Value = "v1", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var source2 = new Config - { - AppId = "002", - Id = Guid.NewGuid().ToString(), - Key = "k2", - Value = "v", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var source3 = new Config - { - AppId = "002", - Id = Guid.NewGuid().ToString(), - Key = "k21", - Value = "v2", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var appref = new AppInheritanced(); - appref.AppId = app.Id; - appref.InheritancedAppId = app1.Id; - appref.Sort = 1; - appref.Id = Guid.NewGuid().ToString(); - - await AppRepository.InsertAsync(app); - await AppRepository.InsertAsync(app1); - await ConfigRepository.InsertAsync(source); - await ConfigRepository.InsertAsync(source1); - await ConfigRepository.InsertAsync(source2); - await ConfigRepository.InsertAsync(source3); - await AppInheritancedRepository.InsertAsync(appref); - - - var dict = await service.GetPublishedConfigsByAppIdWithInheritanced_Dictionary(app.Id, ""); - Assert.IsNotNull(dict); - Assert.AreEqual(4, dict.Keys.Count); - - Assert.IsTrue(dict.ContainsKey(source.Key)); - Assert.IsTrue(dict.ContainsKey(source1.Key)); - Assert.IsTrue(dict.ContainsKey(source2.Key)); - Assert.IsTrue(dict.ContainsKey(source3.Key)); - - Assert.IsTrue(dict[source.Key].Value == "v"); - Assert.IsTrue(dict[source1.Key].Value == "v1"); - Assert.IsTrue(dict[source2.Key].Value == "v"); - Assert.IsTrue(dict[source3.Key].Value == "v2"); - - var source4 = new Config - { - AppId = "001", - Id = Guid.NewGuid().ToString(), - Key = "k4", - Value = "v3", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - var source5 = new Config - { - AppId = "002", - Id = Guid.NewGuid().ToString(), - Key = "k4", - Value = "v2", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - - await ConfigRepository.InsertAsync(source4); - await ConfigRepository.InsertAsync(source5); - - dict = await service.GetPublishedConfigsByAppIdWithInheritanced_Dictionary(app.Id, ""); - Assert.IsNotNull(dict); - Assert.AreEqual(5, dict.Keys.Count); - - var config1 = dict["k4"]; - Assert.AreEqual(source4.Value, config1.Value); - - var app2 = new App(); - app2.Id = "003"; - app2.Name = "x"; - app2.Enabled = true; - app2.CreateTime = DateTime.Now; - app2.UpdateTime = DateTime.Now; - app2.Type = AppType.Inheritance; - await AppRepository.InsertAsync(app2); - var source6 = new Config - { - AppId = "003", - Id = Guid.NewGuid().ToString(), - Key = "k2", - Value = "k4444", - Description = "d", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online - }; - - - var appInheritancedAll2 = await AppInheritancedRepository.AllAsync(); - await AppInheritancedRepository.DeleteAsync(appInheritancedAll2); - await ConfigRepository.InsertAsync(source6); - await AppInheritancedRepository.InsertAsync(appref); - - - var appref1 = new AppInheritanced(); - appref1.AppId = app.Id; - appref1.InheritancedAppId = app2.Id; - appref1.Sort = 2; - appref1.Id = Guid.NewGuid().ToString(); - await AppInheritancedRepository.InsertAsync(appref1); - dict = await service.GetPublishedConfigsByAppIdWithInheritanced_Dictionary(app.Id, ""); - Assert.IsNotNull(dict); - Assert.AreEqual(5, dict.Keys.Count); - - config1 = dict["k2"]; - Assert.AreEqual(source6.Value, config1.Value); - } } \ No newline at end of file diff --git a/test/AgileConfig.Server.ServiceTests/mongodb/ServerNodeServiceTests.cs b/test/AgileConfig.Server.ServiceTests/mongodb/ServerNodeServiceTests.cs new file mode 100644 index 00000000..3681b027 --- /dev/null +++ b/test/AgileConfig.Server.ServiceTests/mongodb/ServerNodeServiceTests.cs @@ -0,0 +1,34 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using AgileConfig.Server.Service; +using System; +using System.Collections.Generic; +using AgileConfig.Server.ServiceTests.sqlite; +using AgileConfig.Server.Data.Repository.Mongodb; + +namespace AgileConfig.Server.ServiceTests.mongodb +{ + [TestClass()] + public class ServerNodeServiceTests_mongo: ServerNodeServiceTests + { + public override void ClearData() + { + var repository = new ServerNodeRepository(conn); + var entities = repository.AllAsync().Result; + foreach (var log in entities) + { + repository.DeleteAsync(log).Wait(); + } + } + + string conn = "mongodb://192.168.0.125:27017/agile_config_1"; + + public override Dictionary GetConfigurationData() + { + var dict = base.GetConfigurationData(); + dict["db:provider"] = "mongodb"; + dict["db:conn"] = conn; + + return dict; + } + } +} \ No newline at end of file diff --git a/test/AgileConfig.Server.ServiceTests/mongodb/SettingServiceTests.cs b/test/AgileConfig.Server.ServiceTests/mongodb/SettingServiceTests.cs new file mode 100644 index 00000000..e8cabf2e --- /dev/null +++ b/test/AgileConfig.Server.ServiceTests/mongodb/SettingServiceTests.cs @@ -0,0 +1,25 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using AgileConfig.Server.ServiceTests.sqlite; + +namespace AgileConfig.Server.ServiceTests.mongodb +{ + [TestClass()] + public class SettingServiceTests_mongo : SettingServiceTests + { + public override void ClearData() + { + } + + string conn = "mongodb://192.168.0.125:27017/agile_config_1"; + + public override Dictionary GetConfigurationData() + { + var dict = base.GetConfigurationData(); + dict["db:provider"] = "mongodb"; + dict["db:conn"] = conn; + + return dict; + } + } +} \ No newline at end of file diff --git a/test/AgileConfig.Server.ServiceTests/mongodb/SysLogServiceTests.cs b/test/AgileConfig.Server.ServiceTests/mongodb/SysLogServiceTests.cs index 9872d267..665e2881 100644 --- a/test/AgileConfig.Server.ServiceTests/mongodb/SysLogServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/mongodb/SysLogServiceTests.cs @@ -3,215 +3,34 @@ using System.Threading.Tasks; using AgileConfig.Server.Data.Abstraction; using AgileConfig.Server.Data.Entity; +using AgileConfig.Server.Data.Repository.Mongodb; using AgileConfig.Server.IService; +using AgileConfig.Server.ServiceTests.sqlite; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AgileConfig.Server.ServiceTests.mongodb; [TestClass()] -public class SysLogServiceTests : Basic +public class SysLogServiceTests_mongo : SysLogServiceTests { - ISysLogService service = null; - - [TestInitialize] - public void TestInitialize() + public override void ClearData() { - service = GetService(); - } - - - [TestCleanup] - public void Clean() - { - } - - [TestMethod()] - public async Task AddSysLogAsyncTest() - { - var source = new SysLog + var repository = new SysLogRepository(conn); + var syslogs = repository.AllAsync().Result; + foreach (var log in syslogs) { - AppId = "001", - LogType = SysLogType.Normal, - LogTime = DateTime.Now, - LogText = "123" - }; - - var result = await service.AddSysLogAsync(source); - Assert.IsTrue(result); - - var log = await SysLogRepository.GetAsync(source.Id); - - Assert.IsNotNull(log); - - Assert.AreEqual(source.Id, log.Id); - Assert.AreEqual(source.AppId, log.AppId); - Assert.AreEqual(source.LogType, log.LogType); - Assert.AreEqual(source.LogTime, log.LogTime); - Assert.AreEqual(source.LogText, log.LogText); - } - - [TestMethod()] - public async Task AddSysLogTransactionAsyncTest() - { - var uowAccessor = GetService>(); - var uow = uowAccessor(""); - - var id = Guid.NewGuid().ToString(); - var source = new SysLog - { - Id = id, - AppId = "001", - LogType = SysLogType.Normal, - LogTime = DateTime.Now, - LogText = "123" - }; - - - try - { - SysLogRepository.Uow = uow; - uow?.Begin(); - await SysLogRepository.InsertAsync(source); - throw new Exception(); + repository.DeleteAsync(log).Wait(); } - catch (Exception e) - { - Console.WriteLine(e); - uow?.Rollback(); - } - finally - { - uow?.Dispose(); - } - - var log = await SysLogRepository.GetAsync(id); - - Assert.IsNull(log); - - - var uowAccessor2 = GetService>(); - var uow2 = uowAccessor2(""); - SysLogRepository.Uow = uow2; - uow2.Begin(); - await SysLogRepository.InsertAsync(source); - await uow2.SaveChangesAsync(); - var log2 = await SysLogRepository.GetAsync(id); - uow2.Dispose(); - - Assert.AreEqual(source.Id, log2.Id); - Assert.AreEqual(source.AppId, log2.AppId); - Assert.AreEqual(source.LogType, log2.LogType); - Assert.AreEqual(source.LogTime?.ToString("yyyy/MM/dd HH:mm:ss"), log2.LogTime?.ToString("yyyy/MM/dd HH:mm:ss")); - Assert.AreEqual(source.LogText, log2.LogText); - } - - - [TestMethod()] - public async Task AddRangeAsyncTest() - { - var source = new SysLog - { - AppId = "001", - LogType = SysLogType.Normal, - LogTime = DateTime.Now, - LogText = "123" - }; - var source1 = new SysLog - { - AppId = "002", - LogType = SysLogType.Warn, - LogTime = DateTime.Now, - LogText = "124" - }; - var result = await service.AddRangeAsync(new List - { - source, source1 - }); - Assert.IsTrue(result); - - var log = await SysLogRepository.GetAsync(source.Id); - Assert.IsNotNull(log); - Assert.AreEqual(source.Id, log.Id); - Assert.AreEqual(source.AppId, log.AppId); - Assert.AreEqual(source.LogType, log.LogType); - Assert.AreEqual(source.LogTime, log.LogTime); - Assert.AreEqual(source.LogText, log.LogText); - - var log1 = await SysLogRepository.GetAsync(source.Id); - Assert.IsNotNull(log1); - Assert.AreEqual(source1.Id, log1.Id); - Assert.AreEqual(source1.AppId, log1.AppId); - Assert.AreEqual(source1.LogType, log1.LogType); - Assert.AreEqual(source1.LogTime, log1.LogTime); - Assert.AreEqual(source1.LogText, log1.LogText); } + string conn = "mongodb://192.168.0.125:27017/agile_config_1"; - [TestMethod()] - public async Task CountTest() - { - var all = await SysLogRepository.AllAsync(); - await SysLogRepository.DeleteAsync(all); - - var source = new SysLog - { - AppId = "001", - LogType = SysLogType.Normal, - LogTime = DateTime.Now, - LogText = "123" - }; - var source1 = new SysLog - { - AppId = "002", - LogType = SysLogType.Warn, - LogTime = DateTime.Now, - LogText = "124" - }; - var result = await service.AddRangeAsync(new List - { - source, source1 - }); - Assert.IsTrue(result); - - var count = await service.Count("001", SysLogType.Normal, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1)); - Assert.AreEqual(1, count); - - var count1 = await service.Count("002", SysLogType.Warn, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1)); - Assert.AreEqual(0, count1); - } - - [TestMethod()] - public async Task SearchPageTest() + public override Dictionary GetConfigurationData() { - var all = await SysLogRepository.AllAsync(); - await SysLogRepository.DeleteAsync(all); - - var source = new SysLog - { - AppId = "001", - LogType = SysLogType.Normal, - LogTime = DateTime.Now, - LogText = "123" - }; - var source1 = new SysLog - { - AppId = "002", - LogType = SysLogType.Warn, - LogTime = DateTime.Now, - LogText = "124" - }; - var result = await service.AddRangeAsync(new List - { - source, source1 - }); - Assert.IsTrue(result); - - var page = await service.SearchPage("001", SysLogType.Normal, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1), - 1, 1); - Assert.AreEqual(1, page.Count); + var dict = base.GetConfigurationData(); + dict["db:provider"] = "mongodb"; + dict["db:conn"] = conn; - var page1 = await service.SearchPage("002", SysLogType.Warn, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1), - 0, 0); - Assert.AreEqual(0, page1.Count); + return dict; } } \ No newline at end of file diff --git a/test/AgileConfig.Server.ServiceTests/sqlite/AppServiceTests.cs b/test/AgileConfig.Server.ServiceTests/sqlite/AppServiceTests.cs index 19660930..05fb7bfc 100644 --- a/test/AgileConfig.Server.ServiceTests/sqlite/AppServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/sqlite/AppServiceTests.cs @@ -6,6 +6,7 @@ using AgileConfig.Server.IService; using AgileConfig.Server.Service; using Microsoft.Extensions.DependencyInjection; +using AgileConfig.Server.Data.Abstraction; namespace AgileConfig.Server.ServiceTests.sqlite { @@ -27,7 +28,7 @@ public override Dictionary GetConfigurationData() public void TestInitialize() { _appservice = _serviceProvider.GetService(); - _fsq.Delete().Where("1=1"); + ClearData(); } @@ -45,10 +46,7 @@ public async Task AddAsyncTest() Enabled = true }; var result = await _appservice.AddAsync(source); - var app = _fsq.Select(new - { - Id = id - }).ToOne(); + var app = await _appservice.GetAsync(source.Id); Assert.IsTrue(result); Assert.IsNotNull(app); @@ -79,13 +77,6 @@ public async Task DeleteAsyncTest() var delResult = await _appservice.DeleteAsync(source); Assert.IsTrue(delResult); - - var app = _fsq.Select(new - { - Id = id - }).ToOne(); - Assert.IsNull(app); - } [TestMethod()] @@ -107,10 +98,8 @@ public async Task DeleteAsyncTest1() var delResult = await _appservice.DeleteAsync(id); Assert.IsTrue(delResult); - var app = _fsq.Select(new - { - Id = id - }).ToOne(); + var app = await _appservice.GetAsync(source.Id); + Assert.IsNull(app); } @@ -137,15 +126,16 @@ public async Task GetAsyncTest() Assert.AreEqual(source.Id, app.Id); Assert.AreEqual(source.Name, app.Name); Assert.AreEqual(source.Secret, app.Secret); - Assert.AreEqual(source.CreateTime.ToString("yyyyMMddhhmmss"), app.CreateTime.ToString("yyyyMMddhhmmss")); - Assert.AreEqual(source.UpdateTime.Value.ToString("yyyyMMddhhmmss"), app.UpdateTime.Value.ToString("yyyyMMddhhmmss")); + Assert.AreEqual(source.CreateTime.ToString("yyyyMMddhhmm"), app.CreateTime.ToString("yyyyMMddhhmm")); + Assert.AreEqual(source.UpdateTime.Value.ToString("yyyyMMddhhmm"), app.UpdateTime.Value.ToString("yyyyMMddhhmm")); Assert.AreEqual(source.Enabled, app.Enabled); } [TestMethod()] public async Task GetAllAppsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + ClearData(); + var id = Guid.NewGuid().ToString(); var source = new App { @@ -203,10 +193,7 @@ public async Task UpdateAsyncTest() var result1 = await _appservice.UpdateAsync(source); Assert.IsTrue(result1); - var app = _fsq.Select(new - { - Id = id - }).ToOne(); + var app = await _appservice.GetAsync(source.Id); Assert.AreEqual(source.Id, app.Id); Assert.AreEqual(source.Name, app.Name); @@ -219,7 +206,8 @@ public async Task UpdateAsyncTest() [TestMethod()] public async Task CountEnabledAppsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); + var id = Guid.NewGuid().ToString(); var source = new App { @@ -252,7 +240,8 @@ public async Task CountEnabledAppsAsyncTest() [TestMethod()] public async Task GetAllInheritancedAppsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); + var id = Guid.NewGuid().ToString(); var source = new App { @@ -308,8 +297,7 @@ public async Task GetAllInheritancedAppsAsyncTest() [TestMethod()] public async Task GetInheritancedAppsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var id = Guid.NewGuid().ToString(); var source = new App @@ -357,8 +345,9 @@ public async Task GetInheritancedAppsAsyncTest() var result = await _appservice.AddAsync(source); await _appservice.AddAsync(source1); await _appservice.AddAsync(source2); - _fsq.Insert(appInher).ExecuteAffrows(); - _fsq.Insert(appInher1).ExecuteAffrows(); + + await _serviceProvider.GetService().InsertAsync(appInher); + await _serviceProvider.GetService().InsertAsync(appInher1); Assert.IsTrue(result); diff --git a/test/AgileConfig.Server.ServiceTests/sqlite/BasicTestService.cs b/test/AgileConfig.Server.ServiceTests/sqlite/BasicTestService.cs index b50ab940..b41e8058 100644 --- a/test/AgileConfig.Server.ServiceTests/sqlite/BasicTestService.cs +++ b/test/AgileConfig.Server.ServiceTests/sqlite/BasicTestService.cs @@ -1,5 +1,6 @@ using AgileConfig.Server.Common; using AgileConfig.Server.Data.Abstraction; +using AgileConfig.Server.Data.Entity; using AgileConfig.Server.Data.Freesql; using AgileConfig.Server.Data.Repository.Freesql; using AgileConfig.Server.Data.Repository.Selector; @@ -17,7 +18,6 @@ namespace AgileConfig.Server.ServiceTests.sqlite public class BasicTestService { protected ServiceProvider _serviceProvider; - protected IFreeSql _fsq = null; public virtual Dictionary GetConfigurationData() { @@ -29,6 +29,22 @@ public virtual Dictionary GetConfigurationData() }; } + public virtual void ClearData() + { + var factory = new EnvFreeSqlFactory(); + var fsq = factory.Create(""); + + fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + //fsq.Delete().Where("1=1").ExecuteAffrows(); + fsq.Delete().Where("1=1").ExecuteAffrows(); + } + public BasicTestService() { var config = new ConfigurationBuilder() @@ -36,9 +52,6 @@ public BasicTestService() .Build(); Global.Config = config; - var factory = new EnvFreeSqlFactory(); - _fsq = factory.Create(""); - var cache = new Mock(); IServiceCollection services = new ServiceCollection(); services.AddScoped(_ => cache.Object); @@ -54,41 +67,5 @@ public BasicTestService() Console.WriteLine("Run BasicTestService"); } - - private static void AddEnvRepositiroies(IServiceCollection sc) - { - sc.AddScoped>(sp => env => - { - var factory = sp.GetService(); - var fsq = factory.Create(env); - return new FreeSqlUow(fsq); - }); - - sc.AddScoped>(sp => env => - { - var factory = sp.GetService(); - return new ConfigPublishedRepository(factory.Create(env)); - }); - - sc.AddScoped>(sp => env => - { - var factory = sp.GetService(); - - return new ConfigRepository(factory.Create(env)); - }); - - sc.AddScoped>(sp => env => - { - var factory = sp.GetService(); - return new PublishDetailRepository(factory.Create(env)); - }); - - sc.AddScoped>(sp => env => - { - var factory = sp.GetService(); - return new PublishTimelineRepository(factory.Create(env)); - }); - } - } } diff --git a/test/AgileConfig.Server.ServiceTests/sqlite/ConfigServiceTests.cs b/test/AgileConfig.Server.ServiceTests/sqlite/ConfigServiceTests.cs index 54938173..a9bbd474 100644 --- a/test/AgileConfig.Server.ServiceTests/sqlite/ConfigServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/sqlite/ConfigServiceTests.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Caching.Memory; using Moq; using Microsoft.Extensions.DependencyInjection; +using AgileConfig.Server.Data.Abstraction; namespace AgileConfig.Server.ServiceTests.sqlite { @@ -30,7 +31,7 @@ public override Dictionary GetConfigurationData() public void TestInitialize() { _service = _serviceProvider.GetService(); - _fsq.Delete().Where("1=1"); + this.ClearData(); } @@ -54,10 +55,7 @@ public async Task AddAsyncTest() var result = await _service.AddAsync(source, ""); Assert.IsTrue(result); - var config = _fsq.Select(new - { - Id = id - }).ToOne(); + var config = await _service.GetAsync(source.Id, ""); Assert.IsTrue(result); Assert.IsNotNull(config); @@ -106,10 +104,7 @@ public async Task UpdateAsyncTest() source.OnlineStatus = OnlineStatus.WaitPublish; var result1 = await _service.UpdateAsync(source, ""); - var config = _fsq.Select(new - { - Id = id - }).ToOne(); + var config = await _service.GetAsync(source.Id, ""); Assert.IsTrue(result1); Assert.IsNotNull(config); @@ -150,10 +145,7 @@ public async Task DeleteAsyncTest() var result1 = await _service.DeleteAsync(source, ""); Assert.IsTrue(result1); - var config = _fsq.Select(new - { - Id = id - }).ToOne(); + var config = await _service.GetAsync(source.Id, ""); Assert.IsNull(config); } @@ -182,10 +174,7 @@ public async Task DeleteAsyncTest1() var result1 = await _service.DeleteAsync(id, ""); Assert.IsTrue(result1); - var config = _fsq.Select(new - { - Id = id - }).ToOne(); + var config = await _service.GetAsync(source.Id, ""); Assert.IsNull(config); } @@ -229,7 +218,7 @@ public async Task GetAsyncTest() [TestMethod()] public async Task GetAllConfigsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var env = "DEV"; var id = Guid.NewGuid().ToString(); @@ -275,7 +264,8 @@ public async Task GetAllConfigsAsyncTest() [TestMethod()] public async Task GetByAppIdKeyTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); + var env = "DEV"; var id = Guid.NewGuid().ToString(); var source = new Config @@ -339,8 +329,7 @@ public async Task GetByAppIdKeyTest() [TestMethod()] public async Task GetByAppIdTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); - + this.ClearData(); var id = Guid.NewGuid().ToString(); var env = "DEV"; var source = new Config @@ -402,7 +391,7 @@ public async Task GetByAppIdTest() [TestMethod()] public async Task SearchTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var env = "DEV"; var id = Guid.NewGuid().ToString(); var source = new Config @@ -470,7 +459,7 @@ public async Task SearchTest() [TestMethod()] public async Task CountEnabledConfigsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); string env = "DEV"; var id = Guid.NewGuid().ToString(); @@ -485,7 +474,7 @@ public async Task CountEnabledConfigsAsyncTest() CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online, + OnlineStatus = OnlineStatus.WaitPublish, Env = env }; var id1 = Guid.NewGuid().ToString(); @@ -500,7 +489,7 @@ public async Task CountEnabledConfigsAsyncTest() CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online, + OnlineStatus = OnlineStatus.WaitPublish, Env = env }; var id2 = Guid.NewGuid().ToString(); @@ -515,16 +504,19 @@ public async Task CountEnabledConfigsAsyncTest() CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online, + OnlineStatus = OnlineStatus.WaitPublish, Env = env }; - var result = await _service.AddAsync(source, ""); + var result = await _service.AddAsync(source, env); Assert.IsTrue(result); - var result1 = await _service.AddAsync(source1, ""); + var result1 = await _service.AddAsync(source1, env); Assert.IsTrue(result1); - var result2 = await _service.AddAsync(source2, ""); + var result2 = await _service.AddAsync(source2, env); Assert.IsTrue(result2); + await _service.Publish("001", new string[] { }, "", "", env); + await _service.Publish("002", new string[] { }, "", "", env); + var count = await _service.CountEnabledConfigsAsync(); Assert.AreEqual(1, count); } @@ -532,8 +524,9 @@ public async Task CountEnabledConfigsAsyncTest() [TestMethod()] public async Task AppPublishedConfigsMd5Test() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); + string env = "DEV"; var id = Guid.NewGuid().ToString(); var source = new Config { @@ -546,7 +539,8 @@ public async Task AppPublishedConfigsMd5Test() CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Status = ConfigStatus.Enabled, - OnlineStatus = OnlineStatus.Online + OnlineStatus = OnlineStatus.Online, + Env = env }; var id1 = Guid.NewGuid().ToString(); var source1 = new Config @@ -560,7 +554,9 @@ public async Task AppPublishedConfigsMd5Test() CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online + OnlineStatus = OnlineStatus.Online, + Env = env + }; var id2 = Guid.NewGuid().ToString(); var source2 = new Config @@ -574,16 +570,17 @@ public async Task AppPublishedConfigsMd5Test() CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Status = ConfigStatus.Deleted, - OnlineStatus = OnlineStatus.Online + OnlineStatus = OnlineStatus.Online, + Env = env }; - var result = await _service.AddAsync(source, ""); + var result = await _service.AddAsync(source, env); Assert.IsTrue(result); - var result1 = await _service.AddAsync(source1, ""); + var result1 = await _service.AddAsync(source1, env); Assert.IsTrue(result1); - var result2 = await _service.AddAsync(source2, ""); + var result2 = await _service.AddAsync(source2, env); Assert.IsTrue(result2); - var md5 = await _service.AppPublishedConfigsMd5("001", ""); + var md5 = await _service.AppPublishedConfigsMd5("001", env); Assert.IsNotNull(md5); } @@ -595,7 +592,7 @@ public void AppPublishedConfigsMd5CacheTest() [TestMethod()] public async Task GetPublishedConfigsByAppIdTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var id = Guid.NewGuid().ToString(); var source = new Config @@ -646,9 +643,6 @@ public async Task GetPublishedConfigsByAppIdTest() var result2 = await _service.AddAsync(source2, ""); Assert.IsTrue(result2); - //var configs = await service.GetPublishedConfigsByAppId("001"); - //Assert.IsNotNull(configs); - //Assert.AreEqual(1, configs.Count); } [TestMethod()] @@ -689,27 +683,16 @@ public async Task AddRangeAsyncTest() }, ""); Assert.IsTrue(result); - var config = _fsq.Select(new - { - Id = id - }).ToOne(); + var config = await _service.GetAsync(id, ""); Assert.IsNotNull(config); - var config1 = _fsq.Select(new - { - Id = id1 - }).ToOne(); + var config1 = await _service.GetAsync(id1, ""); Assert.IsNotNull(config1); } [TestMethod()] public async Task GetPublishedConfigsByAppIdWithInheritanced_DictionaryTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); - _fsq.Delete().Where("1=1").ExecuteAffrows(); - _fsq.Delete().Where("1=1").ExecuteAffrows(); - _fsq.Delete().Where("1=1").ExecuteAffrows(); - _fsq.Delete().Where("1=1").ExecuteAffrows(); - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); string env = "DEV"; @@ -788,15 +771,15 @@ public async Task GetPublishedConfigsByAppIdWithInheritanced_DictionaryTest() appref.Sort = 1; appref.Id = Guid.NewGuid().ToString(); - _fsq.Insert(app).ExecuteAffrows(); - _fsq.Insert(app1).ExecuteAffrows(); - _fsq.Insert(appref).ExecuteAffrows(); + await _serviceProvider.GetService().AddAsync(app); + await _serviceProvider.GetService().AddAsync(app1); + await _serviceProvider.GetService().InsertAsync(appref); // 插入4个config,2个app 001,2个app 002 - _fsq.Insert(source).ExecuteAffrows(); - _fsq.Insert(source1).ExecuteAffrows(); - _fsq.Insert(source2).ExecuteAffrows(); - _fsq.Insert(source3).ExecuteAffrows(); + await _service.AddAsync(source, env); + await _service.AddAsync(source1, env); + await _service.AddAsync(source2, env); + await _service.AddAsync(source3, env); await _service.Publish(app1.Id, new string[] { }, "", "", env); await _service.Publish(app.Id, new string[] { }, "", "", env); @@ -842,8 +825,8 @@ public async Task GetPublishedConfigsByAppIdWithInheritanced_DictionaryTest() Env = env }; // 插入2个config,1个app 001,1个app 002,keyvalue相同,app 001 优先级高 - _fsq.Insert(source4).ExecuteAffrows(); - _fsq.Insert(source5).ExecuteAffrows(); + await _service.AddAsync(source4, env); + await _service.AddAsync(source5, env); await _service.Publish(app1.Id, new string[] { }, "", "", env); await _service.Publish(app.Id, new string[] { }, "", "", env); @@ -862,17 +845,17 @@ public async Task GetPublishedConfigsByAppIdWithInheritanced_DictionaryTest() app2.CreateTime = DateTime.Now; app2.UpdateTime = DateTime.Now; app2.Type = AppType.Inheritance; - _fsq.Insert(app2).ExecuteAffrows(); + await _serviceProvider.GetService().AddAsync(app2); // 插入1个app 003 - _fsq.Delete().Where("1=1").ExecuteAffrows(); + await _serviceProvider.GetService().DeleteAsync(appref); var appref1 = new AppInheritanced(); appref1.AppId = app.Id; appref1.InheritancedAppId = app2.Id; // app 001 继承 app 003 appref1.Sort = 2; appref1.Id = Guid.NewGuid().ToString(); - _fsq.Insert(appref1).ExecuteAffrows(); + await _serviceProvider.GetService().InsertAsync(appref1); var source6 = new Config { @@ -887,7 +870,7 @@ public async Task GetPublishedConfigsByAppIdWithInheritanced_DictionaryTest() OnlineStatus = OnlineStatus.WaitPublish, Env = env }; - _fsq.Insert(source6).ExecuteAffrows(); + await _service.AddAsync(source6, env); await _service.Publish(app2.Id, new string[] { }, "", "", env); // 发布app 003 dict = await _service.GetPublishedConfigsByAppIdWithInheritanced_Dictionary(app.Id, env); diff --git a/test/AgileConfig.Server.ServiceTests/sqlite/ServerNodeServiceTests.cs b/test/AgileConfig.Server.ServiceTests/sqlite/ServerNodeServiceTests.cs index dec1baa8..315daa49 100644 --- a/test/AgileConfig.Server.ServiceTests/sqlite/ServerNodeServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/sqlite/ServerNodeServiceTests.cs @@ -27,13 +27,13 @@ public override Dictionary GetConfigurationData() public void TestInitialize() { _serverNodeService = _serviceProvider.GetService(); - _fsq.Delete().Where("1=1"); + this.ClearData(); } [TestMethod()] public async Task AddAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new ServerNode(); source.Id = "1"; @@ -45,10 +45,7 @@ public async Task AddAsyncTest() var result = await _serverNodeService.AddAsync(source); Assert.IsTrue(result); - var node = _fsq.Select(new - { - Address = "1" - }).ToOne(); + var node = await _serverNodeService.GetAsync("1"); Assert.IsNotNull(node); Assert.AreEqual(source.Id, node.Id); @@ -61,7 +58,7 @@ public async Task AddAsyncTest() [TestMethod()] public async Task DeleteAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new ServerNode(); source.Id = "1"; @@ -76,17 +73,15 @@ public async Task DeleteAsyncTest() var result1 = await _serverNodeService.DeleteAsync(source); Assert.IsTrue(result1); - var node = _fsq.Select(new - { - Address = "1" - }).ToOne(); + var node = await _serverNodeService.GetAsync("1"); + Assert.IsNull(node); } [TestMethod()] public async Task DeleteAsyncTest1() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new ServerNode(); source.Id = "1"; @@ -101,17 +96,15 @@ public async Task DeleteAsyncTest1() var result1 = await _serverNodeService.DeleteAsync(source.Id); Assert.IsTrue(result1); - var node = _fsq.Select(new - { - Address = "1" - }).ToOne(); + var node = await _serverNodeService.GetAsync("1"); + Assert.IsNull(node); } [TestMethod()] public async Task GetAllNodesAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new ServerNode(); source.Id = "1"; @@ -132,7 +125,7 @@ public async Task GetAllNodesAsyncTest() [TestMethod()] public async Task GetAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new ServerNode(); source.Id = "1"; @@ -156,7 +149,7 @@ public async Task GetAsyncTest() [TestMethod()] public async Task UpdateAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new ServerNode(); source.Id = "1"; diff --git a/test/AgileConfig.Server.ServiceTests/sqlite/SettingServiceTests.cs b/test/AgileConfig.Server.ServiceTests/sqlite/SettingServiceTests.cs index be5b515d..52eb9dfa 100644 --- a/test/AgileConfig.Server.ServiceTests/sqlite/SettingServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/sqlite/SettingServiceTests.cs @@ -26,7 +26,7 @@ public override Dictionary GetConfigurationData() public void TestInitialize() { _settingService = _serviceProvider.GetService(); - _fsq.Delete().Where("1=1"); + this.ClearData(); } @@ -41,10 +41,7 @@ public async Task AddAsyncTest() var result = await _settingService.AddAsync(source); Assert.IsTrue(result); - var setting = _fsq.Select(new - { - Id = id - }).ToOne(); + var setting = await _settingService.GetAsync(source.Id); Assert.IsNotNull(setting); @@ -66,10 +63,7 @@ public async Task DeleteAsyncTest() result = await _settingService.DeleteAsync(source); Assert.IsTrue(result); - var setting = _fsq.Select(new - { - Id = id - }).ToOne(); + var setting = await _settingService.GetAsync(source.Id); Assert.IsNull(setting); } @@ -88,10 +82,7 @@ public async Task DeleteAsyncTest1() result = await _settingService.DeleteAsync(id); Assert.IsTrue(result); - var setting = _fsq.Select(new - { - Id = id - }).ToOne(); + var setting = await _settingService.GetAsync(source.Id); Assert.IsNull(setting); } @@ -118,8 +109,9 @@ public async Task GetAsyncTest() [TestMethod()] public async Task GetAllSettingsAsyncTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); - var id = Guid.NewGuid().ToString(); + this.ClearData(); + + var id = Guid.NewGuid().ToString(); var source = new Setting(); source.Id = id; source.Value = "123"; @@ -137,8 +129,6 @@ public async Task GetAllSettingsAsyncTest() var settings = await _settingService.GetAllSettingsAsync(); Assert.IsNotNull(settings); - - Assert.AreEqual(2, settings.Count); } [TestMethod()] diff --git a/test/AgileConfig.Server.ServiceTests/sqlite/SysLogServiceTests.cs b/test/AgileConfig.Server.ServiceTests/sqlite/SysLogServiceTests.cs index ade1033b..877798c6 100644 --- a/test/AgileConfig.Server.ServiceTests/sqlite/SysLogServiceTests.cs +++ b/test/AgileConfig.Server.ServiceTests/sqlite/SysLogServiceTests.cs @@ -7,6 +7,7 @@ using AgileConfig.Server.IService; using Microsoft.Extensions.DependencyInjection; using MongoDB.Driver.Linq; +using AgileConfig.Server.Data.Abstraction; namespace AgileConfig.Server.ServiceTests.sqlite { @@ -28,8 +29,8 @@ public override Dictionary GetConfigurationData() public void TestInitialize() { _syslogservice = _serviceProvider.GetService(); - _fsq.Delete().Where("1=1"); - } + this.ClearData(); + } [TestMethod()] @@ -46,10 +47,7 @@ public async Task AddSysLogAsyncTest() var result = await _syslogservice.AddSysLogAsync(source); Assert.IsTrue(result); - var log = _fsq.Select(new - { - source.Id - }).ToOne(); + var log = await _serviceProvider.GetService().GetAsync(source.Id); Assert.IsNotNull(log); @@ -83,10 +81,8 @@ public async Task AddRangeAsyncTest() }); Assert.IsTrue(result); - var log = _fsq.Select(new - { - source.Id - }).ToOne(); + var log = await _serviceProvider.GetService().GetAsync(source.Id); + Assert.IsNotNull(log); Assert.AreEqual(source.Id, log.Id); Assert.AreEqual(source.AppId, log.AppId); @@ -94,10 +90,8 @@ public async Task AddRangeAsyncTest() Assert.AreEqual(source.LogTime.Value.ToString("yyyyMMddHHmmss"), log.LogTime.Value.ToString("yyyyMMddHHmmss")); Assert.AreEqual(source.LogText, log.LogText); - var log1 = _fsq.Select(new - { - source1.Id - }).ToOne(); + var log1 = await _serviceProvider.GetService().GetAsync(source1.Id); + Assert.IsNotNull(log1); Assert.AreEqual(source1.Id, log1.Id); Assert.AreEqual(source1.AppId, log1.AppId); @@ -110,8 +104,8 @@ public async Task AddRangeAsyncTest() [TestMethod()] public async Task CountTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); - + this.ClearData(); + var source = new SysLog { AppId = "001", @@ -141,7 +135,7 @@ public async Task CountTest() [TestMethod()] public async Task SearchPageTest() { - _fsq.Delete().Where("1=1").ExecuteAffrows(); + this.ClearData(); var source = new SysLog { @@ -157,11 +151,17 @@ public async Task SearchPageTest() LogTime = DateTime.Now, LogText = "124" }; - var result = await _syslogservice.AddRangeAsync(new List { - source, source1 - }); + var result = await _syslogservice.AddSysLogAsync(source); + Assert.IsTrue(result); + result = await _syslogservice.AddSysLogAsync(source1); Assert.IsTrue(result); + var log = await _serviceProvider.GetService().GetAsync(source.Id); + Assert.IsNotNull(log); + + var log1 = await _serviceProvider.GetService().GetAsync(source1.Id); + Assert.IsNotNull(log1); + var page = await _syslogservice.SearchPage("001", SysLogType.Normal, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1), 1, 0); Assert.AreEqual(1, page.Count);