public void DataContextTest() { var context = new LR.Repositories.DataContext(); var props = context.GetType().GetProperties().Where(p => p.PropertyType.IsGenericType).ToArray(); var arry = new object[props.Length]; for (int i = 0; i < props.Length; i++) { var value = props[i].GetValue(context); arry[i] = value.GetType().GetMethod("GetList", new Type[0])?.Invoke(value, null); } Assert.IsTrue(arry.All(p => p != null)); }
public void StaffAddTest() { var context = new LR.Repositories.DataContext(); var list = new List <LR.Entity.Staff>(); string name = "李四"; int index = 0; Random r = new Random(); LR.Entity.Staff staff = null; for (int i = 0; i < 10; i++) { staff = new Entity.Staff { ID = Guid.NewGuid(), Name = $"{name}{index++}", ReferrerID = staff?.ID ?? new Guid() }; list.Add(staff); list.Add(new Entity.Staff { ID = Guid.NewGuid(), Name = $"{name}{index++}", ReferrerID = staff.ID }); if (r.Next(0, 2) == 1) { list.Add(staff = new Entity.Staff { ID = Guid.NewGuid(), Name = $"{name}{index++}", ReferrerID = staff.ID }); } } context.Staffs.InsertRange(list.Select(p => { p.IdenNo = ""; p.MobileNo = ""; p.State = Entity.DataState.Normal; return(p); }).ToArray()); Assert.IsTrue(context.Staffs.Count(p => true) > 0); }
public void UpdateByDicTest() { using (var context = new LR.Repositories.DataContext()) { var list = context.RoyaltyConfigs.GetList(); var random = list[new Random().Next(0, list.Count)].ID; var old = context.RoyaltyConfigs.GetSingle(p => p.ID == random); context.Context.Updateable <Entity.RoyaltyConfig>(new Dictionary <string, object> { ["Percent"] = 13.66m, ["ModifyDate"] = DateTime.Now }).Where(p => p.ID == old.ID).ExecuteCommand(); var news = context.RoyaltyConfigs.GetSingle(p => p.ID == old.ID); Assert.IsTrue(news.Percent == 13.66m && old.CreateDate == news.CreateDate); } }
public void UpdateTest() { using (var context = new LR.Repositories.DataContext()) { var list = context.RoyaltyConfigs.GetList(); var random = list[new Random().Next(0, list.Count)].ID; var old = context.RoyaltyConfigs.GetSingle(p => p.ID == random); context.Context.Updateable <Entity.RoyaltyConfig>(item => new Entity.RoyaltyConfig { Percent = 1.55m, ModifyDate = DateTime.Now }).Where(p => p.ID == old.ID).ExecuteCommand(); var news = context.RoyaltyConfigs.GetSingle(p => p.ID == random); Assert.IsTrue(news.Percent == 1.55m && old.CreateDate == news.CreateDate); } }
public void WorkgroyManagerCategoryAddTest() { var context = new LR.Repositories.DataContext(true); if (context.WorkGroupManagerCategories.Count(p => p.State == 200) == 0) { context.WorkGroupManagerCategories.Insert(new Entity.WorkGroupManagerCategory { ID = Guid.NewGuid(), Name = "妈咪", State = Entity.DataState.Normal }); context.WorkGroupManagerCategories.Insert(new Entity.WorkGroupManagerCategory { ID = Guid.NewGuid(), Name = "助理", State = Entity.DataState.Normal }); } Assert.IsTrue(context.WorkGroupManagerCategories.Count(p => p.State == 200) == 2); }
public void StaffLevelInitTest() { var context = new LR.Repositories.DataContext(); if (context.StaffLevels.Count(t => true) == 0) { var a = new LR.Entity.StaffLevel { ID = Guid.NewGuid(), Name = "初级", MinCount = 2, Order = 0, State = LR.Entity.DataState.Normal }; var b = new LR.Entity.StaffLevel { ID = Guid.NewGuid(), Name = "中级", MinCount = 2, Order = 1, State = LR.Entity.DataState.Normal }; var c = new LR.Entity.StaffLevel { ID = Guid.NewGuid(), Name = "高级", MinCount = 2, Order = 2, State = LR.Entity.DataState.Normal }; context.StaffLevels.InsertRange(new[] { a, b, c }); } Assert.IsTrue(context.StaffLevels.Count(p => true) == 3); }
public void DataContextTranTest() { using (var context1 = new LR.Repositories.DataContext()) { try { context1.Context.Ado.BeginTran(); context1.ConsumeDatas.Delete(p => true); context1.ConsumeDatas.Insert(new Entity.ConsumeData { Amount = 100, ID = Guid.NewGuid(), RoomID = Guid.NewGuid(), StaffID = Guid.NewGuid(), State = 100 }); context1.ConsumeDatas.Insert(new Entity.ConsumeData { Amount = 100, ID = Guid.NewGuid(), RoomID = Guid.NewGuid(), StaffID = Guid.NewGuid(), State = 100 }); context1.Context.Ado.CommitTran(); } catch (Exception e) { context1.Context.Ado.RollbackTran(); throw e; } finally { Assert.IsTrue(context1.ConsumeDatas.Count(p => true) == 2); } } }
public void RoomAddTest() { var context = new LR.Repositories.DataContext(true); var roomcategory = new RoomCategory { ID = Guid.NewGuid(), Name = "一等", State = LR.Entity.DataState.Normal, MinCharge = 200 }; context.RoomCategories.Insert(roomcategory); context.Rooms.Insert(new Room { CategoryID = roomcategory.ID, ID = Guid.NewGuid(), No = "001", Name = "歌厅", State = DataState.Normal, Summary = "ceshi" }); Assert.IsTrue(context.Rooms.Count(p => true) > 0); }