Esempio n. 1
0
        public async Task Test_Query_Update_PreserveExpiry()
        {
            await _fixture.BuildAsync();

            var docId      = System.Guid.NewGuid().ToString();
            var doc        = new { id = docId, testName = nameof(Test_Query_Update_PreserveExpiry), content = "initial" };
            var collection = await _fixture.GetDefaultCollection();

            var opts = new InsertOptions().Expiry(TimeSpan.FromSeconds(30));
            await collection.InsertAsync(docId, doc, options : opts);

            try
            {
                var result = await _fixture.Cluster.QueryAsync <dynamic>("UPDATE default AS d SET d.content = 'updated' WHERE d.id = $1",
                                                                         opts => opts.Parameter(docId)
                                                                         .PreserveExpiry(true));

                // for server version >= 7.1.0, we expect it to succeed.
                Assert.Empty(result.Errors);
                Assert.Equal <uint?>(1, result.MetaData?.Metrics?.MutationCount);
            }
            catch (CouchbaseException ex)
            {
                // for < 7.1.0, we expect an appropriate error.
                Assert.Contains("Unrecognized parameter in request: preserve_expiry", ex.Message);;
            }
        }
        public async Task Test_AddAsync()
        {
            var key1 = Guid.NewGuid().ToString();
            var col  = await _fixture.GetDefaultCollection();

            var list = col.List <int?>(key1);

            try
            {
                await list.AddAsync(4);

                Assert.True(await list.ContainsAsync(4));
                await foreach (var d in list)
                {
                    Assert.NotNull(d);
                }
                Assert.True(await list.RemoveAsync(4));
            }
            finally
            {
                await col.RemoveAsync(key1);
            }
        }