// This will fail using SQLite in-memory as the transaction wraps the whole connection :/ Will probably need // to switch over to SQLite file based at some point. So that one connection can create the DB and a different connection can // do the tests. public void ExternalTransactionDiscarded() { using (var scope = Database.GetTransaction()) { var user = new UserDecorated { Name = "Name" + 16, Age = 20 + 16, DateOfBirth = new DateTime(1970, 1, 1).AddYears(16), Savings = 50.00m + (1.01m * 16) }; InMemoryUsers.Add(user); Database.Insert(user); var extra = new ExtraUserInfoDecorated { UserId = user.UserId, Email = "email" + 16 + "@email.com", Children = 16 }; InMemoryExtraUserInfos.Add(extra); Database.Insert(extra); } var count = Database.ExecuteScalar <long>("SELECT COUNT(*) FROM Users"); Assert.AreEqual(count, 15); }
public void Page_MultiPoco() { var page = Database.Page <CustomerUser>(2, 5, "SELECT Users.UserId AS Id, Users.Name CustomerName, ExtraUserInfos.Email CustomerEmail FROM Users INNER JOIN ExtraUserInfos ON Users.UserId = ExtraUserInfos.UserId"); foreach (var customer in page.Items) { var found = false; var emailMatch = false; foreach (var inMemoryUser in InMemoryUsers) { if (customer.CustomerName == inMemoryUser.Name) { found = true; emailMatch = InMemoryExtraUserInfos.Exists(info => info.UserId == customer.Id && info.Email == customer.CustomerEmail); break; } } if (!found) { Assert.Fail("Could not find user '" + customer.CustomerName + "' in InMemoryUsers."); } if (!emailMatch) { Assert.Fail("Email doesn't match for user '" + customer.CustomerName + "' in InMemoryExtraUserInfos."); } } // Check other stats Assert.AreEqual(page.Items.Count, 5); Assert.AreEqual(page.CurrentPage, 2); Assert.AreEqual(page.ItemsPerPage, 5); Assert.AreEqual(page.TotalItems, 15); Assert.AreEqual(page.TotalPages, 3); }
public void NestedTransactionThatFailsAbortsWholeUsingBeginAbort() { Database.BeginTransaction(); Database.BeginTransaction(); var user1 = new UserDecorated { Name = "Name" + 16, Age = 20 + 16, DateOfBirth = new DateTime(1970, 1, 1).AddYears(16), Savings = 50.00m + (1.01m * 16) }; InMemoryUsers.Add(user1); Database.Insert(user1); var extra1 = new ExtraUserInfoDecorated { UserId = user1.UserId, Email = "email" + 16 + "@email.com", Children = 16 }; InMemoryExtraUserInfos.Add(extra1); Database.Insert(extra1); Database.AbortTransaction(); var user = new UserDecorated { Name = "Name" + 16, Age = 20 + 16, DateOfBirth = new DateTime(1970, 1, 1).AddYears(16), Savings = 50.00m + (1.01m * 16) }; InMemoryUsers.Add(user); Database.Insert(user); var extra = new ExtraUserInfoDecorated { UserId = user.UserId, Email = "email" + 16 + "@email.com", Children = 16 }; InMemoryExtraUserInfos.Add(extra); Database.Insert(extra); Database.CompleteTransaction(); var count = Database.ExecuteScalar <long>("SELECT COUNT(*) FROM Users"); Assert.AreEqual(15, count); }