public async Task FindByEmailAsync_Should_Return_Null_If_User_Is_Not_Available() { const string userName = "******"; const string email = "*****@*****.**"; const string emailToLookFor = "*****@*****.**"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; RavenUser user = new RavenUser(userName, email); RavenUserEmail userEmail = new RavenUserEmail(email, user.Id); await ses.StoreAsync(user); await ses.StoreAsync(userEmail); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserEmailStore <RavenUser> userEmailStore = new RavenUserStore <RavenUser>(ses); RavenUser user = await userEmailStore.FindByEmailAsync(emailToLookFor); Assert.Null(user); } } }
public async Task GetEmailAsync_Should_Return_User_Email_If_Available() { const string userName = "******"; const string userId = "RavenUsers/Tugberk"; const string email = "*****@*****.**"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; RavenUser user = new RavenUser(userName, email); RavenUserEmail userEmail = new RavenUserEmail(email, user.Id); await ses.StoreAsync(user); await ses.StoreAsync(userEmail); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserEmailStore <RavenUser> userEmailStore = new RavenUserStore <RavenUser>(ses); RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId); string userEmail = await userEmailStore.GetEmailAsync(ravenUser); Assert.NotNull(userEmail); Assert.Equal(email, userEmail); } } }
public async Task SetEmailConfirmedAsync(TUser user, bool confirmed) { if (user == null) { throw new ArgumentNullException("user"); } if (user.Email == null) { throw new InvalidOperationException("Cannot set the confirmation status of the e-mail because user doesn't have an e-mail."); } RavenUserEmail userEmail = await GetUserEmailAsync(user.Email).ConfigureAwait(false); if (userEmail == null) { throw new InvalidOperationException("Cannot set the confirmation status of the e-mail because user doesn't have an e-mail as RavenUserEmail document."); } if (confirmed) { userEmail.SetConfirmed(); } else { userEmail.SetUnconfirmed(); } }
public async Task SetEmailConfirmedAsync_Should_Throw_InvalidOperationException_If_User_Email_Property_Is_Not_Available() { const string userName = "******"; const string userId = "RavenUsers/Tugberk"; const string email = "*****@*****.**"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; RavenUser user = new RavenUser(userName); RavenUserEmail userEmail = new RavenUserEmail(email, user.Id); await ses.StoreAsync(user); await ses.StoreAsync(userEmail); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserEmailStore <RavenUser> userEmailStore = new RavenUserStore <RavenUser>(ses); RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await userEmailStore.SetEmailConfirmedAsync(ravenUser, confirmed: true); }); } } }
private async Task <ConfirmationRecord> GetUserEmailConfirmationAsync(string email) { RavenUserEmail userEmail = await GetUserEmailAsync(email).ConfigureAwait(false); return((userEmail != null) ? userEmail.ConfirmationRecord : null); }
public Task SetEmailAsync(TUser user, string email) { if (user == null) { throw new ArgumentNullException("user"); } if (email == null) { throw new ArgumentNullException("email"); } user.SetEmail(email); RavenUserEmail ravenUserEmail = new RavenUserEmail(email, user.Id); return(_documentSession.StoreAsync(ravenUserEmail)); }
public async Task SetEmailAsync_Should_Set_Email_And_SaveChangesAsync_Should_Throw_ConcurrencyException_If_The_Email_Already_Exists() { const string userName = "******"; const string email = "*****@*****.**"; const string userName2 = "Tugberk2"; const string userId2 = "RavenUsers/Tugberk2"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; RavenUser user = new RavenUser(userName, email); RavenUser user2 = new RavenUser(userName2); RavenUserEmail userEmail = new RavenUserEmail(email, user.Id); await ses.StoreAsync(user); await ses.StoreAsync(user2); await ses.StoreAsync(userEmail); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserEmailStore <RavenUser> userEmailStore = new RavenUserStore <RavenUser>(ses); RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId2); await userEmailStore.SetEmailAsync(ravenUser, email); await Assert.ThrowsAsync <ConcurrencyException>(async() => { await ses.SaveChangesAsync(); }); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId2); Assert.Null(ravenUser.Email); } } }
public async Task SetEmailAsync_Should_Set_The_Email_Correctly() { const string userName = "******"; const string userId = "RavenUsers/Tugberk"; const string emailToSave = "*****@*****.**"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; RavenUser user = new RavenUser(userName) { UserName = userName }; await ses.StoreAsync(user); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserEmailStore <RavenUser> userEmailStore = new RavenUserStore <RavenUser>(ses); RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId); await userEmailStore.SetEmailAsync(ravenUser, emailToSave); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; string keyToLookFor = RavenUserEmail.GenerateKey(emailToSave); RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId); RavenUserEmail userEmail = await ses.LoadAsync <RavenUserEmail>(keyToLookFor); Assert.NotNull(userEmail); Assert.Equal(emailToSave, ravenUser.Email); Assert.Equal(emailToSave, userEmail.Email); Assert.Equal(userId, userEmail.UserId); } } }
// IUserEmailStore public async Task <TUser> FindByEmailAsync(string email) { if (email == null) { throw new ArgumentNullException("email"); } string keyToLookFor = RavenUserEmail.GenerateKey(email); RavenUserEmail ravenUserEmail = await _documentSession .Include <RavenUserEmail, TUser>(usrEmail => usrEmail.UserId) .LoadAsync(keyToLookFor) .ConfigureAwait(false); return((ravenUserEmail != null) ? await _documentSession.LoadAsync <TUser>(ravenUserEmail.UserId).ConfigureAwait(false) : default(TUser)); }
public async Task SetEmailConfirmedAsync_With_Confirmed_Param_False_Should_Set_The_Email_As_Not_Confirmed_If_Confirmed_Already() { const string userName = "******"; const string userId = "RavenUsers/Tugberk"; const string email = "*****@*****.**"; using (IDocumentStore store = CreateEmbeddableStore()) { using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; RavenUser user = new RavenUser(userName, email); RavenUserEmail userEmail = new RavenUserEmail(email, user.Id); userEmail.SetConfirmed(); await ses.StoreAsync(user); await ses.StoreAsync(userEmail); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; IUserEmailStore <RavenUser> userEmailStore = new RavenUserStore <RavenUser>(ses); RavenUser ravenUser = await ses.LoadAsync <RavenUser>(userId); await userEmailStore.SetEmailConfirmedAsync(ravenUser, confirmed : false); await ses.SaveChangesAsync(); } using (IAsyncDocumentSession ses = store.OpenAsyncSession()) { ses.Advanced.UseOptimisticConcurrency = true; string keyToLookFor = RavenUserEmail.GenerateKey(email); RavenUserEmail userEmail = await ses.LoadAsync <RavenUserEmail>(keyToLookFor); Assert.Null(userEmail.ConfirmationRecord); } } }
// privates private Task <RavenUserEmail> GetUserEmailAsync(string email) { string keyToLookFor = RavenUserEmail.GenerateKey(email); return(_documentSession.LoadAsync <RavenUserEmail>(keyToLookFor)); }