Example #1
0
        public async Task UserTests(bool directMode)
        {
            CosmosClient  client     = directMode ? DirectCosmosClient : GatewayCosmosClient;
            DatabaseCore  database   = (DatabaseInlineCore)client.GetDatabase(DatabaseId);
            List <string> createdIds = new List <string>();

            try
            {
                UserResponse userResponse = await database.CreateUserAsync("BasicQueryUser1");

                createdIds.Add(userResponse.User.Id);

                userResponse = await database.CreateUserAsync("BasicQueryUser2");

                createdIds.Add(userResponse.User.Id);

                userResponse = await database.CreateUserAsync("BasicQueryUser3");

                createdIds.Add(userResponse.User.Id);

                //Read All
                List <UserProperties> results = await this.ToListAsync(
                    database.GetUserQueryStreamIterator,
                    database.GetUserQueryIterator <UserProperties>,
                    null,
                    CosmosBasicQueryTests.RequestOptions
                    );

                CollectionAssert.IsSubsetOf(createdIds, results.Select(x => x.Id).ToList());

                //Basic query
                List <UserProperties> queryResults = await this.ToListAsync(
                    database.GetUserQueryStreamIterator,
                    database.GetUserQueryIterator <UserProperties>,
                    "select * from T where STARTSWITH(T.id, \"BasicQueryUser\")",
                    CosmosBasicQueryTests.RequestOptions
                    );

                CollectionAssert.AreEquivalent(createdIds, queryResults.Select(x => x.Id).ToList());
            }
            finally
            {
                foreach (string id in createdIds)
                {
                    await database.GetUser(id).DeleteAsync();
                }
            }
        }