Inheritance: global::ProtoBuf.IExtensible
        public void TestFlagOperations()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string flagName = "Name";

            var flagMapUpdate = new MapUpdate
            {
                flag_op = MapUpdate.FlagOp.DISABLE,
                field = new MapField { name = Serializer.Invoke(flagName), type = MapField.MapFieldType.FLAG }
            };

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, new List<MapUpdate> { flagMapUpdate });

            Assert.True(updatedMap1.Result.IsSuccess, updatedMap1.Result.ErrorMessage);
            var mapEntry = updatedMap1.Values.Single(s => s.Field.Name == flagName);
            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsFalse(mapEntry.FlagValue.Value);

            var flagMapUpdate2 = new MapUpdate
            {
                flag_op = MapUpdate.FlagOp.ENABLE,
                field = new MapField { name = Serializer.Invoke(flagName), type = MapField.MapFieldType.FLAG }
            };

            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                new List<MapUpdate> { flagMapUpdate2 });

            Assert.True(updatedMap2.Result.IsSuccess, updatedMap2.Result.ErrorMessage);
            mapEntry = updatedMap2.Values.Single(s => s.Field.Name == flagName);
            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsTrue(mapEntry.FlagValue.Value);
        }
        public void TestFlagOperations()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string flagName = "Name";
            byte[] flagNameBytes = Serializer(flagName);

            var options = new RiakDtUpdateOptions();
            options.SetIncludeContext(true);
            options.SetTimeout(new Timeout(TimeSpan.FromSeconds(60)));

            var flagMapUpdate = new MapUpdate
            {
                flag_op = MapUpdate.FlagOp.ENABLE,
                field = new MapField { name = flagNameBytes, type = MapField.MapFieldType.FLAG }
            };
            var update = new List<MapUpdate> { flagMapUpdate };
            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, update, options);

            Assert.True(updatedMap1.Result.IsSuccess, updatedMap1.Result.ErrorMessage);
            var mapEntry = updatedMap1.Values.Single(s => s.Field.Name == flagName);
            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsTrue(mapEntry.FlagValue.Value);

            flagMapUpdate.flag_op = MapUpdate.FlagOp.DISABLE;
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null, update, options);

            Assert.True(updatedMap2.Result.IsSuccess, updatedMap2.Result.ErrorMessage);
            mapEntry = updatedMap2.Values.Single(s => s.Field.Name == flagName);
            Assert.NotNull(mapEntry.FlagValue);
            Assert.IsFalse(mapEntry.FlagValue.Value);
        }
        public void Test1()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string setName = "set";

            // New Map with Set
            var setMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET }
            };

            // Add X, Y to set
            var addSet = new List<string> { "X", "Y" }.Select(s => Serializer.Invoke(s)).ToList();
            setMapUpdate.set_op.adds.AddRange(addSet);

            // Store
            var updatedMap1 = Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals,
                new List<MapUpdate> { setMapUpdate });

            // Add Z
            var setMapUpdate2 = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET }
            };

            var addSet2 = new List<string> { "Z" }.Select(s => Serializer.Invoke(s)).ToList();
            setMapUpdate2.set_op.adds.AddRange(addSet2);

            // Remove Set
            var fieldToRemove = new RiakDtMapField(setMapUpdate.field);

            // Store again
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context,
                new List<RiakDtMapField> { fieldToRemove }, new List<MapUpdate> { setMapUpdate2 });

            Assert.AreEqual(1, updatedMap2.Values.Count);

            var set = updatedMap2.Values.Single(s => s.Field.Name == setName);
            var setValues = set.SetValue.Select(v => Deserializer.Invoke(v)).ToList();

            Assert.AreEqual(1, setValues.Count);
            Assert.Contains("Z", setValues);
        }
        public void TestMapSetOperations()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string setName = "Name";

            var setMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET }
            };

            var addSet = new List<string> { "Alex" }.Select(s => Serializer.Invoke(s)).ToList();
            setMapUpdate.set_op.adds.AddRange(addSet);

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, new List<MapUpdate> { setMapUpdate });
            var setValues1 =
                updatedMap1.Values.Single(s => s.Field.Name == setName)
                    .SetValue.Select(v => Deserializer.Invoke(v))
                    .ToList();
            Assert.Contains("Alex", setValues1);
            Assert.AreEqual(1, setValues1.Count);

            setMapUpdate.set_op = new SetOp();
            var removeSet = addSet;
            var addSet2 = new List<string> { "Luke", "Jeremiah" }.Select(s => Serializer.Invoke(s)).ToList();
            setMapUpdate.set_op.adds.AddRange(addSet2);
            setMapUpdate.set_op.removes.AddRange(removeSet);

            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                new List<MapUpdate> { setMapUpdate });
            var setValues2 =
                updatedMap2.Values.Single(s => s.Field.Name == setName)
                    .SetValue.Select(v => Deserializer.Invoke(v))
                    .ToList();
            Assert.Contains("Luke", setValues2);
            Assert.Contains("Jeremiah", setValues2);
            Assert.AreEqual(2, setValues2.Count);
        }
        public void TestRegisterOperations()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string registerName = "Name";

            var registerMapUpdate = new MapUpdate
            {
                register_op = Serializer.Invoke("Alex"),
                field = new MapField { name = Serializer.Invoke(registerName), type = MapField.MapFieldType.REGISTER }
            };

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, new List<MapUpdate> { registerMapUpdate });
            Assert.AreEqual("Alex",
                Deserializer.Invoke(updatedMap1.Values.Single(s => s.Field.Name == registerName).RegisterValue));

            registerMapUpdate.register_op = Serializer.Invoke("Luke");
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                new List<MapUpdate> { registerMapUpdate });
            Assert.AreEqual("Luke",
                Deserializer.Invoke(updatedMap2.Values.Single(s => s.Field.Name == registerName).RegisterValue));
        }
        public void DtUpdateMapWithRecursiveDataWithoutContext_ThrowsException()
        {
            var nestedRemoves = new List<MapField>
            {
                new MapField { name = "field_name".ToRiakString(), type = MapField.MapFieldType.SET }
            };

            var mapUpdateNested = new MapUpdate { map_op = new MapOp() };
            mapUpdateNested.map_op.removes.AddRange(nestedRemoves);

            var map_op = new MapOp();
            map_op.updates.Add(mapUpdateNested);

            var mapUpdate = new MapUpdate { map_op = new MapOp() };
            mapUpdate.map_op.updates.Add(mapUpdateNested);

            var updates = new List<MapUpdate> { mapUpdate };

            Assert.Throws<ArgumentNullException>(
                () => Client.DtUpdateMap(
                        "bucketType", "bucket", "key", Serializer, (byte[])null, null, updates, null)
            );
        }
        public void Test2()
        {
            // New Map with Counter of value 5
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string counterName = "counter";

            var counterMapUpdate = new MapUpdate
            {
                counter_op = new CounterOp
                {
                    increment = 5
                },
                field = new MapField { name = Serializer.Invoke(counterName), type = MapField.MapFieldType.COUNTER }
            };

            // Store
            var updatedMap = Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals,
                new List<MapUpdate> { counterMapUpdate });

            // Increment by 2
            var counterMapUpdate2 = new MapUpdate
            {
                counter_op = new CounterOp
                {
                    increment = 2
                },
                field = new MapField { name = Serializer.Invoke(counterName), type = MapField.MapFieldType.COUNTER }
            };

            // Remove field
            var fieldToRemove = new RiakDtMapField(counterMapUpdate.field);

            // Store
            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap.Context,
                new List<RiakDtMapField> { fieldToRemove }, new List<MapUpdate> { counterMapUpdate2 });

            Assert.AreEqual(1, updatedMap2.Values.Count);

            var counterField = updatedMap2.Values.Single(s => s.Field.Name == counterName);
            Assert.AreEqual(2, counterField.Counter.Value);
        }
        public void Test5()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);
            const string setName = "set";

            // New Map with Set
            var setMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET }
            };

            // Add X, Y to set
            var addSet = new List<string> { "X", "Y" }.Select(s => Serializer.Invoke(s)).ToList();
            setMapUpdate.set_op.adds.AddRange(addSet);

            // Store
            var updatedMap1 = Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals,
                new List<MapUpdate> { setMapUpdate });
            updatedMap1.Result.IsSuccess.ShouldBeTrue();

            // Remove X from set
            var setMapUpdate2 = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = Serializer.Invoke(setName), type = MapField.MapFieldType.SET }
            };

            setMapUpdate2.set_op.removes.Add(Serializer("X"));

            // Store again, no context
            Assert.Throws<ArgumentNullException>(() =>
                Client.DtUpdateMap(id, Serializer, NoContext, NoRemovals, new List<MapUpdate> { setMapUpdate2 }));
        }
        public void Test3()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);

            // New map w/ Nested Map w/ Nested Set; Add X,Y to set
            byte[] innerMapName = Serializer("innerMap");
            byte[] innerMapSetName = Serializer("innerMap_innerSet");
            byte[][] adds = { Serializer("X"), Serializer("Y") };

            var innerMapUpdate = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = innerMapSetName, type = MapField.MapFieldType.SET }
            };
            innerMapUpdate.set_op.adds.AddRange(adds);

            var parentMapUpdate = new MapUpdate
            {
                field = new MapField { name = innerMapName, type = MapField.MapFieldType.MAP },
                map_op = new MapOp()
            };

            parentMapUpdate.map_op.updates.Add(innerMapUpdate);

            var updatedMap = Client.DtUpdateMap(id, Serializer, NoContext, null, new List<MapUpdate> { parentMapUpdate });

            Assert.AreEqual(1, updatedMap.Values.Count);

            var innerMapField = updatedMap.Values.Single(s => s.Field.Name == innerMapName.FromRiakString());

            Assert.AreEqual(1, innerMapField.MapValue.Count);

            var innerMapSetField =
                innerMapField.MapValue.Single(entry => entry.Field.Name == innerMapSetName.FromRiakString());
            var setValues = innerMapSetField.SetValue.Select(v => Deserializer(v)).ToList();

            Assert.AreEqual(2, setValues.Count);
            Assert.Contains("X", setValues);
            Assert.Contains("Y", setValues);

            // Remove nested map, add Z to set
            var innerMapUpdate2 = new MapUpdate
            {
                set_op = new SetOp(),
                field = new MapField { name = innerMapSetName, type = MapField.MapFieldType.SET }
            };
            innerMapUpdate2.set_op.adds.Add(Serializer("Z"));

            var parentMapUpdate2 = new MapUpdate
            {
                field = new MapField { name = innerMapName, type = MapField.MapFieldType.MAP },
                map_op = new MapOp()
            };

            parentMapUpdate2.map_op.removes.Add(innerMapUpdate2.field);
            parentMapUpdate2.map_op.updates.Add(innerMapUpdate2);

            var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap.Context, NoRemovals,
                new List<MapUpdate> { parentMapUpdate2 });

            Assert.AreEqual(1, updatedMap2.Values.Count);

            var innerMapField2 = updatedMap2.Values.Single(s => s.Field.Name == innerMapName.FromRiakString());

            Assert.AreEqual(1, innerMapField2.MapValue.Count);

            var innerMapSetField2 =
                innerMapField2.MapValue.Single(entry => entry.Field.Name == innerMapSetName.FromRiakString());
            var setValues2 = innerMapSetField2.SetValue.Select(v => Deserializer(v)).ToList();

            Assert.AreEqual(1, setValues2.Count);
            Assert.Contains("Z", setValues2);
        }
        public void TestBasicMapOperations()
        {
            string key = GetRandomKey();

            var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key);

            // Fetch empty
            // []
            var initialMap = Client.DtFetchMap(id);
            Assert.IsNull(initialMap.Context);
            Assert.IsEmpty(initialMap.Values);

            // Add Counter
            // [ Score => 1 ]
            const string counterName = "Score";

            var counterMapUpdate = new MapUpdate
            {
                counter_op = new CounterOp { increment = 1 },
                field = new MapField { name = Serializer.Invoke(counterName), type = MapField.MapFieldType.COUNTER }
            };

            var updatedMap1 = Client.DtUpdateMap(id, Serializer, initialMap.Context, null,
                new List<MapUpdate> { counterMapUpdate });

            Assert.IsNotNull(updatedMap1.Context);
            Assert.IsNotEmpty(updatedMap1.Values);
            Assert.AreEqual(1, updatedMap1.Values.Single(s => s.Field.Name == counterName).Counter.Value);


            // Increment Counter
            // [ Score => 5 ]
            counterMapUpdate.counter_op.increment = 4;
            RiakDtMapResult updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                new List<MapUpdate> { counterMapUpdate });
            var counterMapField = updatedMap2.Values.Single(s => s.Field.Name == counterName);
            Assert.AreEqual(5, counterMapField.Counter.Value);


            // Add an embedded map with new counter
            // decrement "Score" counter by 10
            // [ Score => -5, subMap [ InnerScore => 42 ]]
            const string innerMapName = "subMap";
            const string innerMapCounterName = "InnerScore";
            var innerCounterMapUpdate = new MapUpdate
            {
                counter_op = new CounterOp { increment = 42 },
                field =
                    new MapField { name = Serializer.Invoke(innerMapCounterName), type = MapField.MapFieldType.COUNTER }
            };

            var parentMapUpdate = new MapUpdate
            {
                field = new MapField { name = Serializer.Invoke(innerMapName), type = MapField.MapFieldType.MAP },
                map_op = new MapOp()
            };

            parentMapUpdate.map_op.updates.Add(innerCounterMapUpdate);
            counterMapUpdate.counter_op.increment = -10;

            var updatedMap3 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null,
                new List<MapUpdate> { parentMapUpdate, counterMapUpdate });

            counterMapField = updatedMap3.Values.Single(entry => entry.Field.Name == counterName);
            var innerMapField = updatedMap3.Values.Single(entry => entry.Field.Name == innerMapName);
            var innerMapCounterField = innerMapField.MapValue.Single(entry => entry.Field.Name == innerMapCounterName);

            Assert.AreEqual(-5, counterMapField.Counter.Value);
            Assert.AreEqual(42, innerMapCounterField.Counter.Value);
            Assert.AreEqual(2, updatedMap3.Values.Count);
            Assert.AreEqual(1, innerMapField.MapValue.Count);


            // Remove Counter from map
            // [ subMap [ InnerScore => 42 ]]
            var removes = new List<RiakDtMapField> { new RiakDtMapField(counterMapField.Field.ToMapField()) };
            var updatedMap4 = Client.DtUpdateMap(id, Serializer, updatedMap3.Context, removes);

            innerMapField = updatedMap4.Values.Single(entry => entry.Field.Name == innerMapName);
            innerMapCounterField = innerMapField.MapValue.Single(entry => entry.Field.Name == innerMapCounterName);
            Assert.AreEqual(1, updatedMap4.Values.Count);
            Assert.AreEqual(42, innerMapCounterField.Counter.Value);
        }