public async Task Find() { // Ensure that the database starts out empty. Assert.Empty(from doc in context.Query <object>() select doc); // Verify that finding a document that doesn't exist returns NULL. Assert.Null(await bucket.FindSafeAsync <Person>(Person.CreateKey("0"))); Assert.Null(await bucket.FindDocumentSafeAsync <Person>(Person.CreateKey("0"))); // Verify that finding a document that does exist works. var jack = new Person() { Id = 0, Name = "Jack", Age = 10, Gender = Gender.Male, Data = new byte[] { 0, 1, 2, 3, 4 } }; await bucket.UpsertSafeAsync(jack, persistTo : PersistTo.One); var person = await bucket.FindSafeAsync <Person>(Person.CreateKey("0")); Assert.NotNull(person); Assert.Equal(jack.Id, person.Id); Assert.Equal(jack.Name, person.Name); Assert.Equal(jack.Age, person.Age); Assert.Equal(jack.Gender, person.Gender); Assert.Equal(jack.Data, person.Data); var personDoc = await bucket.FindDocumentSafeAsync <Person>(Person.CreateKey("0")); Assert.NotNull(personDoc); Assert.Equal(jack.Id, personDoc.Content.Id); Assert.Equal(jack.Name, personDoc.Content.Name); Assert.Equal(jack.Age, personDoc.Content.Age); Assert.Equal(jack.Gender, personDoc.Content.Gender); Assert.Equal(jack.Data, personDoc.Content.Data); }
public async Task Basic() { // Basic test to verify that we can put/get/remove a document. await bucket.UpsertSafeAsync("hello", "world!"); Assert.Equal("world!", await bucket.GetSafeAsync <string>("hello")); await bucket.RemoveSafeAsync("hello"); Assert.Null(await bucket.FindSafeAsync <string>("hello")); }
public async Task Flush() { var indexQuery = $"select * from system:indexes where keyspace_id={CbHelper.Literal(bucket.Name)}"; // Flush and verify that the primary index was created by default. couchbase.Clear(); var indexes = await bucket.QuerySafeAsync <JObject>(indexQuery); Assert.Single(indexes); var index = (JObject)indexes.First().GetValue("indexes"); Assert.True((bool)index.GetValue("is_primary")); Assert.Equal("idx_primary", (string)index.GetValue("name")); // Write some data, verify that it was written then flush // the bucket and verify that the data is gone. await bucket.UpsertSafeAsync("hello", "world!"); Assert.Equal("world!", await bucket.GetSafeAsync <string>("hello")); couchbase.Clear(); Assert.Null(await bucket.FindSafeAsync <string>("hello")); // Create a secondary index and verify. await bucket.QuerySafeAsync <dynamic>($"create index idx_foo on {CbHelper.LiteralName(bucket.Name)} ( {CbHelper.LiteralName("Test")} )"); indexes = await bucket.QuerySafeAsync <JObject>(indexQuery); Assert.Equal(2, indexes.Count); // Expecting the primary and new secondary index // Clear the database and then verify that only the // recreated primary index exists. couchbase.Clear(); indexes = await bucket.QuerySafeAsync <JObject>(indexQuery); Assert.Single(indexes); index = (JObject)indexes.First().GetValue("indexes"); Assert.True((bool)index.GetValue("is_primary")); Assert.Equal("idx_primary", (string)index.GetValue("name")); }
public async Task Clear() { var indexQuery = $"select * from system:indexes where keyspace_id={CouchbaseHelper.Literal(bucket.Name)}"; // Flush and verify that the primary index was created by default. couchbase.Clear(); var indexes = await bucket.QuerySafeAsync <JObject>(indexQuery); Assert.Single(indexes); var index = (JObject)indexes.First().GetValue("indexes"); Assert.True((bool)index.GetValue("is_primary")); Assert.Equal("#primary", (string)index.GetValue("name")); // Write some data, verify that it was written then flush // the bucket and verify that the data is gone. await bucket.UpsertSafeAsync("hello", "world!"); Assert.Equal("world!", await bucket.GetSafeAsync <string>("hello")); couchbase.Clear(); Assert.Null(await bucket.FindSafeAsync <string>("hello")); // Create a secondary index and verify. await bucket.QuerySafeAsync <dynamic>($"create index idx_foo on {CouchbaseHelper.LiteralName(bucket.Name)} ( {CouchbaseHelper.LiteralName("Test")} )"); indexes = await bucket.QuerySafeAsync <JObject>(indexQuery); Assert.Equal(2, indexes.Count); // Expecting the primary and new secondary index // Clear the database and then verify that only the // recreated primary index exists. couchbase.Clear(); indexes = await bucket.QuerySafeAsync <JObject>(indexQuery); Assert.Single(indexes); index = (JObject)indexes.First().GetValue("indexes"); Assert.True((bool)index.GetValue("is_primary")); Assert.Equal("#primary", (string)index.GetValue("name")); // Create a fts index and verify. var ftsIndex = new Dictionary <string, object>(); ftsIndex.Add("type", "fulltext-index"); ftsIndex.Add("name", "test"); ftsIndex.Add("sourceType", "couchbase"); ftsIndex.Add("sourceName", "test"); await jsonClient.PutAsync("/api/index/test", JsonConvert.SerializeObject(ftsIndex)); ftsIndex = new Dictionary <string, object>(); ftsIndex.Add("type", "fulltext-index"); ftsIndex.Add("name", "test123"); ftsIndex.Add("sourceType", "couchbase"); ftsIndex.Add("sourceName", "test"); await jsonClient.PutAsync("/api/index/test123", JsonConvert.SerializeObject(ftsIndex)); var ftsIndexes = jsonClient.GetAsync <dynamic>("/api/index").Result.indexDefs; Assert.True(((JObject)ftsIndexes.indexDefs).Count == 2); // Clear the database and then verify that only the // recreated primary index exists. couchbase.Clear(); ftsIndexes = jsonClient.GetAsync <dynamic>("/api/index").Result.indexDefs; Assert.True(((JObject)ftsIndexes.indexDefs).Count == 0); }