public void MPT_ReadOnlyExtensionProperties() { var user = Get <TestUser>(); var properties = new List <string>(); user.PropertyChanged += (o, e) => { properties.Add(e.PropertyName); }; properties.Clear(); TestUserExt.SetUserCode(user, "NewCode"); Assert.IsTrue(properties.Contains("TestUserExt_UserCode")); Assert.IsTrue(properties.Contains("TestUserExt_ReadOnlyUserCode")); Assert.IsTrue(properties.Contains("TestUserExt_ReadOnlyUserCodeShadow")); Assert.AreEqual(TestUserExt.GetUserCode(user), "NewCode"); Assert.AreEqual(TestUserExt.GetReadOnlyUserCode(user), "NewCode ReadOnly!"); Assert.AreEqual(TestUserExt.GetReadOnlyUserCodeShadow(user), "NewCode ReadOnly!"); var typeProperties = TypeDescriptor.GetProperties(user); var property = typeProperties.Find("TestUserExt_ReadOnlyUserCode", false); Assert.IsNotNull(property); Assert.IsTrue(property.IsReadOnly); property = typeProperties.Find("TestUserExt_ReadOnlyUserCodeShadow", false); Assert.IsNotNull(property); Assert.IsTrue(property.IsReadOnly); }
public void MPT_ORM_PropertiesMapping_Inheritance() { var repo = RF.Find <TestAdministrator>() as TestUserRepository; //清空历史数据 var user = repo.GetByName("huqf"); if (user != null) { user.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(user); } //新建用户并设置一些值。 var user1 = repo.New().CastTo <TestAdministrator>(); user1.Name = "huqf"; user1.Level = 1; TestUserExt.SetUserCode(user1, "NewUserCode"); //为用户添加一个角色 var userRoles = user1.TestRoleList; var role = new TestRole(); userRoles.Add(role); role.Name = "admin"; Assert.AreEqual(user1.Id, role.TestUserId); //保存新建用户 repo.Save(user1); //重新获取保存的用户 var user2 = repo.GetByName("huqf").CastTo <TestAdministrator>(); Assert.IsNotNull(user2); Assert.AreEqual(user1.Name, user2.Name); Assert.AreEqual(user2.Level, 1); Assert.AreEqual(TestUserExt.GetUserCode(user2), "NewUserCode"); Assert.AreEqual(user1.TestRoleList.Count, 1); Assert.AreEqual(user1.TestRoleList[0].CastTo <TestRole>().Name, "admin"); //获取 Role var role2 = RF.Find <TestRole>().GetById(role.Id).CastTo <TestRole>(); Assert.AreEqual(role.Name, "admin"); Assert.AreEqual(role2.Name, "admin"); Assert.AreEqual(user1.Id, role2.TestUserId); Assert.IsNotNull(role2.TestUser); //删除用户 user1.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(user1); var users = repo.GetAll(); Assert.IsTrue(!users.Cast <TestUser>().Any(u => u.Name == "huqf")); }
public void MPT_ExtensionProperties() { var user = Get <TestUser>(); Assert.AreEqual(TestUserExt.GetUserCode(user), "DefaultUserCode"); TestUserExt.SetUserCode(user, "NewCode"); Assert.AreEqual(TestUserExt.GetUserCode(user), "NewCode"); var properties = TypeDescriptor.GetProperties(user); var property = properties.Find("TestUserExt_UserCode", false); Assert.IsNotNull(property); Assert.IsFalse(property.IsReadOnly); }
public void MPT_ORM_PropertiesMapping() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var repo = RF.ResolveInstance <TestUserRepository>(); //新建用户并设置一些值。 var user1 = repo.New(); user1.Name = "huqf"; TestUserExt.SetUserCode(user1, "NewUserCode"); //为用户添加一个角色 var userRoles = user1.TestRoleList; var role = new TestRole(); userRoles.Add(role); role.Name = "admin"; Assert.AreEqual(user1.Id, role.TestUserId); //保存新建用户 repo.Save(user1); //重新获取保存的用户 var user2 = repo.GetByName("huqf"); Assert.IsNotNull(user2); Assert.AreEqual(user1.Name, user2.Name); Assert.AreEqual(TestUserExt.GetUserCode(user2), "NewUserCode"); Assert.AreEqual(user1.TestRoleList.Count, 1); Assert.AreEqual(user1.TestRoleList[0].CastTo <TestRole>().Name, "admin"); //获取 Role var role2 = RF.Find <TestRole>().GetById(role.Id).CastTo <TestRole>(); Assert.AreEqual(role.Name, "admin"); Assert.AreEqual(role2.Name, "admin"); Assert.AreEqual(user1.Id, role2.TestUserId); Assert.IsNotNull(role2.TestUser); //删除用户 user1.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(user1); var users = repo.GetAll(); Assert.IsTrue(!users.Cast <TestUser>().Any(u => u.Name == "huqf")); } }