Ejemplo n.º 1
0
        public void RoundTrip_CustomReadOnlyDictionary()
        {
            IReadOnlyDictionary <string, int> input = new CustomReadOnlyDictionary <string, int>(new Dictionary <string, int>
            {
                ["one"] = 1,
                ["two"] = 2,
            });
            var serialized   = BinaryConvert.Serialize(input);
            var deserialized = BinaryConvert.Deserialize <CustomReadOnlyDictionary <string, int> >(serialized);

            Assert.Equal(input.OrderBy(x => x.Key), deserialized.OrderBy(x => x.Key));
        }
Ejemplo n.º 2
0
            public bool Equals(CustomReadOnlyDictionary <TKey, TValue> other)
            {
                if (Count != other.Count)
                {
                    return(false);
                }

                foreach (var key in Keys)
                {
                    if (!other.TryGetValue(key, out var otherValue) || !TryGetValue(key, out var value) || !value.Equals(otherValue))
                    {
                        return(false);
                    }
                }

                return(true);
            }
Ejemplo n.º 3
0
        public void SerializeDeserializeCustomReadOnlyDictionaryUtf8()
        {
            var dictionary = new Dictionary <string, DictionaryValue>
            {
                { "Alice1", new DictionaryValue {
                      Name = "Bob1"
                  } },
                { "Alice2", new DictionaryValue {
                      Name = "Bob2"
                  } },
                { "Alice3", new DictionaryValue {
                      Name = "Bob3"
                  } }
            };
            var customReadOnlyDictionary = new CustomReadOnlyDictionary <string, DictionaryValue>(dictionary);
            var serialized = JsonSerializer.Generic.Utf8.Serialize(customReadOnlyDictionary);

            Assert.NotNull(serialized);
            var deserialized = JsonSerializer.Generic.Utf8.Deserialize <CustomReadOnlyDictionary <string, DictionaryValue> >(serialized);

            Assert.NotNull(deserialized);
            Assert.Equal(customReadOnlyDictionary, deserialized);
        }