Пример #1
0
        public void ConcurrentObservableDictionaryTest()
        {
            ConcurrentObservableDictionary <int, string> dict = new ConcurrentObservableDictionary <int, string>();
            var times = 0;

            dict.CollectionChanged += delegate
            {
                times++;
            };

            dict.Add(1, "foo");
            dict.Add(2, "moo");
            dict.Add(3, "boo");

            dict.AddOrReplace(1, "boo");
            dict.Remove(dict.First(x => x.Value == "moo"));

            Assert.True(dict.Values.All(x => x == "boo"));
            Assert.Equal(5, times);
        }
Пример #2
0
        public void ConcurrentObservableDictionaryTest()
        {
            ConcurrentObservableDictionary <int, string> dict = new ConcurrentObservableDictionary <int, string>();

            _times = 0;
            dict.CollectionChanged += Dict_CollectionChanged;

            try
            {
                dict.Add(1, "foo");
                dict.Add(2, "moo");
                dict.Add(3, "boo");

                dict.AddOrReplace(1, "boo");
                dict.Remove(dict.First(x => x.Value == "moo"));

                Assert.DoesNotContain(dict.Values, x => x != "boo");
                Assert.Equal(5, _times);
            }
            finally
            {
                dict.CollectionChanged -= Dict_CollectionChanged;
            }
        }