Ejemplo n.º 1
0
        public void ClearAndAddRangeWithExistingWorks()
        {
            var list = new ListItemCollection <string>();

            list.AddGroup("Hello", new List <string> {
                "Foo"
            });

            var items = new List <ListItemInnerCollection <string> >();

            items.Add(new ListItemInnerCollection <string>("Hello", new List <string> {
                "Bar"
            }));

            list.ClearAndAddRange(items);

            list.Count.Should().Be(1);
        }
Ejemplo n.º 2
0
        public void ClearAndAddRangeOnlyRaisesOneCollectionChangeEventForTheAdd()
        {
            var list = new ListItemCollection <string>();

            var initial = new List <string>
            {
                "A",
                "B"
            };

            var toAdd = new List <string>
            {
                "Foo",
                "Bar"
            };

            var toAddSecond = new List <string>
            {
                "Foo",
                "Bar",
                "Hello"
            };

            list.AddGroup("FooBar", initial);

            var eventCount = 0;
            var action     = NotifyCollectionChangedAction.Add;

            ((INotifyCollectionChanged)list).CollectionChanged += (s, e) =>
            {
                ++eventCount;
                action = e.Action;
            };

            list.ClearAndAddRange(new List <Tuple <string, IEnumerable <string> > >
            {
                Tuple.Create("Bob", (IEnumerable <string>)toAdd),
                Tuple.Create("Dave", (IEnumerable <string>)toAddSecond),
            });

            eventCount.Should().Be(1);
            action.Should().Be(NotifyCollectionChangedAction.Reset);
        }
Ejemplo n.º 3
0
        public void ClearAndAddRangeClearsAndAddsARangeFromEnumerableOfTuple()
        {
            var list = new ListItemCollection <string>();

            var initial = new List <string>
            {
                "A",
                "B"
            };

            var toAdd = new List <string>
            {
                "Foo",
                "Bar"
            };

            var toAddSecond = new List <string>
            {
                "Foo",
                "Bar",
                "Hello"
            };

            list.AddGroup("FooBar", initial);

            list.ClearAndAddRange(new List <Tuple <string, IEnumerable <string> > >
            {
                Tuple.Create("Bob", (IEnumerable <string>)toAdd),
                Tuple.Create("Dave", (IEnumerable <string>)toAddSecond),
            });

            list.Count.Should().Be(2);

            list[0].Title.Should().Be("Bob");
            list[0].Should().ContainInOrder(toAdd);
            list[0].Should().OnlyContain(s => toAdd.Contains(s));
            list[0].Count.Should().Be(2);

            list[1].Title.Should().Be("Dave");
            list[1].Should().ContainInOrder(toAddSecond);
            list[1].Should().OnlyContain(s => toAddSecond.Contains(s));
            list[1].Count.Should().Be(3);
        }
Ejemplo n.º 4
0
        public void ClearAndAddRangeClearsAndAddsARange()
        {
            var list = new ListItemCollection <string>();

            var initial = new List <string>
            {
                "A",
                "B"
            };

            var toAdd = new List <string>
            {
                "Foo",
                "Bar"
            };

            var toAddSecond = new List <string>
            {
                "Foo",
                "Bar",
                "Hello"
            };

            list.AddGroup("FooBar", initial);

            list.ClearAndAddRange(new List <ListItemInnerCollection <string> >
            {
                new ListItemInnerCollection <string>("Bob", toAdd),
                new ListItemInnerCollection <string>("Dave", toAddSecond),
            });

            list.Count.Should().Be(2);

            list[0].Title.Should().Be("Bob");
            list[0].Should().ContainInOrder(toAdd);
            list[0].Should().OnlyContain(s => toAdd.Contains(s));
            list[0].Count.Should().Be(2);

            list[1].Title.Should().Be("Dave");
            list[1].Should().ContainInOrder(toAddSecond);
            list[1].Should().OnlyContain(s => toAddSecond.Contains(s));
            list[1].Count.Should().Be(3);
        }
Ejemplo n.º 5
0
        public void ClearAndAddRangeClearsAndAddsARangeFromEnumerableAndFunc()
        {
            var list = new ListItemCollection <string> {
                SortTitleAlphabetically = true
            };

            var toAdd = new List <string>
            {
                "xxx",
                "Foo",
                "Hello",
                "Bar",
                "FooBar",
                "HelloWorld"
            };

            list.ClearAndAddRange(toAdd, s => s.Substring(0, 1).ToUpper());

            list.Count.Should().Be(4);

            list[0].Title.Should().Be("B");
            list[0].Should().OnlyContain(s => s == "Bar");
            list[0].Count.Should().Be(1);

            list[1].Title.Should().Be("F");
            list[1].Should().OnlyContain(s => s == "Foo" || s == "FooBar");
            list[1].Count.Should().Be(2);

            list[2].Title.Should().Be("H");
            list[2].Should().OnlyContain(s => s == "Hello" || s == "HelloWorld");
            list[2].Count.Should().Be(2);

            list[3].Title.Should().Be("X");
            list[3].Should().OnlyContain(s => s == "xxx");
            list[3].Count.Should().Be(1);
        }
Ejemplo n.º 6
0
        public void ClearAndAddRangeWithExistingWorks()
        {
            var list = new ListItemCollection<string>();
            list.AddGroup("Hello", new List<string> {"Foo"});

            var items = new List<ListItemInnerCollection<string>>();
            items.Add(new ListItemInnerCollection<string>("Hello", new List<string> { "Bar" }));

            list.ClearAndAddRange(items);

            list.Count.Should().Be(1);
        }
Ejemplo n.º 7
0
        public void ClearAndAddRangeOnlyRaisesOneCollectionChangeEventForTheAdd()
        {
            var list = new ListItemCollection<string>();

            var initial = new List<string>
            {
                "A",
                "B"
            };

            var toAdd = new List<string>
            {
                "Foo",
                "Bar"
            };

            var toAddSecond = new List<string>
            {
                "Foo",
                "Bar",
                "Hello"
            };

            list.AddGroup("FooBar", initial);

            var eventCount = 0;
            var action = NotifyCollectionChangedAction.Add;

            ((INotifyCollectionChanged) list).CollectionChanged += (s, e) =>
                {
                    ++eventCount;
                    action = e.Action;
                };

            list.ClearAndAddRange(new List<Tuple<string, IEnumerable<string>>>
            {
                Tuple.Create("Bob", (IEnumerable<string>) toAdd),
                Tuple.Create("Dave", (IEnumerable<string>) toAddSecond),
            });

            eventCount.Should().Be(1);
            action.Should().Be(NotifyCollectionChangedAction.Reset);
        }
Ejemplo n.º 8
0
        public void ClearAndAddRangeClearsAndAddsARangeFromEnumerableOfTuple()
        {
            var list = new ListItemCollection<string>();

            var initial = new List<string>
            {
                "A",
                "B"
            };

            var toAdd = new List<string>
            {
                "Foo",
                "Bar"
            };

            var toAddSecond = new List<string>
            {
                "Foo",
                "Bar",
                "Hello"
            };

            list.AddGroup("FooBar", initial);

            list.ClearAndAddRange(new List<Tuple<string, IEnumerable<string>>>
            {
                Tuple.Create("Bob", (IEnumerable<string>) toAdd),
                Tuple.Create("Dave", (IEnumerable<string>) toAddSecond),
            });

            list.Count.Should().Be(2);

            list[0].Title.Should().Be("Bob");
            list[0].Should().ContainInOrder(toAdd);
            list[0].Should().OnlyContain(s => toAdd.Contains(s));
            list[0].Count.Should().Be(2);

            list[1].Title.Should().Be("Dave");
            list[1].Should().ContainInOrder(toAddSecond);
            list[1].Should().OnlyContain(s => toAddSecond.Contains(s));
            list[1].Count.Should().Be(3);
        }
Ejemplo n.º 9
0
        public void ClearAndAddRangeClearsAndAddsARangeFromEnumerableAndFunc()
        {
            var list = new ListItemCollection<string> {SortTitleAlphabetically = true};

            var toAdd = new List<string>
            {
                "xxx",
                "Foo",
                "Hello",
                "Bar",
                "FooBar",
                "HelloWorld"
            };

            list.ClearAndAddRange(toAdd, s => s.Substring(0, 1).ToUpper());

            list.Count.Should().Be(4);

            list[0].Title.Should().Be("B");
            list[0].Should().OnlyContain(s => s == "Bar");
            list[0].Count.Should().Be(1);

            list[1].Title.Should().Be("F");
            list[1].Should().OnlyContain(s => s == "Foo" || s == "FooBar");
            list[1].Count.Should().Be(2);

            list[2].Title.Should().Be("H");
            list[2].Should().OnlyContain(s => s == "Hello" || s == "HelloWorld");
            list[2].Count.Should().Be(2);

            list[3].Title.Should().Be("X");
            list[3].Should().OnlyContain(s => s == "xxx");
            list[3].Count.Should().Be(1);
        }
Ejemplo n.º 10
0
        public void ClearAndAddRangeClearsAndAddsARange()
        {
            var list = new ListItemCollection<string>();

            var initial = new List<string>
            {
                "A",
                "B"
            };

            var toAdd = new List<string>
            {
                "Foo",
                "Bar"
            };

            var toAddSecond = new List<string>
            {
                "Foo",
                "Bar",
                "Hello"
            };

            list.AddGroup("FooBar", initial);

            list.ClearAndAddRange(new List<ListItemInnerCollection<string>>
            {
                new ListItemInnerCollection<string>("Bob", toAdd),
                new ListItemInnerCollection<string>("Dave", toAddSecond),
            });

            list.Count.Should().Be(2);

            list[0].Title.Should().Be("Bob");
            list[0].Should().ContainInOrder(toAdd);
            list[0].Should().OnlyContain(s => toAdd.Contains(s));
            list[0].Count.Should().Be(2);

            list[1].Title.Should().Be("Dave");
            list[1].Should().ContainInOrder(toAddSecond);
            list[1].Should().OnlyContain(s => toAddSecond.Contains(s));
            list[1].Count.Should().Be(3);
        }