public async Task UpdateUser() { // Create a session and user store for this test. var session = SessionFactory.OpenSession(); var userStore = new TestUserStore(session); // Create and save a user. string userName = "******"; string email = "*****@*****.**"; var user = new TestUser { UserName = userName }; using (var transaction = session.BeginTransaction()) { await userStore.CreateAsync(user); transaction.Commit(); } // Check the user has an id and a username. Assert.IsNotNull(user.Id); Assert.IsNotNull(user.UserName); Assert.IsNull(user.Email); // Update the user's email address. using (var transaction = session.BeginTransaction()) { user.Email = email; await userStore.UpdateAsync(user); transaction.Commit(); } // Create a new session and user store so that we actually hit the database and not the cache. userStore.Dispose(); session.Dispose(); session = SessionFactory.OpenSession(); userStore = new TestUserStore(session); // Load and update the user. TestUser updatedUser; using (var transaction = session.BeginTransaction()) { updatedUser = await userStore.FindByIdAsync(user.Id); transaction.Commit(); } // Check the email has been updated and saved. Assert.AreEqual(updatedUser.Email, email); }
public async Task UpdateUser() { // Create a session and user store for this test. var session = SessionFactory.OpenSession(); var userStore = new TestUserStore<TestUser>(session); // Create and save a user. string userName = "******"; string email = "*****@*****.**"; var user = new TestUser { UserName = userName }; using (var transaction = session.BeginTransaction()) { await userStore.CreateAsync(user); transaction.Commit(); } // Check the user has an id and a username. Assert.IsNotNull(user.Id); Assert.IsNotNull(user.UserName); Assert.IsNull(user.Email); // Update the user's email address. using (var transaction = session.BeginTransaction()) { user.Email = email; await userStore.UpdateAsync(user); transaction.Commit(); } // Create a new session and user store so that we actually hit the database and not the cache. userStore.Dispose(); session.Dispose(); session = SessionFactory.OpenSession(); userStore = new TestUserStore<TestUser>(session); // Load and update the user. TestUser updatedUser; using (var transaction = session.BeginTransaction()) { updatedUser = await userStore.FindByIdAsync(user.Id); transaction.Commit(); } // Check the email has been updated and saved. Assert.AreEqual(updatedUser.Email, email); }