Exemplo n.º 1
0
        public void CreateRelationWithDataViolation()
        {
            TestDatabase database = new TestDatabase();

            database.Members.Insert(new Member { Id = "A", GroupId = 1 });
            database.Members.Insert(new Member { Id = "B", GroupId = null });

            database.AddMemberGroupRelation();
        }
Exemplo n.º 2
0
        public void InsertRelatedEntity()
        {
            TestDatabase database = new TestDatabase();
            database.AddMemberGroupRelation();

            database.Groups.Insert(new Group { Name = "Group 1" });
            database.Groups.Insert(new Group { Name = "Group 2" });

            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 1 });
        }
        public void CascadedDelete()
        {
            TestDatabase database = new TestDatabase();
            database.AddMemberGroupRelation(cascadedDeletion: true);
      
            database.Groups.Insert(new Group { Name = "Group 1" });
            database.Groups.Insert(new Group { Name = "Group 2" });
            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 1 });
      
            database.Groups.Delete(new Group { Id = 1 });

            Assert.AreEqual(1, database.Groups.Count());
            Assert.AreEqual(0, database.Members.Count());
        }
Exemplo n.º 4
0
        public void OuterJoinNulledFields()
        {
            TestDatabase db = new TestDatabase();
            db.AddMemberGroupRelation();

            Group group = new Group { Name = "Group" };
            db.Groups.Insert(group);

            db.Members.Insert(new Member { Id = "A", Name = "John", GroupId = null });
            db.Members.Insert(new Member { Id = "B", Name = "Kay", GroupId = group.Id });
            
            var q =
                from m in db.Members
                join g_ in db.Groups on m.GroupId equals g_.Id into groups_
                from g in groups_.DefaultIfEmpty()
                select new { Name = m.Name, GroupName = g.Name };

            var result = q.ToList();
            
            Assert.IsTrue(result.Any(x => x.GroupName == null));
        }
Exemplo n.º 5
0
        public void InsertRelatedEntityViolationDisabled()
        {
            TestDatabase database = new TestDatabase();
            IRelation relation = database.AddMemberGroupRelation();

            database.Groups.Insert(new Group { Name = "Group 1" });
            database.Groups.Insert(new Group { Name = "Group 2" });
            
            relation.IsEnabled = false;
            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 3 });
        }
Exemplo n.º 6
0
 public void CreateMultiFieldRelationWithExpressionFactory()
 {
     TestDatabase database = new TestDatabase();
     database.AddMemberGroupRelation(createMultiField: true, useExpressionFactory: true);
 }
Exemplo n.º 7
0
        public void CreateMultiFieldRelationWithInconsistentDataAndExpressionFactory()
        {
            TestDatabase database = new TestDatabase();

            database.Members.Insert(new Member { Id = "A", GroupId = 1, GroupId2 = 2 });

            database.AddMemberGroupRelation(createMultiField: true, useExpressionFactory: true);
        }
Exemplo n.º 8
0
        public void CreateMultiFieldRelationWithEmptyData()
        {
            TestDatabase database = new TestDatabase();

            database.Members.Insert(new Member { Id = "A", GroupId = null, GroupId2 = 2 });

            database.AddMemberGroupRelation(createMultiField: true);
        }
Exemplo n.º 9
0
        public void CreateMultiFieldRelationWithConsistentData()
        {
            TestDatabase database = new TestDatabase();

            database.Groups.Insert(new Group { Id = 1, Id2 = 2, Name = "A" });
            database.Members.Insert(new Member { Id = "A", GroupId = 1, GroupId2 = 2 });

            database.AddMemberGroupRelation(createMultiField: true);
        }
Exemplo n.º 10
0
        public void CreateRelation()
        {
            TestDatabase database = new TestDatabase();

            database.AddMemberGroupRelation();
        }
Exemplo n.º 11
0
 public void CreateMultiFieldRelation()
 {
     TestDatabase database = new TestDatabase();
     database.AddMemberGroupRelation(createMultiField: true);
 }
Exemplo n.º 12
0
        public void DeleteRelatedEntitiesViolationDisabledReenable()
        {
            TestDatabase database = new TestDatabase();
            IRelation relation = database.AddMemberGroupRelation();

            database.Groups.Insert(new Group { Name = "Group 1" });
            database.Groups.Insert(new Group { Name = "Group 2" });
            database.Groups.Insert(new Group { Name = "Group 3" });
            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 1 });

            relation.IsEnabled = false;
            database.Groups.Delete();

            relation.IsEnabled = true;
        }
Exemplo n.º 13
0
        public void DeleteRelatedEntities()
        {
            TestDatabase database = new TestDatabase();
            database.AddMemberGroupRelation();

            database.Groups.Insert(new Group { Name = "Group 1" });
            database.Groups.Insert(new Group { Name = "Group 2" });
            database.Groups.Insert(new Group { Name = "Group 3" });

            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 1 });

            database.Groups.Where(g => g.Id > 1).Delete();
        }
Exemplo n.º 14
0
        public void UpdateRelatedEntitiesViolationDisabledReenabled()
        {
            TestDatabase database = new TestDatabase(false); // No identity
            IRelation relation = database.AddMemberGroupRelation();

            database.Groups.Insert(new Group { Id = 1, Name = "Group 1" });
            database.Groups.Insert(new Group { Id = 2, Name = "Group 2" });
            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 1 });
            database.Members.Insert(new Member { Id = "MS", Name = "Michael Smith", GroupId = 2 });

            relation.IsEnabled = false;
            database.Groups.Update(g => new Group { Id = g.Id + 1 });

            relation.IsEnabled = true;
        }
Exemplo n.º 15
0
        public void UpdateRelatedEntities()
        {
            TestDatabase database = new TestDatabase(false); // No identity
            database.AddMemberGroupRelation();

            database.Groups.Insert(new Group { Id = 1, Name = "Group 1" });
            database.Groups.Insert(new Group { Id = 2, Name = "Group 2" });
            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = 1 });
            database.Members.Insert(new Member { Id = "MS", Name = "Michael Smith", GroupId = 2 });

            database.Groups.Update(g => new Group { Id = g.Id % 2 + 1 });
        }
Exemplo n.º 16
0
        public void InsertRelatedEntityWithEmptyForeignKey()
        {
            TestDatabase database = new TestDatabase();
            database.AddMemberGroupRelation();

            database.Members.Insert(new Member { Id = "JD", Name = "John Doe", GroupId = null });
        }