public void Test_Add()
        {
            const string key = "CouchbaseDictionaryTests.Test_Add";
            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary<string, Poco>(_bucket, key);
            dictionary.Add("somekey1", new Poco {Name = "poco1"});
            dictionary.Add("somekey2", new Poco { Name = "poco2" });

            Assert.AreEqual(2, dictionary.Count);
        }
        public void Test_Indexer_Get()
        {
            const string key = "CouchbaseDictionaryTests.Test_Add";
            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary<string, Poco>(_bucket, key);
            dictionary.Add("somekey1", new Poco { Name = "poco1" });
            dictionary.Add("somekey2", new Poco { Name = "poco2" });

            var item = dictionary["somekey1"];
            Assert.AreEqual("poco1", item.Name);
        }
        public void Test_Remove()
        {
            const string key = "CouchbaseDictionaryTests.Test_Clear";
            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary<string, Poco>(_bucket, key);
            dictionary.Add("somekey1", new Poco { Name = "poco1" });
            dictionary.Add("somekey2", new Poco { Name = "poco2" });
            var result = dictionary.Remove("somekey2");

            Assert.IsTrue(result);
            Assert.AreEqual(1, dictionary.Count);
        }
Exemple #4
0
        public void Test_Add()
        {
            const string key = "CouchbaseDictionaryTests.Test_Add";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey1", new Poco {
                Name = "poco1"
            });
            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });

            Assert.AreEqual(2, dictionary.Count);
        }
Exemple #5
0
        public void Test_TryGetValue_DoesNotExist()
        {
            const string key = "CouchbaseDictionaryTests.Test_TryGetValue_DoesNotExist";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });

            Poco item;
            var  result = dictionary.TryGetValue("somekey3", out item);

            Assert.IsFalse(result);
            Assert.IsNull(item);
        }
Exemple #6
0
        public void Test_TryGetValue()
        {
            const string key = "CouchbaseDictionaryTests.Test_TryGetValue";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });

            Poco item;
            var  result = dictionary.TryGetValue("somekey2", out item);

            Assert.IsTrue(result);
            Assert.AreEqual("poco2", item.Name);
        }
Exemple #7
0
        public void Test_Indexer_Get()
        {
            const string key = "CouchbaseDictionaryTests.Test_Add";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey1", new Poco {
                Name = "poco1"
            });
            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });

            var item = dictionary["somekey1"];

            Assert.AreEqual("poco1", item.Name);
        }
Exemple #8
0
        public void Test_Remove()
        {
            const string key = "CouchbaseDictionaryTests.Test_Clear";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey1", new Poco {
                Name = "poco1"
            });
            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });
            var result = dictionary.Remove("somekey2");

            Assert.IsTrue(result);
            Assert.AreEqual(1, dictionary.Count);
        }
Exemple #9
0
        public void Test_ContainsKey_KeyIsNotFound()
        {
            const string key = "CouchbaseDictionaryTests.Test_ContainsKey_KeyIsNotFound";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey1", new Poco {
                Name = "poco1"
            });
            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });

            var result = dictionary.ContainsKey("somekey");

            Assert.IsFalse(result);
        }
Exemple #10
0
        private static void DictionaryDemo(IBucket bucket)
        {
            //var dictionary = new Dictionary<string, PizzaEmployee>();
            var dictionary = new CouchbaseDictionary <string, PizzaEmployee>(bucket, "Dictionary_PizzaStaff");

            dictionary.Clear();

            dictionary.Add("Matt", new PizzaEmployee {
                Shift = "8-5", HourlyWage = 7.25M
            });
            dictionary.Add("Mary", new PizzaEmployee {
                Shift = "5-12", HourlyWage = 8.25M
            });

            foreach (var key in dictionary.Keys)
            {
                Console.WriteLine($"Employee '{key}' makes {dictionary[key].HourlyWage}/hour");
            }
            Console.WriteLine();

            dictionary.Add("Hiro", new PizzaEmployee {
                Shift = "5-12", HourlyWage = 10.25M
            });

            try
            {
                dictionary.Add("Matt", new PizzaEmployee {
                    Shift = "8-12", HourlyWage = 20.00M
                });
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Can't add 'Matt' to the dictionary twice.");
                Console.WriteLine();
            }

            foreach (var key in dictionary.Keys)
            {
                Console.WriteLine($"Employee '{key}' makes {dictionary[key].HourlyWage}/hour");
            }
        }
        public void Test_ContainsKey_KeyIsNotFound()
        {
            const string key = "CouchbaseDictionaryTests.Test_ContainsKey_KeyIsNotFound";
            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary<string, Poco>(_bucket, key);
            dictionary.Add("somekey1", new Poco { Name = "poco1" });
            dictionary.Add("somekey2", new Poco { Name = "poco2" });

            var result = dictionary.ContainsKey("somekey");
            Assert.IsFalse(result);
        }
        public void Test_TryGetValue_DoesNotExist()
        {
            const string key = "CouchbaseDictionaryTests.Test_TryGetValue_DoesNotExist";
            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary<string, Poco>(_bucket, key);
            dictionary.Add("somekey2", new Poco { Name = "poco2" });

            Poco item;
            var result = dictionary.TryGetValue("somekey3", out item);

            Assert.IsFalse(result);
            Assert.IsNull(item);
        }
        public void Test_TryGetValue()
        {
            const string key = "CouchbaseDictionaryTests.Test_TryGetValue";
            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary<string, Poco>(_bucket, key);
            dictionary.Add("somekey2", new Poco { Name = "poco2" });

            Poco item;
            var result = dictionary.TryGetValue("somekey2", out item);

            Assert.IsTrue(result);
            Assert.AreEqual("poco2", item.Name);
        }
Exemple #14
0
        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();
        }