public void EIT_StringId_IntWithString_Insert() { var repo = RF.ResolveInstance <HouseMerchantRepository>(); var houseRepo = RF.ResolveInstance <HouseRepository>(); using (RF.TransactionScope(repo)) { var house = new House { Id = "House1" }; houseRepo.Save(house); var house2 = new House { Id = "House2" }; houseRepo.Save(house2); var merchant = new HouseMerchant { MerchantItemList = { new MerchantItem { House = house }, new MerchantItem { House = house2 } } }; merchant.Id = "Merchant1"; repo.Save(merchant); } }
public void SSPT_GetValue_T() { var repo = RF.ResolveInstance <GlobalSettingRepository>(); using (RF.TransactionScope(repo)) { var key = "SystemSettingsPluginTest_TestKey"; var controller = DomainControllerFactory.Create <GlobalSettingController>(); try { controller.GetValue <int>(key); Assert.IsTrue(false, "不存在,应该抛出异常。"); } catch (InvalidProgramException) { } repo.Save(new GlobalSetting { Key = key, Value = "1" }); var value = controller.GetValue <int>(key); Assert.AreEqual(1, value); } }
private static FormattedSql ParseWhere(string filter) { var repo = RF.ResolveInstance <TestUserRepository>(); var q = Parse(filter, repo); return(QueryNodeTester.GenerateTestSql(q.Where)); }
public void StampT_Insert_CreatedUser_Logined() { var oldPrincipal = RafyEnvironment.Principal; try { var userName = "******"; RafyEnvironment.Principal = new GenericPrincipal(new GenericIdentity(userName), null); var repo = RF.ResolveInstance <InvoiceRepository>(); using (RF.TransactionScope(repo)) { var inv = new Invoice(); repo.Save(inv); Assert.AreEqual(inv.GetCreatedUser(), userName, "登录后,创建人属性应该正确的设置上。"); inv = repo.GetById(inv.Id); Assert.AreEqual(inv.GetCreatedUser(), userName, "登录后,创建人属性应该正确的设置上。"); } } finally { RafyEnvironment.Principal = oldPrincipal; } }
public void EPT_BatchImport() { int size = EntityTest.BATCH_IMPORT_DATA_SIZE; var repo = RF.ResolveInstance <InvoiceRepository>(); using (RF.TransactionScope(repo)) { var list = new InvoiceList(); for (int i = 0; i < size; i++) { var item = new Invoice(); list.Add(item); } repo.CreateImporter().Save(list); list.Clear(); repo.CreateImporter().Save(list); Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。"); using (PhantomContext.DontFilterPhantoms()) { Assert.AreEqual(repo.CountAll(), size, "幽灵状态的实体,可以使用特定 API 查出。"); var all2 = repo.GetAll(); Assert.AreEqual(all2.Count, size, "幽灵状态的实体,应该无法通过正常的 API 查出。"); Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。"); } } }
public void MPT_Redundancy_AutoUpdateC() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var a = new A { Name = "AName" }; Save(a); var b = new B { A = a }; Save(b); var c = new C { B = b }; Save(c); a.Name = "New Name"; Save(a); var b2 = RF.ResolveInstance <BRepository>().GetById(b.Id) as B; Assert.AreEqual("New Name", b2.AName); var c2 = RF.ResolveInstance <CRepository>().GetById(c.Id) as C; Assert.AreEqual("New Name", c2.AName); } }
protected override Result ExecuteCore() { var order = RF.Find <PurchaseOrder>().GetById(this.OrderId) as PurchaseOrder; if (order == null) { throw new ArgumentNullException("order"); } if (order.StorageInStatus != OrderStorageInStatus.Waiting) { return("该订单已经完全入库,操作失败。"); } //生成入库单 var storageIn = new OrderStorageInBill { Order = order, Code = order.Code + " - 入库", Date = DateTime.Now, Comment = "系统生成" }; //默认直接入库第一个仓库 storageIn.Storage = RF.ResolveInstance <StorageRepository>().CacheAll().First() as Storage; //调用另外一个服务直接入库 var siService = ServiceFactory.Create <AddOrderStorageInBillService>(); siService.Item = storageIn; siService.Invoke(); return(siService.Result); }
/// <summary> /// 查找某个岗位下某个指定模块的禁用功能。 /// </summary> /// <param name="c"></param> /// <returns></returns> private EntityList GetBy(OperationAC_GetDenyListCriteria c) { var opId = c.OrgPositionId; var moduleAC = RF.ResolveInstance <ModuleACRepository>().GetById(c.ModuleACId); var operations = this.DoGetByParent(moduleAC); //把所有已经禁用的功能都加入到列表中去。并把这个返回 var list = this.NewList(); var op = RF.ResolveInstance <OrgPositionRepository>().GetById(opId) as OrgPosition; var denyList = op.OrgPositionOperationDenyList; list.AddRange(operations.Cast <OperationAC>().Where(item => { foreach (var deny in denyList) { if (item.IsSame(deny)) { return(true); } } return(false); })); return(list); }
protected override void Up() { this.RunCode((Action <Rafy.Data.IDbAccesser>)(db => { var repo = RF.ResolveInstance <MonthPlanRepository>(); var plans = repo.GetAll(); foreach (MonthPlan plan in plans) { foreach (TaskOrCategory item in plan.TaskOrCategoryList) { if (item.IsCategoryRO) { item.ObjectiveNum = null; item.WeightInCategory = null; item.Score = null; } else { item.MonthPercent = null; item.MonthScore = null; } } } RF.Save(plans); })); }
public void SNPT_SpecificTime() { using (RF.TransactionScope(SerialNumberPlugin.DbSettingName)) { var name = "testACP"; var controller = DomainControllerFactory.Create <SerialNumberController>(); var sni = controller.CreateDailySerialNumberInfo(name); var next = controller.GenerateNext(name, DateTime.Parse("2000-01-01")); Assert.AreEqual("2000010100000001", next); next = controller.GenerateNext(name, DateTime.Parse("2000-01-01")); Assert.AreEqual("2000010100000002", next); next = controller.GenerateNext(name, DateTime.Parse("2016-05-01")); Assert.AreEqual("2016050100000001", next); next = controller.GenerateNext(sni, DateTime.Parse("2016-05-02")); Assert.AreEqual("2016050200000001", next); next = controller.GenerateNext(sni, DateTime.Parse("2016-05-02")); Assert.AreEqual("2016050200000002", next); next = controller.GenerateNext(sni, DateTime.Parse("2016-05-02")); Assert.AreEqual("2016050200000003", next); var valueRepo = RF.ResolveInstance <SerialNumberValueRepository>(); var value = valueRepo.GetByTime(sni, DateTime.Parse("2016-05-02")); Assert.AreEqual(3, value.RollValue); } }
public void MPT_ORM_IsSelfDirty() { var repo = RF.ResolveInstance <TestUserRepository>(); //clear var e = repo.GetByName("huqf"); if (e != null) { e.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(e); } var user = repo.New().CastTo <TestUser>(); user.Name = "huqf"; user.NotEmptyCode = "NotEmptyCode"; Assert.IsTrue(user.IsNew); Assert.IsTrue(user.IsDirty); repo.Save(user); Assert.IsTrue(!user.IsNew); Assert.IsTrue(!user.IsDirty); user.PersistenceStatus = PersistenceStatus.Deleted; Assert.IsTrue(user.IsDeleted); repo.Save(user); Assert.IsTrue(!user.IsDeleted); Assert.IsTrue(!user.IsDirty); }
public void ODT_ODataQuery_OrderBy_Decending() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var repo = RF.ResolveInstance <TestUserRepository>(); var all = repo.GetAll(); all.Clear(); repo.Save(all); RF.Save(new TestUser { Name = "1" }); RF.Save(new TestUser { Name = "2" }); RF.Save(new TestUser { Name = "3" }); var list = QueryUserList(new ODataQueryCriteria { OrderBy = "Name desc" }); Assert.AreEqual(list.Count, 3); Assert.IsTrue(string.Compare(list[0].Name, list[1].Name) == 1); Assert.IsTrue(string.Compare(list[1].Name, list[2].Name) == 1); } }
public override void Execute(ListLogicalView view) { var barcode = BarcodeTextBoxGenerator.GetTextBoxParameter(this); if (!string.IsNullOrEmpty(barcode)) { var list = view.Data; var item = list.Cast <ProductRefItem>().FirstOrDefault(i => i.Product.Barcode == barcode); if (item != null) { item.Amount++; } else { var product = RF.ResolveInstance <ProductRepository>().GetByBarcode(barcode); if (product == null) { App.MessageBox.Show(string.Format("没有找到对应 {0} 的商品".Translate(), barcode), MessageBoxImage.Error); return; } item = view.CreateNewItem().CastTo <ProductRefItem>(); item.Product = product; item.Amount = 1; list.Add(item); view.RefreshControl(); } view.Current = item; } }
public void EIT_StringId_IntWithString_GetParentRef() { var repo = RF.ResolveInstance <HouseMerchantRepository>(); var itemRepo = RF.ResolveInstance <MerchantItemRepository>(); using (RF.TransactionScope(repo)) { var house = new House { Id = "House1" }; RF.Save(house); var merchant = new HouseMerchant { MerchantItemList = { new MerchantItem { House = house } } }; merchant.Id = "Merchant1"; repo.Save(merchant); var item = itemRepo.GetFirst(); Assert.IsTrue(item.HouseMerchantId == merchant.Id); } }
public void APT_Login_Failed_UserDisabled() { var repo = RF.ResolveInstance <UserRepository>(); using (RF.TransactionScope(repo)) { var controller = DomainControllerFactory.Create <AccountController>(); controller.MaxLoginFailedTimes = 3; repo.Save(new User { UserName = "******", RealName = "hqf", Password = controller.EncodePassword("hqf") }); User user = null; var res = controller.LoginByUserName("hqf", "hqf", out user); Assert.IsTrue(res.Success); user.IsDisabled = true; repo.Save(user); res = controller.LoginByUserName("hqf", "hqf", out user); Assert.IsFalse(res.Success); Assert.AreEqual(ResultCodes.LoginUserDisabled, res.StatusCode, "用户已经被禁用。"); } }
/// <summary> /// 为 <see cref="DataGridView"/> 对象绑定数据源。 /// </summary> /// <param name="dataGridView"></param> internal static void BindDataGridView(DataGridView dataGridView) { var repository = RF.ResolveInstance <LicenseEntityRepository>(); var list = repository.GetAll(); var source = list.Select(l => { var entity = (LicenseEntity)l; return(new { entity.Id, entity.PrivateKey, entity.PublicKey, entity.LicenseTarget, entity.ExpireTime, entity.MacCode, entity.LicenseCode, entity.CreateTime }); }).ToList(); dataGridView.Invoke(new Action(() => { dataGridView.DataSource = source; })); }
public void MPT_ORM_ForeignKey() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var repo = RF.ResolveInstance <TestUserRepository>(); var user = repo.New().CastTo <TestUser>(); user.Name = "huqf"; //为用户添加一个角色 var userRoles = user.TestRoleList; var role = new TestRole(); userRoles.Add(role); role.Name = "admin"; Assert.IsTrue(user.Id == role.TestUserId); Assert.IsTrue(!(user as IEntityWithId).IdProvider.IsAvailable(user.Id)); //保存新建用户 repo.Save(user); Assert.AreEqual(user.Id, role.TestUserId); var roles = RF.ResolveInstance <TestRoleRepository>().GetByUserId(user.Id); Assert.AreEqual(roles.Count, 1); Assert.AreEqual(userRoles.Count, 1); Assert.AreEqual(roles[0].CastTo <TestRole>().Name, role.Name); } }
/// <summary> /// 在缓存的版本号中找到对应主键的数据。 /// </summary> /// <param name="classRegion"></param> /// <param name="scopeClassName"></param> /// <param name="scopeId"></param> /// <returns></returns> public ScopeVersion Find(string classRegion, string scopeClassName, string scopeId) { //检测是否过期 if (this._regionValues == null || this.IsExpired()) { lock (this) { if (this._regionValues == null) { var allValues = RF.ResolveInstance <ScopeVersionRepository>().GetAll() as ScopeVersionList; this.SetAllValues(allValues); } //如果过期,则差异更新。 else if (this.IsExpired()) { var values = RF.ResolveInstance <ScopeVersionRepository>().GetList(_serverTime); this.UpdateByDifference(values); } } } List <ScopeVersion> regionValues = null; if (this._regionValues.TryGetValue(classRegion, out regionValues)) { return(regionValues.FirstOrDefault(v => v.ScopeClass == scopeClassName && v.ScopeId == scopeId)); } return(null); }
public void MPT_Redundancy_RefId() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var a1 = new A { Name = "A1" }; var a2 = new A { Name = "A2" }; Save(a1, a2); var b = new B { A = a1 }; Save(b); var c = new C { B = b }; Save(c); Assert.AreEqual(c.AIdOfB, b.AId); Assert.AreEqual(b.AId, a1.Id); b.A = a2; Save(b); var cInDb = RF.ResolveInstance <CRepository>().GetById(c.Id) as C; Assert.AreEqual(cInDb.AIdOfB, a2.Id); } }
public void UtilsTest_TrasactionScope_Outer_RollBack() { var repo = RF.ResolveInstance <TestUserRepository>(); Assert.IsTrue(repo.CountAll() == 0); using (var tranWhole = RF.TransactionScope(repo)) { repo.Save(new TestUser()); Assert.IsTrue(repo.CountAll() == 1); using (var tranSub = RF.TransactionScope(repo)) { repo.Save(new TestUser()); Assert.IsTrue(repo.CountAll() == 2); tranWhole.Complete(); } Assert.IsTrue(repo.CountAll() == 2); //外部不提交 } Assert.IsTrue(repo.CountAll() == 0, "外部事务未提交,整个事务不应该提交。"); }
public void EPT_JoinQuery() { var repo = RF.ResolveInstance <InvoiceRepository>(); using (RF.TransactionScope(repo)) { var Invoice = new Invoice(); var item1 = new InvoiceItem() { Amount = 100 }; var item2 = new InvoiceItem() { Amount = 200 }; Invoice.InvoiceItemList.Add(item1); Invoice.InvoiceItemList.Add(item2); repo.Save(Invoice); Assert.AreEqual(repo.GetInvoiceByAmount(80).Count, 2); item2.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(Invoice); Assert.AreEqual(repo.GetInvoiceByAmount(80).Count, 1); } }
public void UtilsTest_TrasactionScope_MultiDatabases() { var repoUser = RF.ResolveInstance <TestUserRepository>(); Assert.IsTrue(repoUser.CountAll() == 0); var repoCustomer = RF.ResolveInstance <CustomerRepository>(); Assert.IsTrue(repoCustomer.CountAll() == 0); using (var tranWhole = RF.TransactionScope(repoUser)) { repoUser.Save(new TestUser()); Assert.IsTrue(repoUser.CountAll() == 1); //另一数据的事务。 using (var tranSub = RF.TransactionScope(repoCustomer)) { repoUser.Save(new Customer()); Assert.IsTrue(repoCustomer.CountAll() == 1); //内部不提交 } tranWhole.Complete(); } Assert.IsTrue(repoCustomer.CountAll() == 0, "两个数据库的事务互不干扰,Customer 对应的数据库事务已经回滚。"); Assert.IsTrue(repoUser.CountAll() == 1, "两个数据库的事务互不干扰,TestUser 对应的数据库事务提交成功。"); DeleteUsers(); }
public void EPT_Clear_Query() { var repo = RF.ResolveInstance <InvoiceRepository>(); using (RF.TransactionScope(repo)) { var InvoiceList = new InvoiceList { new Invoice(), new Invoice(), new Invoice() }; repo.Save(InvoiceList); Assert.AreEqual(repo.CountAll(), 3); InvoiceList.Clear(); repo.Save(InvoiceList); Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。"); var all = repo.GetAll(); Assert.AreEqual(all.Count, 0, "幽灵状态的实体,应该无法通过正常的 API 查出。"); using (PhantomContext.DontFilterPhantoms()) { Assert.AreEqual(repo.CountAll(), 3, "幽灵状态的实体,可以使用特定 API 查出。"); var all2 = repo.GetAll(); Assert.AreEqual(all2.Count, 3, "幽灵状态的实体,应该无法通过正常的 API 查出。"); Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。"); Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[1]), true, "幽灵状态的实体,IsPhantom 值为 true。"); Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[2]), true, "幽灵状态的实体,IsPhantom 值为 true。"); } } }
public void UtilsTest_LiteDataTable_Query() { var repoUser = RF.ResolveInstance <TestUserRepository>(); using (var tranWhole = RF.TransactionScope(repoUser)) { repoUser.Save(new TestUser() { Age = 1 }); repoUser.Save(new TestUser() { Age = 1 }); repoUser.Save(new TestUser() { Age = 1 }); using (var dba = DbAccesserFactory.Create(repoUser)) { var table = dba.QueryLiteDataTable("Select * from Users where id > {0}", 0); var columns = table.Columns; Assert.IsTrue(columns.Find("UserName") != null); Assert.IsTrue(columns.Find("Age") != null); var rows = table.Rows; Assert.IsTrue(rows.Count == 3); Assert.IsTrue(rows[0].Values.Length == columns.Count); Assert.IsTrue(rows[0].GetInt32("Age") == 1); } } }
public void EPT_Query() { var repo = RF.ResolveInstance <InvoiceRepository>(); using (RF.TransactionScope(repo)) { var Invoice = new Invoice(); repo.Save(Invoice); Assert.AreEqual(repo.CountAll(), 1); Invoice.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(Invoice); Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。"); var all = repo.GetAll(); Assert.AreEqual(all.Count, 0, "幽灵状态的实体,应该无法通过正常的 API 查出。"); using (PhantomContext.DontFilterPhantoms()) { Assert.AreEqual(repo.CountAll(), 1, "幽灵状态的实体,可以使用特定 API 查出。"); var all2 = repo.GetAll(); Assert.AreEqual(all2.Count, 1, "幽灵状态的实体,应该无法通过正常的 API 查出。"); Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。"); } } }
public void UtilsTest_Logger_ThreadDbAccessed() { var repo = RF.ResolveInstance <TestUserRepository>(); using (RF.TransactionScope(repo)) { int count = 0; EventHandler <Logger.DbAccessedEventArgs> handler = (o, e) => { if (e.ConnectionSchema == RdbDataProvider.Get(repo).DbSetting) { count++; } }; Logger.ThreadDbAccessed += handler; repo.Save(new TestUser()); Logger.ThreadDbAccessed -= handler; var p = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName).ProviderName; if (p == DbSetting.Provider_SqlClient) { Assert.IsTrue(count == 1);//sqlServer= 1 } else { Assert.IsTrue(count == 2);//sqlce oracle=2 } } }
private void barManager1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (e.Item.Name == "tlSave") { Save(); } if (e.Item.Name == "tlEdit") { MessageDxUtil.ShowWarning("登陆用户:" + _appContext.User.UserName); } if (e.Item.Name == "tlAdd") { var repo = RF.ResolveInstance <ModulesRepository>(); Rafy.Sys.Domain.Modules entity = repo.New(); _CurrModulesList.Add(entity); this.modulesListBindingSource.ResetBindings(false);//使绑定到 BindingSource 重新读取当前选定的项,并刷新其显示的值。 } if (e.Item.Name == "tlDelete") { if (this.modulesListBindingSource.Current == null) { return; } Rafy.Sys.Domain.Modules entity = this.modulesListBindingSource.Current as Rafy.Sys.Domain.Modules; if (entity == null) { MessageDxUtil.ShowWarning("请重新选择!"); } if (MessageDxUtil.ShowYesNoAndWarning("是否删除?") == DialogResult.Yes) { _CurrModulesList.Remove(entity); Save(); } } }
public void APT_Register_Identity_UserName() { var repo = RF.ResolveInstance <UserRepository>(); using (RF.TransactionScope(repo)) { var controller = DomainControllerFactory.Create <AccountController>(); var res = controller.Register(new User()); Assert.IsFalse(res.Success); Assert.AreEqual(ResultCodes.RegisterUserNameInvalid, res.StatusCode); res = controller.Register(new User { UserName = "******", Password = controller.EncodePassword("hqf") }); Assert.IsTrue(res.Success); res = controller.Register(new User { UserName = "******", Password = controller.EncodePassword("hqf") }); Assert.IsFalse(res.Success); Assert.AreEqual(ResultCodes.RegisterUserNameDuplicated, res.StatusCode); } }
/// <summary> /// 验证参数。 /// </summary> /// <param name="mac"></param> /// <param name="expireTime"></param> /// <param name="authorizationTarget"></param> /// <returns></returns> internal static bool ValidateParameters(string mac, DateTime expireTime, LicenseTarget authorizationTarget) { if (string.IsNullOrWhiteSpace(mac) || !_regex.IsMatch(mac)) { MessageBox.Show(LicenseManagerResource.ManagerFormValidateParametersMACAddress, LicenseManagerResource.ManagerFormValidateParametersWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (expireTime < DateTime.Now) { MessageBox.Show(LicenseManagerResource.ManagerFormValidateParametersExpireTime, LicenseManagerResource.ManagerFormValidateParametersWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (authorizationTarget == LicenseTarget.None) { MessageBox.Show(LicenseManagerResource.ManagerFormValidateParametersSelectAuthenticationTarget, LicenseManagerResource.ManagerFormValidateParametersWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } var repository = RF.ResolveInstance <LicenseEntityRepository>(); var entity = repository.GetFirstBy(new CommonQueryCriteria(BinaryOperator.And) { new PropertyMatch(LicenseEntity.MacCodeProperty, PropertyOperator.Equal, mac) }); if (entity != null) { MessageBox.Show(string.Format(LicenseManagerResource.ManagerFormValidateParametersMACHasUsed, mac), LicenseManagerResource.ManagerFormValidateParametersWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } return(true); }
public void EIT_StringId_StringRefLong() { var lRepo = RF.ResolveInstance <LesseeRepository>(); var repo = RF.ResolveInstance <HouseRepository>(); using (RF.TransactionScope(repo)) { var house = new House { Id = "House1" }; repo.Save(house); house = repo.GetFirst(); Assert.IsTrue(house.LesseeId == null); var lessee = new Lessee(); lRepo.Save(lessee); Assert.IsTrue(lessee.Id > 0); house.Lessee = lessee; Assert.IsTrue(house.LesseeId.GetValueOrDefault() == lessee.Id); repo.Save(house); house = repo.GetFirst(); Assert.IsTrue(house.LesseeId.GetValueOrDefault() == lessee.Id); } }