Beispiel #1
0
        private static void SimpleCrudTestsEntity()
        {
            using (var db = OpenConnection())
            {
                var user = new User
                {
                    Username = "******",
                    Fullname = "Test User1",
                    Email = "*****@*****.**",
                    JoinDate = DateTime.Now,
                    Status = UserStatus.AwaitingActivation,
                    Type = UserType.Admin,
                    Password = "******"
                };

                db.Insert(user);

                user = db.GetById<User>(user.Id);
                Console.WriteLine(user.Username);

                user.Username = "******" + DateTime.Now.Ticks;
                db.Update(user);

                user = db.GetById<User>(user.Id);
                Console.WriteLine(user.Username);

                db.Delete(user);

                user = db.GetById<User>(user.Id);
                Console.WriteLine(user == null);
            }
        }
Beispiel #2
0
        private static void SimpleCrudTestsAssociationEntity()
        {
            using (var db = OpenConnection())
            {
                var post = new Post { CreateDate = DateTime.Now, Title = "Test Post", User = new User { Id = 4 } };
                var user = new User { JoinDate = DateTime.Now, Username = "******" };

                db.Insert(post);
                db.Insert(user);

                var like = new Like
                {
                    Post = post,
                    User = user,
                    LikedDate = DateTime.Now
                };

                db.Insert(like);

                like = db.GetById<Like>(like);
                Console.WriteLine(like.LikedDate);

                like.LikedDate = DateTime.Now.AddDays(2);
                db.Update(like);

                like = db.GetById<Like>(like);
                Console.WriteLine(like.LikedDate);

                db.Delete(like);

                like = db.GetById<Like>(like);
                Console.WriteLine(like == null);
            }
        }