Beispiel #1
0
        public void DoesSupportObservableHashSet()
        {
            List <string> expected;
            List <int>    expectedForked;

            ObservableHashSet <int> source1 = new ObservableHashSet <int>();
            ObservableHashSet <int> source2 = new ObservableHashSet <int>();
            ObservableHashSet <int> source3 = new ObservableHashSet <int>();

            List <string> projection1 = new List <string>();
            List <string> projection2 = new List <string>();
            List <int>    projection3 = new List <int>();

            Func <int, string> transformation  = i => i.ToString();
            Func <int, bool>   filterPredicate = i => i <= 2;

            ListBinding <string> binding = new ListBinding <string>()
                                           .AddSource(source1, convert: transformation, filter: filterPredicate)
                                           .AddSource(source2, convert: transformation, filter: filterPredicate)
                                           .AddSource(source3, convert: transformation, filter: filterPredicate);

            source1.Add(0);
            source2.Add(1);
            source3.Add(2);
            source3.Add(3);
            source2.Add(4);

            binding.AddTarget(projection1);

            source1.Add(5);
            source2.Add(6);

            binding.AddTarget(projection2);

            source1.Add(7);
            source3.Add(8);

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            var bindingForked = binding.Select <int>(item => int.Parse(item));

            source2.Remove(4);
            source1.Remove(5);
            source2.Remove(6);

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            source1.Add(4);
            source3.Add(5);
            source1.Add(6);

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            source1.Clear();

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            source3.Clear();
            source2.Clear();

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            expectedForked = source1.Concat(source2).Concat(source3).Where(filterPredicate).ToList();
            expectedForked.Sort();
            Assert.Equal(expectedForked, projection3);
        }