示例#1
0
 public void InsertCheckKey()
 {
     using (var connection = GetOpenConnection())
     {
         connection.Get<IUser>(3).IsNull();
         User user = new User { Name = "Adamb", Age = 10 };
         int id = (int)connection.Insert(user);
         user.Id.IsEqualTo(id);
     }
 }
示例#2
0
        public void BuilderSelectClause()
        {
            using (var connection = GetOpenConnection())
            {
                var rand = new Random(8675309);
                var data = new List<User>();
                for (int i = 0; i < 100; i++)
                {
                    var nU = new User { Age = rand.Next(70), Id = i, Name = Guid.NewGuid().ToString() };
                    data.Add(nU);
                    nU.Id = (int)connection.Insert<User>(nU);
                }

                var builder = new SqlBuilder();
                var justId = builder.AddTemplate("SELECT /**select**/ FROM Users");
                var all = builder.AddTemplate("SELECT Name, /**select**/, Age FROM Users");

                builder.Select("Id");

                var ids = connection.Query<int>(justId.RawSql, justId.Parameters);
                var users = connection.Query<User>(all.RawSql, all.Parameters);

                foreach (var u in data)
                {
                    if (!ids.Any(i => u.Id == i)) throw new Exception("Missing ids in select");
                    if (!users.Any(a => a.Id == u.Id && a.Name == u.Name && a.Age == u.Age)) throw new Exception("Missing users in select");
                }
            }
        }
示例#3
0
 public async Task InsertCheckKeyAsync()
 {
     using (var connection = GetOpenConnection())
     {
         (await connection.GetAsync<IUser>(3)).IsNull();
         User user = new User { Name = "Adamb", Age = 10 };
         int id = (int)await connection.InsertAsync(user);
         user.Id.IsEqualTo(id);
     }
 }