public async Task Basic() { couchbase.Clear(); await bucket.UpsertSafeAsync("hello", "world!"); Assert.Equal("world!", await bucket.GetSafeAsync <string>("hello")); }
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 WriteReadOne() { // Ensure that the database starts out empty (because we flushed it in the constructor). await Assert.ThrowsAsync <CouchbaseKeyValueResponseException>(async() => await bucket.GetSafeAsync <string>("one")); await Assert.ThrowsAsync <CouchbaseKeyValueResponseException>(async() => await bucket.GetSafeAsync <string>("two")); // Do a simple write/read test. await bucket.UpsertSafeAsync("one", "1"); Assert.Equal("1", await bucket.GetSafeAsync <string>("one")); }
public async Task WriteReadOne() { // Ensure that the database starts out empty. couchbase.Clear(); await Assert.ThrowsAsync <CouchbaseKeyValueResponseException>(async() => await bucket.GetSafeAsync <string>("one")); await Assert.ThrowsAsync <CouchbaseKeyValueResponseException>(async() => await bucket.GetSafeAsync <string>("two")); // Do a simple write/read test. await bucket.UpsertSafeAsync("one", "1"); Assert.Equal("1", await bucket.GetSafeAsync <string>("one")); // Do another flush just for fun. couchbase.Clear(); await Assert.ThrowsAsync <CouchbaseKeyValueResponseException>(async() => await bucket.GetSafeAsync <string>("one")); await Assert.ThrowsAsync <CouchbaseKeyValueResponseException>(async() => await bucket.GetSafeAsync <string>("two")); }
public async Task WriteReadList() { // Ensure that the database starts out empty. Assert.Empty(from doc in context.Query <object>() select doc); // Verify that the generated CreateKey() methods return the // correct values. Assert.Equal($"{Person.PersistedType}::0", Person.CreateKey("0")); Assert.Equal($"{City.PersistedType}::Woodinville", City.CreateKey("Woodinville")); // Verify that we can write generated entity models. var jack = new Person() { Id = 0, Name = "Jack", Age = 10, Gender = Gender.Male, Data = new byte[] { 0, 1, 2, 3, 4 } }; var jill = new Person() { Id = 1, Name = "Jill", Age = 11, Gender = Gender.Female, Data = new byte[] { 5, 6, 7, 8, 9 } }; Assert.Equal("Test.Neon.Models.Definitions.Person::0", jack.GetKey()); Assert.Equal("Test.Neon.Models.Definitions.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 <Person>(Person.CreateKey(0)); var jillRead = await bucket.GetSafeAsync <Person>(Person.CreateKey(1)); Assert.Equal("Test.Neon.Models.Definitions.Person::0", jackRead.GetKey()); Assert.Equal("Test.Neon.Models.Definitions.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 Person 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); await bucket.WaitForIndexerAsync(); //----------------------------------------------------------------- // Query for the people and verify var peopleQuery = (from doc in context.Query <Person>() 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()); // $todo(jeff.lill): https://github.com/nforgeio/neonKUBE/issues/475 //----------------------------------------------------------------- // 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(Person.SameTypeAs(jack)); Assert.False(Person.SameTypeAs(city)); Assert.False(Person.SameTypeAs(null)); }
public async Task HostsDbStacks() { // Deploy a couple of simple NodeJS based services as stacks, one // listening on port 8080 and the other on 8081. We're also going // to use the [HostsFixture] to map a couple of DNS names to the local // loopback address and then use these to query the services and finally, // we're going to do some things to Couchbase. // Confirm that Docker starts out with no running stacks or services. Assert.Empty(fixture.ListStacks()); Assert.Empty(fixture.ListServices()); // Use the [HostsFixture] to initialize a couple DNS entries and then verify that these work. hosts.AddHostAddress("test-foo.com", "127.0.0.1", deferCommit: true); hosts.AddHostAddress("test-bar.com", "127.0.0.1", deferCommit: true); hosts.Commit(); Assert.Equal(new IPAddress[] { IPAddress.Parse("127.0.0.1") }, Dns.GetHostAddresses("test-foo.com")); Assert.Equal(new IPAddress[] { IPAddress.Parse("127.0.0.1") }, Dns.GetHostAddresses("test-bar.com")); // Spin up a couple of NodeJS services configuring them to return // different text using the OUTPUT environment variable. var fooCompose = @"version: '3' services: web: image: nhive/node ports: - ""8080:80"" environment: - ""OUTPUT=FOO"" "; fixture.DeployStack("foo-stack", fooCompose); var barCompose = @"version: '3' services: web: image: nhive/node ports: - ""8081:80"" environment: - ""OUTPUT=BAR"" "; fixture.DeployStack("bar-stack", barCompose); // Verify that each of the services are returning the expected output. using (var client = new HttpClient()) { Assert.Equal("FOO", client.GetStringAsync("http://test-foo.com:8080").Result.Trim()); Assert.Equal("BAR", client.GetStringAsync("http://test-bar.com:8081").Result.Trim()); } // Do some Couchbase operations to prove that we can. bucket.UpsertSafeAsync("one", "1").Wait(); bucket.UpsertSafeAsync("two", "2").Wait(); Assert.Equal("1", await bucket.GetSafeAsync <string>("one")); Assert.Equal("2", await bucket.GetSafeAsync <string>("two")); // Remove one of the stacks and verify. fixture.RemoveStack("foo-stack"); Assert.Empty(fixture.ListStacks().Where(s => s.Name == "foo-stack")); }