public void ClearTest()
        {
            var set = new DistributedPropertySet();

            set.TryAdd("string", "0");
            set.TryAdd("int", int.MaxValue);
            set.TryAdd("uint", uint.MaxValue);
            set.TryAdd("double", double.MaxValue);

            Assert.NotEmpty(set);

            set.Clear();

            Assert.Empty(set);
        }
        public void TryAddTest(string name, object value)
        {
            var flag = false;
            var set  = new DistributedPropertySet();

            set.MapChanged += (sender, args) =>
            {
                if (args.DistributedCollectionChange == DistributedCollectionChange.ItemInserted)
                {
                    flag = true;
                }
            };

            Assert.True(set.TryAdd(name, value));
            Assert.Equal(value, set[name]);
            Assert.True(flag);
        }
        public void AddOrUpdateTest_UpdateFactory(string name, object addValue, object updateValue)
        {
            var flag = false;
            var set  = new DistributedPropertySet();

            set.MapChanged += (sender, args) =>
            {
                if (args.DistributedCollectionChange == DistributedCollectionChange.ItemChanged)
                {
                    flag = true;
                }
            };

            Assert.True(set.TryAdd(name, addValue));
            Assert.Equal(updateValue, set.AddOrUpdate(name, n => addValue, (n, v) => updateValue));
            Assert.True(flag);
        }
        public void TryRemoveTest(string name, object value)
        {
            var flag = false;
            var set  = new DistributedPropertySet();

            set.MapChanged += (sender, args) =>
            {
                if (args.DistributedCollectionChange == DistributedCollectionChange.ItemRemoved)
                {
                    flag = true;
                }
            };

            Assert.True(set.TryAdd(name, value));
            Assert.True(set.TryRemove(name, out var outValue));
            Assert.Equal(value, outValue);
            Assert.False(set.ContainsKey(name));
            Assert.True(flag);
        }
        public IDistributedPropertySet Deserialize(byte[] source)
        {
            var yaml = Encoding.UTF8.GetString(source);
            var valueKindDictionary = new Deserializer().Deserialize <Dictionary <string, Pair> >(yaml);

            if (valueKindDictionary == null)
            {
                return(null);
            }

            var results = new DistributedPropertySet();

            valueKindDictionary.ToList().ForEach(pair =>
            {
                try
                {
                    var toParse = pair.Value.Value.ToString();

                    results.TryAdd(pair.Key, Type.GetType(pair.Value.Key)?.Name switch
                    {
                        nameof(String) => toParse,
                        nameof(Int16) => short.TryParse(toParse, out var parsed) ? parsed : default,
        public void NullNameTest()
        {
            var set = new DistributedPropertySet();

            Assert.Throws <ArgumentNullException>((Action)(() => set.TryAdd(null, null)));
        }