コード例 #1
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);
                }
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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);
                }
            }
        }