示例#1
0
        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);
                }
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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);
                    });
                }
            }
        }
示例#5
0
        private async Task <ConfirmationRecord> GetUserEmailConfirmationAsync(string email)
        {
            RavenUserEmail userEmail = await GetUserEmailAsync(email).ConfigureAwait(false);

            return((userEmail != null)
                ? userEmail.ConfirmationRecord
                : null);
        }
示例#6
0
        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));
        }
示例#7
0
        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);
                }
            }
        }
示例#8
0
        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);
                }
            }
        }
示例#9
0
        // 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));
        }
示例#10
0
        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);
                }
            }
        }
示例#11
0
        // privates

        private Task <RavenUserEmail> GetUserEmailAsync(string email)
        {
            string keyToLookFor = RavenUserEmail.GenerateKey(email);

            return(_documentSession.LoadAsync <RavenUserEmail>(keyToLookFor));
        }