Beispiel #1
0
        internal RiakDtMapEntry(MapEntry entry)
        {
            Field = new RiakDtMapField(entry.field);

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Counter)
            {
                Counter = new RiakDtCounter {
                    Value = entry.counter_value
                };
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Flag)
            {
                FlagValue = entry.flag_value;
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Map)
            {
                MapValue = entry.map_value.Select(mv => new RiakDtMapEntry(mv)).ToList();
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Register)
            {
                RegisterValue = entry.register_value;
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Set)
            {
                SetValue = entry.set_value;
            }
        }
        internal RiakDtMapEntry(MapEntry entry)
        {
            Field = new RiakDtMapField(entry.field);

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Counter)
            {
                Counter = new RiakDtCounter { Value = entry.counter_value };
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Flag)
            {
                FlagValue = entry.flag_value;
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Map)
            {
                MapValue = entry.map_value.Select(mv => new RiakDtMapEntry(mv)).ToList();
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Register)
            {
                RegisterValue = entry.register_value;
            }

            if (Field.Type == RiakDtMapField.RiakDtMapFieldType.Set)
            {
                SetValue = entry.set_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 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 Test4()
        {
            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();

            // 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, no context
            Assert.Throws<ArgumentNullException>(() =>
                Client.DtUpdateMap(id, Serializer, NoContext,
                    new List<RiakDtMapField> { fieldToRemove },
                    new List<MapUpdate> { setMapUpdate2 }));
        }