Beispiel #1
0
        public static void InitializeContextWithNavigationProperties()
        {
            using (DbContextConnectionClass dbContextConnectionClass = new DbContextConnectionClass()) {
                dbContextConnectionClass.ResetDatabase();
                Company companyFirst = null;
                for (int i = 1; i < 4; i++)
                {
                    string indexString = i.ToString();

                    Company company = new Company();
                    company.CompanyName = indexString;
                    company.Description = indexString;

                    Person person = new Person();
                    person.PersonName  = indexString;
                    person.Description = indexString;
                    company.Person     = person;
                    person.Company     = company;

                    Office office = new Office();
                    office.Name        = indexString;
                    office.Description = indexString;

                    if (companyFirst == null)
                    {
                        companyFirst = company;
                    }

                    companyFirst.Offices.Add(office);
                    dbContextConnectionClass.Company.Add(company);
                    dbContextConnectionClass.Persons.Add(person);
                }
                dbContextConnectionClass.SaveChanges();
            }
        }
Beispiel #2
0
        public void Read_PolicyAllow_OneObjectDeny_IncludeNavigateObject_SaveChanges()
        {
            SecurityTestHelper.InitializeContextWithNavigationProperties();
            using (DbContextConnectionClass dbContextConnectionClass = new DbContextConnectionClass()) {
                dbContextConnectionClass.PermissionsContainer.SetPermissionPolicy(PermissionPolicy.AllowAllByDefault);
                dbContextConnectionClass.PermissionsContainer.AddObjectPermission(SecurityOperation.ReadWrite, OperationState.Deny, SecurityTestHelper.PersonNameEqualsOne);

                Company company1 = dbContextConnectionClass.Company.Include(p => p.Person).Single(d => d.CompanyName == "1");
                Assert.IsNull(company1.Person);

                company1.Description = "5";
                dbContextConnectionClass.SaveChanges();
            }

            using (DbContextConnectionClass dbContextConnectionClass = new DbContextConnectionClass()) {
                var company1 = dbContextConnectionClass.Company.Include(p => p.Person).First(p => p.Description == "5");
                Assert.IsNotNull(company1.Person);
            }
        }
 private void CreateThreeObjectDbContextConnectionClass()
 {
     using (DbContextConnectionClass dbContextConnectionClass = new DbContextConnectionClass()) {
         for (int i = 1; i < 4; i++)
         {
             Company company = new Company();
             company.CompanyName = i.ToString();
             company.Description = i.ToString();
             Persons persons = new Persons();
             persons.PersonName  = i.ToString();
             persons.Description = i.ToString();
             company.Persons     = persons;
             persons.Company     = company;
             dbContextConnectionClass.Company.Add(company);
             dbContextConnectionClass.Persons.Add(persons);
         }
         dbContextConnectionClass.SaveChanges();
     }
 }
Beispiel #4
0
        public void Read_Collection_NestedCriteria()
        {
            using (DbContextConnectionClass dbContext = new DbContextConnectionClass()) {
                Company company = new Company()
                {
                    CompanyName = "Pixar"
                };
                Office office = new Office()
                {
                    Name    = "London",
                    Company = company
                };
                dbContext.Offices.Add(office);
                dbContext.Company.Add(company);
                dbContext.PermissionsContainer.AddObjectPermission <DbContextConnectionClass, Company>(SecurityOperation.Read, OperationState.Deny, (db, obj) => obj.Offices.Any(p => p.Name == "London"));
                dbContext.SaveChanges();

                Assert.IsNull(dbContext.Company.Where(p => p.CompanyName == "Pixar").FirstOrDefault());
            }
        }