Пример #1
0
        public void TimestampInsert()
        {
            TestDatabase db = new TestDatabase();

            TimestampEntity entity = new TimestampEntity() { Id = 1 };
            db.TimestampEntities.Insert(entity);
        }
        public void NotNullableConstraintCompletion()
        {
            TestDatabase db = new TestDatabase(createNotNullConstraint: true);

            Group group = new Group { Id = 1};
            db.Groups.Insert(group);
        }
        public void IdentityReturned()
        {
            TestDatabase db = new TestDatabase(createIdentityForGroup:true);
            Group group = new Group { Name = "Group" };

            db.Groups.Insert(group);

            Assert.AreEqual(group.Id, 1);
        }
        public void NCharContraintCompletion()
        {
            TestDatabase db = new TestDatabase(createNcharContraintForGroup: true);

            Group group = new Group { Id = 1, Name = "wat" };
            db.Groups.Insert(group);

            Assert.AreEqual("wat ", db.Groups.Single().Name);
        }
Пример #5
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();
        }
Пример #6
0
        public void InsertEntity()
        {
            TestDatabase database = new TestDatabase();

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

            var result = database.Members.ToList();
            Assert.IsTrue(result.Count > 0);
        }
        public void TimestampReturnedOnInsert()
        {
            TestDatabase db = new TestDatabase();
            TimestampEntity entity = new TimestampEntity() { Id = 1 };
            Timestamp timestamp = entity.Timestamp;

            db.TimestampEntities.Insert(entity);

            Assert.AreNotEqual(timestamp, entity.Timestamp);
        }
Пример #8
0
        public void InsertRelatedEntityViolation()
        {
            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 = 3 });
        }
Пример #9
0
        public void TimestampChangedOnInsert()
        {
            TestDatabase db = new TestDatabase();

            TimestampEntity entity = new TimestampEntity() { Id = 1 };
            Timestamp timestamp = entity.Timestamp;

            db.TimestampEntities.Insert(entity);

            Assert.AreNotEqual(timestamp, db.TimestampEntities.Single(t => t.Id == 1).Timestamp);
        }
        public void Count()
        {
            TestDatabase database = new TestDatabase();

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

            int count = database.Groups.Where(g => g.Id > 1).Count();

            Assert.AreEqual(count, 2);
        }
Пример #11
0
        public void UpdateEntities()
        {
            TestDatabase database = new TestDatabase();
            
            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.Groups.Update(x => new Group { Name = x.Name + " (deleted)" });

            var newEntities = database.Groups.ToList();
            Assert.IsTrue(newEntities.All(e => e.Name.EndsWith("(deleted)")));
        }
Пример #12
0
        public void UpdateEntity()
        {
            TestDatabase database = new TestDatabase();
            Member member = new Member { Id = "JD1967", Name = "Joh Doe" };
            database.Members.Insert(member);

            member.Name = "John Doe";

            database.Members.Update(member);

            Member updated = database.Members.FirstOrDefault();
            Assert.AreEqual(updated.Name, "John Doe");
        }
        public void TransactionScope()
        {
            TestDatabase database = new TestDatabase();

            using (TransactionScope tran = new TransactionScope())
            {
                database.Members.Insert(new Member { Id = "A" });
                tran.Complete();
            }

            Assert.AreEqual(database.Members.Count, 1);
            Assert.IsTrue(database.Members.Any(m => m.Id == "A"));
        }
        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());
        }
        public void TimestampReturnedOnUpdate()
        {
            TestDatabase db = new TestDatabase();
            TimestampEntity entity = new TimestampEntity() { Id = 1 };

            db.TimestampEntities.Insert(entity);
            Timestamp timestamp = entity.Timestamp;

            entity.Data = "altered";
            db.TimestampEntities.Update(entity);


            Assert.AreNotEqual(timestamp, entity.Timestamp);
        }
        public void StoredProcedure_IncompatibleType1()
        {
            TestDatabase database = new TestDatabase();

            IQueryable<Group> query =
                database.Groups.Where(g =>
                    g.Id == new Parameter<int>("param1"));

            var procedure = database.StoredProcedures.Create(query);

            var result = procedure
                .Execute(
                    new Dictionary<string, object> { { "param1", null } })
                .ToList();
        }
        public void StoredProcedure_ParameterDescription()
        {
            TestDatabase database = new TestDatabase();

            IQueryable<Group> query = 
                database.Groups.Where(g =>
                    g.Id > new Parameter<int>("param1") + new Parameter<long?>("param2"));

            var procedure = database.StoredProcedures.Create(query);

            Assert.AreEqual(procedure.Parameters.Count, 2);
            Assert.IsTrue(procedure.Parameters.Any(p => 
                p.Name == "param1" && p.Type == typeof(int)));
            Assert.IsTrue(procedure.Parameters.Any(p =>
                p.Name == "param2" && p.Type == typeof(long?)));
        }
        public void StoredProcedure_InternalParameter()
        {
            TestDatabase database = new TestDatabase();

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

            IQueryable<Group> query = 
                database.Groups.Where(g => g.Id > new Parameter<int>("param1"));

            var procedure = database.StoredProcedures.Create(query);

            var result = procedure
                .Execute(new Dictionary<string, object> { { "param1", 1 } })
                .ToList();

            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(result.All(g => g.Id > 1));
        }
Пример #19
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));
        }
        public void LocalTransactionRollback()
        {
            TestDatabase database = new TestDatabase();
            database.AddGroupNameIndex();

            bool failed = false;

            database.Groups.Insert(new Group { Name = "A" });
            try
            {
                database.Groups.Insert(new Group { Name = "A" });
            }
            catch
            {
                failed = true;
            }

            Assert.IsTrue(failed);
            Assert.AreEqual(database.Groups.Count, 1);

        }
Пример #21
0
        public void CreateMultiFieldRelationWithEmptyData()
        {
            TestDatabase database = new TestDatabase();

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

            database.AddMemberGroupRelation(createMultiField: true);
        }
Пример #22
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 });
        }
Пример #23
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);
        }
Пример #24
0
 public void CreateMultiFieldRelationWithExpressionFactory()
 {
     TestDatabase database = new TestDatabase();
     database.AddMemberGroupRelation(createMultiField: true, useExpressionFactory: true);
 }
Пример #25
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);
        }
Пример #26
0
 public void CreateMultiFieldRelation()
 {
     TestDatabase database = new TestDatabase();
     database.AddMemberGroupRelation(createMultiField: true);
 }
Пример #27
0
        public void CreateRelation()
        {
            TestDatabase database = new TestDatabase();

            database.AddMemberGroupRelation();
        }
Пример #28
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;
        }
Пример #29
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();
        }
Пример #30
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;
        }