コード例 #1
0
        public async Task UserNotFoundShouldReturnNullWhenThrowExceptionsOn()
        {
            using (var store = new UserStoreFixture <ElasticUser>(ElasticServerUrl, "elasticidentity-tests", true, true))
            {
                var user404 = await With503RetryForIndexRecovery(async() => await store.FindByIdAsync("missing"), 5);

                Assert.Null(user404);
            }
        }
コード例 #2
0
        public async Task UpdateUser()
        {
            using (var store = new UserStoreFixture <ElasticUser>())
            {
                var user = new ElasticUser(UserId, UserName);

                await store.CreateAsync(user);

                user = await store.FindByIdAsync(user.Id);

                user.Roles.Add("hello");

                await store.UpdateAsync(user);

                user = await store.FindByIdAsync(user.Id);

                Assert.True(user.Roles.Contains("hello"));

                // create another user object from the same id
                var sameUser = await store.FindByIdAsync(user.Id);

                sameUser.Roles.Add("another_role");
                await store.UpdateAsync(sameUser);

                sameUser = await store.FindByIdAsync(sameUser.Id);

                Assert.True(sameUser.Roles.Contains("another_role"));

                // same id, different versions
                Assert.Equal(user.Id, sameUser.Id);
                Assert.NotEqual(user.Version, sameUser.Version);

                // exception should be thrown as we're attempting to
                // update the original, out of date, user.
                user.Roles.Add("bad_role");
                await Assert.ThrowsAsync <Elasticsearch.Net.ElasticsearchClientException>(async() => await store.UpdateAsync(user));
            }
        }
コード例 #3
0
        public async Task FindById()
        {
            using (var store = new UserStoreFixture <ElasticUser>())
            {
                var user = new ElasticUser(UserId, UserName);

                await store.CreateAsync(user);

                var elasticUser = await store.FindByIdAsync(user.Id);

                Assert.NotNull(elasticUser);
                Assert.Equal(user.Id, elasticUser.Id);
            }
        }