public async Task DeleteUser() { // 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 = "******"; 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); var userId = user.Id; // 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 delete the user. using (var transaction = session.BeginTransaction()) { user = await userStore.FindByIdAsync(userId); await userStore.DeleteAsync(user); transaction.Commit(); } // Check that the user has been deleted. var deletedUser = await userStore.FindByIdAsync(userId); Assert.IsNull(deletedUser); }
public async Task DeleteUser() { // 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 = "******"; 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); var userId = user.Id; // 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 delete the user. using (var transaction = session.BeginTransaction()) { user = await userStore.FindByIdAsync(userId); await userStore.DeleteAsync(user); transaction.Commit(); } // Check that the user has been deleted. var deletedUser = await userStore.FindByIdAsync(userId); Assert.IsNull(deletedUser); }