示例#1
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);
                }
            }
        }
        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);
                }
            }
        }