コード例 #1
0
        public async Task SetEmailConfirmedAsync_Should_Throw_InvalidOperationException_If_User_Email_Property_Is_Available_But_UserEmail_Document_Not()
        {
            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);
                    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 Assert.ThrowsAsync <InvalidOperationException>(async() =>
                    {
                        await userEmailStore.SetEmailConfirmedAsync(ravenUser, confirmed: true);
                    });
                }
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
        public async Task SetEmailConfirmedAsync_Should_Throw_InvalidOperationException_If_User_Email_Property_Is_Available_But_UserEmail_Document_Not()
        {
            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);
                    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 Assert.ThrowsAsync<InvalidOperationException>(async () =>
                    {
                        await userEmailStore.SetEmailConfirmedAsync(ravenUser, confirmed: true);
                    });
                }
            }
        }
コード例 #4
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);
                }
            }
        }