public void RollbackNavigationProperty() { SecurityTestHelper.InitializeContextWithNavigationProperties(); using (DbContextConnectionClass dbContextConnectionClass = new DbContextConnectionClass()) { dbContextConnectionClass.PermissionsContainer.SetPermissionPolicy(PermissionPolicy.AllowAllByDefault); dbContextConnectionClass.PermissionsContainer.AddMemberPermission(SecurityOperation.Write, OperationState.Deny, "Person", SecurityTestHelper.CompanyNameEqualsTwo); Assert.AreEqual(3, dbContextConnectionClass.Company.Include(p => p.Person).Count()); Company company = dbContextConnectionClass.Company.Include(p => p.Person).First(p => p.CompanyName == "2"); Assert.IsNotNull(company.Person); Person newPerson = new Person(); newPerson.Description = "New person"; newPerson.Company = company; company.Person = newPerson; dbContextConnectionClass.Persons.Add(newPerson); Assert.AreEqual(EntityState.Modified, dbContextConnectionClass.Entry(company).State); Assert.AreEqual(EntityState.Added, dbContextConnectionClass.Entry(newPerson).State); SecurityTestHelper.FailSaveChanges(dbContextConnectionClass); Assert.AreEqual(EntityState.Unchanged, dbContextConnectionClass.Entry(company).State); Assert.IsFalse(dbContextConnectionClass.ChangeTracker.Entries().Any(p => p.Entity == newPerson)); //Assert.AreEqual(EntityState.Modified, dbContextConnectionClass.Entry(company1).State); //Assert.IsTrue(dbContextConnectionClass.Entry(company1).Property("Description").IsModified); //Assert.IsTrue(dbContextConnectionClass.Entry(company1).Property("DecimalItem").IsModified); //Assert.IsFalse(dbContextConnectionClass.Entry(company1).Property("ItemCount").IsModified); } }
public void ReadBlockedMembersFromObjectWithBlockedCollectionProperty() { SecurityTestHelper.InitializeContextWithNavigationPropertiesAndCollections(); using (DbContextConnectionClass dbContextConnectionClass = new DbContextConnectionClass()) { dbContextConnectionClass.PermissionsContainer.SetPermissionPolicy(PermissionPolicy.AllowAllByDefault); dbContextConnectionClass.PermissionsContainer.AddMemberPermission(SecurityOperation.Read, OperationState.Deny, "Offices", SecurityTestHelper.CompanyNameEqualsTwo); Assert.AreEqual(3, dbContextConnectionClass.Company.Include(p => p.Offices).Count()); Company company1 = dbContextConnectionClass.Company.Include(p => p.Offices).OrderBy(d => d.Id).First(p => p.CompanyName == "1"); Assert.IsNotNull(company1.Offices); Assert.AreEqual(2, company1.Offices.Count()); IList <string> company1BlockedMembers = dbContextConnectionClass.Entry(company1).GetBlockedMembers(); Assert.IsNotNull(company1BlockedMembers); Assert.AreEqual(0, company1BlockedMembers.Count()); Company company2 = dbContextConnectionClass.Company.Include(p => p.Offices).OrderBy(d => d.Id).First(p => p.CompanyName == "2"); Assert.IsNull(company2.Offices); IList <string> company2BlockedMembers = dbContextConnectionClass.Entry(company2).GetBlockedMembers(); Assert.IsNotNull(company2BlockedMembers); Assert.AreEqual(2, company2BlockedMembers.Count()); Assert.AreEqual("Offices", company2BlockedMembers.First()); } }