private static void ListDemo(IBucket bucket) { //var pizzaPlaces = new List<PizzaPlace>(); var pizzaPlaces = new CouchbaseList <PizzaPlace>(bucket, "List_PizzaPlaces"); pizzaPlaces.Clear(); pizzaPlaces.Add(new PizzaPlace { Name = "Tammy's Pizza", Rating = 5, Delivery = false }); pizzaPlaces.Add(new PizzaPlace { Name = "Flyer's", Rating = 3, Delivery = true }); foreach (var pizzaPlace in pizzaPlaces) { Console.WriteLine(pizzaPlace.Name); } Console.WriteLine(); pizzaPlaces.Add(new PizzaPlace { Name = "Reggio", Rating = 4, Delivery = false }); foreach (var pizzaPlace in pizzaPlaces) { Console.WriteLine(pizzaPlace.Name); } }
public void Test_Add() { //arrange var builder = new Mock <IMutateInBuilder <List <Poco> > >(); builder.Setup(x => x.ArrayAppend(It.IsAny <Poco>(), It.IsAny <bool>())).Returns(builder.Object); builder.Setup(x => x.Execute()).Returns(new DocumentFragment <List <Poco> >(builder.Object) { Success = true }); var bucket = MockHelper.CreateBucket <Poco>(BucketKey); bucket.Setup(x => x.MutateIn <List <Poco> >(BucketKey)).Returns(builder.Object); var collection = new CouchbaseList <Poco>(bucket.Object, BucketKey); var poco = new Poco { Key = "Poco", Name = "Poco #1" }; //act/assert Assert.DoesNotThrow(() => collection.Add(poco)); builder.Verify(x => x.ArrayAppend(poco, true), Times.Once()); builder.Verify(x => x.Execute(), Times.Once()); }
public void Test_Add() { //arrange var builder = new Mock <IMutateInBuilder <List <Poco> > >(); builder.Setup(x => x.ArrayAppend(It.IsAny <Poco>(), It.IsAny <bool>())).Returns(builder.Object); builder.Setup(x => x.Execute()).Returns(new DocumentFragment <List <Poco> >(builder.Object) { Success = true }); var bucket = new Mock <IBucket>(); bucket.Setup(x => x.Insert(It.IsAny <Document <List <Poco> > >())). Returns(new DocumentResult <List <Poco> >(new OperationResult <List <Poco> > { Success = true })); bucket.Setup(x => x.MutateIn <List <Poco> >(It.IsAny <string>())).Returns(builder.Object); var collection = new CouchbaseList <Poco>(bucket.Object, "Thecollection"); //act/assert Assert.DoesNotThrow(() => collection.Add(new Poco { Key = "poco1", Name = "Poco-pica" })); }
public void Test_Add() { var collection = new CouchbaseList<Poco>(_bucket, "BucketListTests_Test_Add"); collection.Add(new Poco { Key = "poco1", Name = "Poco-pica" }); var item = collection[0]; Assert.AreEqual("poco1", item.Key); }
public void Test_Clear() { var collection = new CouchbaseList<Poco>(_bucket, "BucketListTests_Test_Clear"); collection.Add(new Poco { Key = "poco2", Name = "Poco-pica" }); collection.Clear(); var count = collection.Count; Assert.AreEqual(0, count); }
public void Test_Add() { var collection = new CouchbaseList <Poco>(_bucket, "BucketListTests_Test_Add"); collection.Add(new Poco { Key = "poco1", Name = "Poco-pica" }); var item = collection[0]; Assert.AreEqual("poco1", item.Key); }
public void Test_Clear() { var collection = new CouchbaseList <Poco>(_bucket, "BucketListTests_Test_Clear"); collection.Add(new Poco { Key = "poco2", Name = "Poco-pica" }); collection.Clear(); var count = collection.Count; Assert.AreEqual(0, count); }
public void Test_Enumeration() { var collection = new CouchbaseList<Poco>(_bucket, "BucketListTests_Test_Enumeration"); var numItems = 5; for (var i = 0; i < numItems; i++) { collection.Add(new Poco {Key = "poco"+i, Name = "Poco-pica"+i}); } foreach (var poco in collection) { Assert.IsNotNull(poco); } }
public void Test_Enumeration() { var collection = new CouchbaseList <Poco>(_bucket, "BucketListTests_Test_Enumeration"); var numItems = 5; for (var i = 0; i < numItems; i++) { collection.Add(new Poco { Key = "poco" + i, Name = "Poco-pica" + i }); } foreach (var poco in collection) { Assert.IsNotNull(poco); } }
public void Test_Add() { //arrange var builder = new Mock<IMutateInBuilder<List<Poco>>>(); builder.Setup(x => x.ArrayAppend(It.IsAny<Poco>(), It.IsAny<bool>())).Returns(builder.Object); builder.Setup(x => x.Execute()).Returns(new DocumentFragment<List<Poco>>(builder.Object) {Success = true}); var bucket = new Mock<IBucket>(); bucket.Setup(x => x.Insert(It.IsAny<Document<List<Poco>>>())). Returns(new DocumentResult<List<Poco>>(new OperationResult<List<Poco>> { Success = true })); bucket.Setup(x => x.MutateIn<List<Poco>>(It.IsAny<string>())).Returns(builder.Object); var collection = new CouchbaseList<Poco>(bucket.Object, "Thecollection"); //act/assert Assert.DoesNotThrow(()=> collection.Add(new Poco { Key = "poco1", Name = "Poco-pica" })); }
public static void Main(string[] args) { ClusterHelper.Initialize(new ClientConfiguration { Servers = new List <Uri> { new Uri("couchbase://localhost") } }); var bucket = ClusterHelper.GetBucket("data-structures"); // creates list document or uses existing list document // tag::createlist[] var list = new CouchbaseList <dynamic>(bucket, "myList"); // end::createlist[] // tag::examplesoflist[] // add 10 objects to the list for (var i = 0; i < 10; i++) { list.Add(new { num = i, foo = "bar" + Guid.NewGuid() }); } // remove an item from the list by index list.RemoveAt(5); // show an item from the list by index var item = list[5]; Console.WriteLine("6th item in the list: " + item.foo + " / " + item.num); // end::examplesoflist[] // --- queue Console.WriteLine(); // creates queue document or uses existing queue document // tag::createqueue[] var queue = new CouchbaseQueue <dynamic>(bucket, "myQueue"); // end::createqueue[] // tag::queueexample[] for (var i = 0; i < 3; i++) { queue.Enqueue(new { num = i, foo = "baz" + Guid.NewGuid() }); } // dequeue var item = queue.Dequeue(); Console.WriteLine("item num " + item.num + " was dequeued. There are now " + queue.Count + " items left in the queue."); // end::queueexample[] // --- dictionary Console.WriteLine(); // creates dictionary document or uses existing dictionary document // tag::createdict[] var dict = new CouchbaseDictionary <string, dynamic>(bucket, "myDict"); // end::createdict[] // add 5 k/v pairs to the dictionary // tag::dictexample[] for (var i = 0; i < 5; i++) { dict.Add("key" + Guid.NewGuid(), new { num = i, foo = "qux" + Guid.NewGuid() }); } // print out keys in the dictionary Console.WriteLine("There are " + dict.Keys.Count + " keys in the dictionary."); foreach (var key in dict.Keys) { Console.WriteLine("key: " + key + ", value.num: " + dict[key].num); } // end::dictexample[] ClusterHelper.Close(); }