public void AddGroupReturnsFalseIfGroupAlreadyExists()
        {
            var list = new ListItemCollection<string>();

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

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

            list.AddGroup("Bob", toAdd).Should().BeTrue();
            list.AddGroup("Bob", toAddSecond).Should().BeFalse();

            list.Count.Should().Be(1);
            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);
        }
Пример #2
0
        public void AddGroupReturnsFalseIfGroupAlreadyExists()
        {
            var list = new ListItemCollection <string>();

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

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

            list.AddGroup("Bob", toAdd).Should().BeTrue();
            list.AddGroup("Bob", toAddSecond).Should().BeFalse();

            list.Count.Should().Be(1);
            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);
        }
Пример #3
0
        public void GroupsAreSorted()
        {
            var list = new ListItemCollection <string>();

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

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

            list.Should().HaveCount(2);
            list[0].Title.Should().Be("Bob");
            list[1].Title.Should().Be("Dave");

            list.TitleSortOrder = new List <string>
            {
                "Dave",
                "Colin",
                "Bob"
            };

            list.Should().HaveCount(2);
            list[0].Title.Should().Be("Dave");
            list[1].Title.Should().Be("Bob");

            list.AddGroup("Colin", new List <string>
            {
                "FooBar",
                "HelloWorld"
            });

            list.Should().HaveCount(3);
            list[0].Title.Should().Be("Dave");
            list[1].Title.Should().Be("Colin");
            list[2].Title.Should().Be("Bob");

            list.Delete("FooBar");
            list.Delete("HelloWorld");

            list.Should().HaveCount(2);
            list[0].Title.Should().Be("Dave");
            list[1].Title.Should().Be("Bob");
        }
Пример #4
0
        public void DeleteReturnsTrueIfItDeletesTheItem()
        {
            var list = new ListItemCollection <string>();

            list.AddGroup("Hello", new List <string> {
                "Foo", "Bar"
            });
            list.Delete("Foo").Should().BeTrue();
        }
Пример #5
0
        public void DeleteRemovesEmptyGroups()
        {
            var list = new ListItemCollection <string>();

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

            list.Should().HaveCount(2);

            list.Delete("FooBar").Should().BeTrue();

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 2 &&
                                  g.Contains("Foo") && g.Contains("Bar"));
        }
Пример #6
0
        public void RemoveGroupRemovesGroupIfItIsThere()
        {
            var list = new ListItemCollection <string>();

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

            list.AddGroup("Bob", toAdd);
            list.AddGroup("Dave", toAdd);

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

            list.RemoveGroup("Dave");

            list.Count.Should().Be(1);
            list[0].Title.Should().Be("Bob");
        }
        public void AddAddsToNewGroupIfGroupDoesntExist()
        {
            var list = new ListItemCollection<string>();
            list.AddGroup("Hello", new List<string> { "Foo" });

            list.Add("World", "Bar");

            list.Should().HaveCount(2);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 1 && g[0] == "Foo");
            list.Should().Contain(g => g.Title == "World" && g.Count == 1 && g[0] == "Bar");
        }
        public void AddAddsToExistingGroupIfGroupDoesExist()
        {
            var list = new ListItemCollection<string>();
            list.AddGroup("Hello", new List<string> { "Foo" });

            list.Add("Hello", "Bar");

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 2 &&
                g.Contains("Foo") && g.Contains("Bar"));
        }
Пример #9
0
        public void RemoveGroupReturnsFalseIfTheGroupIsNotPresent()
        {
            var list = new ListItemCollection <string>();

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

            list.AddGroup("Bob", toAdd);
            list.AddGroup("Dave", toAdd);

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

            list.RemoveGroup("Trevor").Should().BeFalse();

            list.Count.Should().Be(2);
            list[0].Title.Should().Be("Bob");
            list[1].Title.Should().Be("Dave");
        }
Пример #10
0
        public void DeleteDeletesItem()
        {
            var list = new ListItemCollection <string>();

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

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 1 && g[0] == "Bar");
        }
Пример #11
0
        public void DeleteReturnsFalseIfTheItemDoesnExist()
        {
            var list = new ListItemCollection <string>();

            list.AddGroup("Hello", new List <string> {
                "Foo", "Bar"
            });
            list.Delete("World").Should().BeFalse();

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 2 &&
                                  g.Contains("Foo") && g.Contains("Bar"));
        }
Пример #12
0
        public void AddAddsToNewGroupIfGroupDoesntExist()
        {
            var list = new ListItemCollection <string>();

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

            list.Add("World", "Bar");

            list.Should().HaveCount(2);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 1 && g[0] == "Foo");
            list.Should().Contain(g => g.Title == "World" && g.Count == 1 && g[0] == "Bar");
        }
Пример #13
0
        public void AddAddsToExistingGroupIfGroupDoesExist()
        {
            var list = new ListItemCollection <string>();

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

            list.Add("Hello", "Bar");

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 2 &&
                                  g.Contains("Foo") && g.Contains("Bar"));
        }
Пример #14
0
        public void ClearClearsTheList()
        {
            var list = new ListItemCollection <string>();

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

            list.AddGroup("Bob", toAdd);
            list.Clear();

            list.Count.Should().Be(0);
        }
Пример #15
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);
        }
Пример #16
0
        public void AddGroupReturnsTrueIfGroupIsAdded()
        {
            var list = new ListItemCollection <string>();

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

            list.AddGroup("Bob", toAdd).Should().BeTrue();

            list.Count.Should().Be(1);
            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);
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
0
        public void AddGroupReturnsTrueIfGroupIsAdded()
        {
            var list = new ListItemCollection<string>();

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

            list.AddGroup("Bob", toAdd).Should().BeTrue();

            list.Count.Should().Be(1);
            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);
        }
Пример #20
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);
        }
Пример #21
0
        public void AddRangeDoesntAddExistingGroups()
        {
            var list = new ListItemCollection <string>();

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

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

            list.AddGroup("Bob", toAdd);

            list.AddRange(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);
        }
Пример #22
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);
        }
Пример #23
0
        public void RemoveGroupReturnsTrueIfTheGroupIsRemoved()
        {
            var list = new ListItemCollection<string>();

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

            list.AddGroup("Bob", toAdd);
            list.AddGroup("Dave", toAdd);

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

            list.RemoveGroup("Dave").Should().BeTrue();

            list.Count.Should().Be(1);
            list[0].Title.Should().Be("Bob");
        }
Пример #24
0
        public void RemoveGroupReturnsFalseIfTheGroupIsNotPresent()
        {
            var list = new ListItemCollection<string>();

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

            list.AddGroup("Bob", toAdd);
            list.AddGroup("Dave", toAdd);

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

            list.RemoveGroup("Trevor").Should().BeFalse();

            list.Count.Should().Be(2);
            list[0].Title.Should().Be("Bob");
            list[1].Title.Should().Be("Dave");
        }
Пример #25
0
        public void GroupsAreSorted()
        {
            var list = new ListItemCollection<string>();

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

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

            list.Should().HaveCount(2);
            list[0].Title.Should().Be("Bob");
            list[1].Title.Should().Be("Dave");

            list.TitleSortOrder = new List<string>
            {
                "Dave",
                "Colin",
                "Bob"
            };

            list.Should().HaveCount(2);
            list[0].Title.Should().Be("Dave");
            list[1].Title.Should().Be("Bob");

            list.AddGroup("Colin", new List<string>
            {
                "FooBar",
                "HelloWorld"
            });

            list.Should().HaveCount(3);
            list[0].Title.Should().Be("Dave");
            list[1].Title.Should().Be("Colin");
            list[2].Title.Should().Be("Bob");

            list.Delete("FooBar");
            list.Delete("HelloWorld");

            list.Should().HaveCount(2);
            list[0].Title.Should().Be("Dave");
            list[1].Title.Should().Be("Bob");
        }
Пример #26
0
 public void DeleteReturnsTrueIfItDeletesTheItem()
 {
     var list = new ListItemCollection<string>();
     list.AddGroup("Hello", new List<string> { "Foo", "Bar" });
     list.Delete("Foo").Should().BeTrue();
 }
Пример #27
0
        public void DeleteReturnsFalseIfTheItemDoesnExist()
        {
            var list = new ListItemCollection<string>();
            list.AddGroup("Hello", new List<string> { "Foo", "Bar" });
            list.Delete("World").Should().BeFalse();

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 2 &&
                g.Contains("Foo") && g.Contains("Bar"));
        }
Пример #28
0
        public void DeleteRemovesEmptyGroups()
        {
            var list = new ListItemCollection<string>();
            list.AddGroup("Hello", new List<string> { "Foo", "Bar" });
            list.AddGroup("World", new List<string> { "FooBar" });

            list.Should().HaveCount(2);

            list.Delete("FooBar").Should().BeTrue();

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 2 &&
                g.Contains("Foo") && g.Contains("Bar"));
        }
Пример #29
0
        public void DeleteDeletesItem()
        {
            var list = new ListItemCollection<string>();
            list.AddGroup("Hello", new List<string> { "Foo", "Bar" });
            list.Delete("Foo");

            list.Should().HaveCount(1);
            list.Should().Contain(g => g.Title == "Hello" && g.Count == 1 && g[0] == "Bar");
        }
Пример #30
0
        public void ClearClearsTheList()
        {
            var list = new ListItemCollection<string>();

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

            list.AddGroup("Bob", toAdd);
            list.Clear();

            list.Count.Should().Be(0);
        }
Пример #31
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);
        }
Пример #32
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);
        }
Пример #33
0
        public void AddRangeDoesntAddExistingGroups()
        {
            var list = new ListItemCollection<string>();

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

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

            list.AddGroup("Bob", toAdd);

            list.AddRange(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);
        }
Пример #34
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);
        }