public async Task CustomNames() { // Ensure that the database starts out empty. Assert.Empty(from doc in context.Query <object>() select doc); // Verify that we can write generated entity models. var jack = new CustomPerson() { Id = 0, Name = "Jack", Age = 10, Gender = Gender.Male, Data = new byte[] { 0, 1, 2, 3, 4 } }; var jill = new CustomPerson() { Id = 1, Name = "Jill", Age = 11, Gender = Gender.Female, Data = new byte[] { 5, 6, 7, 8, 9 } }; Assert.Equal("custom-person::0", jack.GetKey()); Assert.Equal("custom-person::1", jill.GetKey()); await bucket.UpsertSafeAsync(jack, persistTo : PersistTo.One); await bucket.UpsertSafeAsync(jill, persistTo : PersistTo.One); // Verify that we can read them. var jackRead = await bucket.GetSafeAsync <CustomPerson>(CustomPerson.CreateKey(0)); var jillRead = await bucket.GetSafeAsync <CustomPerson>(CustomPerson.CreateKey(1)); Assert.Equal("custom-person::0", jackRead.GetKey()); Assert.Equal("custom-person::1", jillRead.GetKey()); Assert.True(jack == jackRead); Assert.True(jill == jillRead); //----------------------------------------------------------------- // Persist a [City] entity (which has a different entity type) and then // perform a N1QL query to list the [CustomPerson] entities and verify that // we get only Jack and Jill back. This verifies the the [TypeFilter] // attribute is generated and working correctly. var city = new City() { Name = "Woodinville", Population = 12345 }; var result = await bucket.UpsertAsync(city); bucket.WaitForIndexer(); //----------------------------------------------------------------- // Query for the people and verify var peopleQuery = (from doc in context.Query <CustomPerson>() select doc); var people = peopleQuery.ToList(); Assert.Equal(2, people.Count); Assert.Contains(people, p => p.Name == "Jack"); Assert.Contains(people, p => p.Name == "Jill"); //----------------------------------------------------------------- // Query for the city and verify. var cityQuery = from doc in context.Query <City>() select doc; var cities = cityQuery.ToList(); Assert.Single(cities); Assert.Contains(cities, p => p.Name == "Woodinville"); //----------------------------------------------------------------- // Query for documents that don't exist and verify. var rawResults = await bucket.QueryAsync <object>($"select * from `{bucket.Name}` where __T=\"Test.Neon.Models.Definitions.Country\";"); var countryQuery = from doc in context.Query <Country>() select doc; Assert.Empty(rawResults.ToList()); Assert.Empty(countryQuery.ToList()); //----------------------------------------------------------------- // Verify that plain old object serialization still works. var poo = new PlainOldObject() { Foo = "bar" }; await bucket.UpsertSafeAsync("poo", poo, persistTo : PersistTo.One); poo = await bucket.GetSafeAsync <PlainOldObject>("poo"); Assert.Equal("bar", poo.Foo); //----------------------------------------------------------------- // Extra credit #1: Verify that [DeepClone()] works. var clone = jack.DeepClone(); Assert.Equal(jack.Name, clone.Name); Assert.Equal(jack.Age, clone.Age); Assert.Equal(jack.Gender, clone.Gender); Assert.NotSame(jack.Data, clone.Data); //----------------------------------------------------------------- // Extra credit #2: Verify that [SameTypeAs()] works. Assert.True(CustomPerson.SameTypeAs(jack)); Assert.False(CustomPerson.SameTypeAs(city)); Assert.False(CustomPerson.SameTypeAs(null)); }