Exemplo n.º 1
0
        public void EventOrdering_CommitItem_Sorted()
        {
            var items = new List <Rectangle>()
            {
                new Rectangle {
                    Width = 0
                },
                new Rectangle {
                    Width = 1
                },
                new Rectangle {
                    Width = 3
                },
                new Rectangle {
                    Width = 4
                },
            };

            Source.Source           = items;
            View.CollectionChanged += (o, e) => CollectionChangedArgs.Add(e);
            View.SortDescriptions.Add(new SortDescription("Width", ListSortDirection.Ascending));

            Editable.AddNew();
            CollectionChangedArgs.Clear();
            Editable.CommitNew();

            Assert.AreEqual(2, CollectionChangedArgs.Count, "#1");

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, CollectionChangedArgs[0].Action, "#2");
            Assert.AreEqual(4, CollectionChangedArgs[0].OldStartingIndex, "#3");

            Assert.AreEqual(NotifyCollectionChangedAction.Add, CollectionChangedArgs[1].Action, "#4");
            Assert.AreEqual(0, CollectionChangedArgs[1].NewStartingIndex, "#5");
        }
Exemplo n.º 2
0
        public void AddNew_DoesNotRegenerateGroups()
        {
            var groups = View.Groups;

            Editable.AddNew();
            Assert.AreSame(groups, View.Groups, "#1");

            Editable.CommitNew();
            Assert.AreSame(groups, View.Groups, "#2");
        }
Exemplo n.º 3
0
        public void EventOrdering_CommitFilteredItem()
        {
            // Filter everything then add a new item
            View.Filter = o => false;

            Editable.AddNew();
            CollectionChangedArgs.Clear();
            Editable.CommitNew();

            Assert.AreEqual(1, CollectionChangedArgs.Count, "#1");
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, CollectionChangedArgs[0].Action, "#2");
        }
Exemplo n.º 4
0
        public void AddNew_CommitFilteredItem()
        {
            // Filter everything then add a new item
            View.Filter = o => false;

            var item = Editable.AddNew();

            Assert.IsTrue(View.Cast <object>().Contains(item), "#1");
            Editable.CommitNew();

            Assert.IsFalse(View.Cast <object>().Contains(item), "#2");
        }
Exemplo n.º 5
0
        public void AddNew_Sorted_SameKeys()
        {
            var items = new List <Rectangle> ()
            {
                new Rectangle {
                    Width = 0
                },
                new Rectangle {
                    Width = 2, Height = 1
                },
                new Rectangle {
                    Width = 1
                },
                new Rectangle {
                    Width = 2, Height = 2
                },
                new Rectangle {
                    Width = 3
                },
                new Rectangle {
                    Width = 2, Height = 3
                },
                new Rectangle {
                    Width = 4
                },
                new Rectangle {
                    Width = 2, Height = 4
                },
            };

            Source.Source = items;
            Source.SortDescriptions.Add(new SortDescription("Width", ListSortDirection.Ascending));

            var rect = Editable.AddNew() as Rectangle;

            Assert.AreSame(rect, View.Cast <object> ().Last(), "#1");
            Assert.AreSame(rect, View.CurrentItem, "#2");
            Assert.AreEqual(8, View.CurrentPosition, "#3");

            rect.Width = 2;
            Assert.AreSame(rect, View.Cast <object> ().Last(), "#4");
            Assert.AreSame(rect, View.CurrentItem, "#5");
            Assert.AreEqual(8, View.CurrentPosition, "#6");

            Editable.CommitNew();
            Assert.AreSame(rect, View.CurrentItem, "#7");
            Assert.AreEqual(3, View.CurrentPosition, "#8");
            Assert.AreSame(rect, View.Cast <object> ().ElementAt(3), "#9");
        }
Exemplo n.º 6
0
        public void AddAndCommitNew_IsAddedToGroups()
        {
            // If we 'AddNew' the item ends up in a special group it seems
            View.GroupDescriptions.Add(new ConcretePropertyGroupDescription()
            {
                GroupNameFromItemFunc = (item, depth, culture) => Items.IndexOf(item) < 3 ? "First" : "Second"
            });
            var groups = View.Groups;

            var added = Editable.AddNew();

            Editable.CommitNew();
            Assert.AreEqual(2, groups.Count, "#1");

            Assert.IsFalse(((CollectionViewGroup)groups [0]).Items.Contains(added), "#2");
            Assert.IsTrue(((CollectionViewGroup)groups [1]).Items.Contains(added), "#3");
            Assert.AreSame(added, ((CollectionViewGroup)groups [1]).Items.Last(), "#4");
            Assert.AreSame(groups, View.Groups, "#5");
        }
Exemplo n.º 7
0
 public void CommitNew_NoAdd()
 {
     // This has no effect if there's no add new
     Editable.CommitNew();
 }