public void SingleInto() { var u = new User(); var user = Database.SingleInto(u, "select u.* from users u where u.userid = 1"); AssertUserValues(InMemoryUsers[0], user); Assert.AreEqual(u, user); }
public void SingleOrDefaultIntoWithNoRecord() { var u = new User(); var user = Database.SingleOrDefaultInto(u, "select u.* from users u where u.userid = -1"); AssertUserValues(u, new User()); Assert.Null(user); }
protected void AssertUserValues(User expected, User actual) { Assert.AreEqual(expected.UserId, actual.UserId); Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Age, actual.Age); Assert.AreEqual(expected.DateOfBirth, actual.DateOfBirth); Assert.AreEqual(expected.Savings, actual.Savings); }
public async Task InsertTwoPocoIntoDatabaseUsingInsertAsync() { var user1 = new User() { Age = 10, DateOfBirth = DateTime.Now }; var user2 = new User() { Age = 11, DateOfBirth = DateTime.Now }; var pk1 = await Database.InsertAsync(user1); var userDb1 = Database.Query<User>().Where(x => x.UserId == user1.UserId).Single(); Assert.AreEqual(user1.Age, userDb1.Age); Assert.AreEqual(pk1, userDb1.UserId); var pk2 = await Database.InsertAsync(user2); var userDb2 = Database.Query<User>().Where(x => x.UserId == user2.UserId).Single(); Assert.AreEqual(user2.Age, userDb2.Age); Assert.AreEqual(pk2, userDb2.UserId); }
public async Task InsertPocoIntoDatabaseUsingInsertAsync() { var user = new User() { Age = 10, DateOfBirth = DateTime.Now }; var pk = await Database.InsertAsync(user); var userDb = Database.Query<User>().Where(x => x.UserId == user.UserId).Single(); Assert.AreEqual(user.Age, userDb.Age); Assert.AreEqual(pk, userDb.UserId); Assert.AreEqual(user.UserId, userDb.UserId); }
public void InsertTwoPocoIntoDatabaseUsingInsertAsyncWaitingForAll1() { var user1 = new User() { Age = 10, DateOfBirth = DateTime.Now }; var user2 = new User() { Age = 11, DateOfBirth = DateTime.Now }; var task1 = Database.InsertAsync(user1).ContinueWith(y => { var userDb1 = Database.Query<User>().Where(x => x.UserId == user1.UserId).Single(); Assert.AreEqual(user1.Age, userDb1.Age); Console.WriteLine(user1.Age); }); var task2 = Database.InsertAsync(user2).ContinueWith(y => { var userDb2 = Database.Query<User>().Where(x => x.UserId == user2.UserId).Single(); Assert.AreEqual(user2.Age, userDb2.Age); Console.WriteLine(user2.Age); }); Task.WaitAll(task1, task2); }
public void SingleIntoWithNoRecord() { var u = new User(); Assert.Throws<InvalidOperationException>(() => Database.SingleInto(u, "select u.* from users u where u.userid = -1")); }
protected virtual void InsertData() { InMemoryUsers = new List<User>(); InMemoryExtraUserInfos = new List<ExtraUserInfo>(); InMemoryHouses = new List<House>(); for (var i = 0; i < 5; i++) { var house = new House() { Address = i + " Road Street, Suburb" }; Database.Insert(house); InMemoryHouses.Add(house); } Database.Insert(new House { Address = "_ Road\\Street, Suburb" } ); for (var i = 0; i < 15; i++) { var user = new User { Name = "Name" + (i + 1), Age = 20 + (i + 1), DateOfBirth = new DateTime(1970, 1, 1).AddYears(i - 1), Savings = 50.00m + (1.01m * (i + 1)), IsMale = (i % 2 == 0), YorN = (i % 2 == 0) ? 'Y' : 'N', UniqueId = (i % 2 != 0 ? Guid.NewGuid() : (Guid?)null), TimeSpan = new TimeSpan(1, 1, 1), House = i % 2 == 0 ? null : InMemoryHouses[i % 5], SupervisorId = (i + 1) % 2 == 0 ? (i + 1) : (int?)null, Address = i % 10 == 0 ? null : new Address() { Street = i + " Road Street", City = "City " + i }, TestEnum = (i + 1) % 2 == 0 ? TestEnum.All : TestEnum.None }; Database.Insert(user); InMemoryUsers.Add(user); var extra = new ExtraUserInfo { UserId = user.UserId, Email = "email" + (i + 1) + "@email.com", Children = (i + 1) }; Database.Insert(extra); InMemoryExtraUserInfos.Add(extra); var one = new One() { Name = "Name" + (i + 1), }; Database.Insert(one); for (int j = 0; j < (i % 3); j++) { var many = new Many() { OneId = one.OneId, Currency = "Cur" + (i + j + 1), Value = (i + j + 1) }; Database.Insert(many); } } }
protected void AssertUserValues(User expected, User actual) { Assert.AreEqual(expected.UserId, actual.UserId); Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Age, actual.Age); Assert.AreEqual(expected.DateOfBirth, actual.DateOfBirth); Assert.AreEqual(expected.Savings, actual.Savings); if (expected.Address != null) { Assert.AreEqual(expected.Address.Street, actual.Address.Street); Assert.AreEqual(expected.Address.City, actual.Address.City); } else { Assert.AreEqual(expected.Address, actual.Address); } }
protected void AssertUserHouseValues(User expected, User actual) { if (actual.House == null) Assert.Null(expected.House); else Assert.AreEqual(expected.House.HouseId, actual.House.HouseId); }
protected void InsertData() { InMemoryUsers = new List<User>(); InMemoryExtraUserInfos = new List<ExtraUserInfo>(); for (var i = 0; i < 15; i++) { var user = new User { Name = "Name" + (i + 1), Age = 20 + (i + 1), DateOfBirth = new DateTime(1970, 1, 1).AddYears(i + 1), Savings = 50.00m + (1.01m * (i + 1)), IsMale = (i%2 == 0) }; Database.Insert(user); InMemoryUsers.Add(user); var extra = new ExtraUserInfo { UserId = user.UserId, Email = "email" + (i + 1) + "@email.com", Children = (i + 1) }; Database.Insert(extra); InMemoryExtraUserInfos.Add(extra); } }
private string FormatAge(User u) { return string.Format("Age: {0}, IsMale: {1}", u.Age, u.IsMale); }
protected virtual void InsertData() { InMemoryUsers = new List<User>(); InMemoryExtraUserInfos = new List<ExtraUserInfo>(); InMemoryHouses = new List<House>(); for (var i = 0; i < 5; i++) { var house = new House() { Address = i + " Road Street, Suburb" }; Database.Insert(house); InMemoryHouses.Add(house); } for (var i = 0; i < 15; i++) { var user = new User { Name = "Name" + (i + 1), Age = 20 + (i + 1), DateOfBirth = new DateTime(1970, 1, 1).AddYears(i - 1), Savings = 50.00m + (1.01m * (i + 1)), IsMale = (i%2 == 0), YorN = (i%2 == 0) ? 'Y' : 'N', UniqueId = (i%2 != 0 ? Guid.NewGuid() : (Guid?)null), TimeSpan = new TimeSpan(1,1,1), HouseId = i%2==0?(int?)null:InMemoryHouses[i%5].HouseId, SupervisorId = (i+1)%2==0?(i+1):(int?)null }; Database.Insert(user); InMemoryUsers.Add(user); var extra = new ExtraUserInfo { UserId = user.UserId, Email = "email" + (i + 1) + "@email.com", Children = (i + 1) }; Database.Insert(extra); InMemoryExtraUserInfos.Add(extra); } }