Beispiel #1
0
        public void TestInsert()
        {
            Console.WriteLine("--- TestInsert ---");
            _testList.Clear();
            _testList.RemoveSort();

            for (var i = 0; i < 3; i++)
            {
                _testList.Insert(0, _testObjects[i]);
            }

            Assert.AreEqual(_testList.Count, 3);
            Assert.AreEqual(_testList[0], _testObjects[2]);
            Assert.AreEqual(_testList[1], _testObjects[1]);
            Assert.AreEqual(_testList[2], _testObjects[0]);

            var _subArray = new EditableTestObject[3];

            for (var i = 3; i < _testObjects.Length; i++)
            {
                _subArray[i - 3] = _testObjects[i];
            }

            _testList.InsertRange(0, _subArray);
            Assert.AreEqual(_testList.Count, 6);

            Assert.AreEqual(_testList[0], _testObjects[3]);
            Assert.AreEqual(_testList[1], _testObjects[4]);
            Assert.AreEqual(_testList[2], _testObjects[5]);

            PrintList();

            _testList.Clear();
        }
Beispiel #2
0
        public void TestSortedPropertyChange()
        {
            Console.WriteLine("--- TestSortedPropertyChange ---");
            _testList.Clear();
            _testList.RemoveSort();
            _testList.ApplySort(_testList.GetItemProperties(null)["Seconds"], ListSortDirection.Descending);
            _testList.AddRange(_testObjects);

            var eto = EditableTestObject.CreateInstance(6, "Dummy", 10);

            _testList.Add(eto);
            Assert.AreEqual(_testList.Count, 7);
            Assert.AreEqual(_testList[6], eto);

            eto.Seconds = 20;
            Assert.AreEqual(_testList[6], eto);

            eto.Seconds = 23;
            Assert.AreEqual(_testList[5], eto);

            eto.Seconds = 30;
            Assert.AreEqual(_testList[4], eto);

            eto.Seconds = 40;
            Assert.AreEqual(_testList[2], eto);

            eto.Seconds = 50;
            Assert.AreEqual(_testList[1], eto);

            eto.Seconds = 60;
            Assert.AreEqual(_testList[0], eto);
        }
Beispiel #3
0
        public void TestAdd()
        {
            Console.WriteLine("--- TestAdd ---");
            _testList.Clear();
            _testList.RemoveSort();

            for (int i = 0; i < 3; i++)
            {
                _testList.Add(_testObjects[i]);
            }

            Assert.AreEqual(_testList.Count, 3);
            Assert.AreEqual(_testList[0], _testObjects[0]);
            Assert.AreEqual(_testList[1], _testObjects[1]);
            Assert.AreEqual(_testList[2], _testObjects[2]);

            EditableTestObject[] subArray = new EditableTestObject[3];

            for (int i = 3; i < _testObjects.Length; i++)
            {
                subArray[i - 3] = _testObjects[i];
            }

            _testList.AddRange(subArray);
            Assert.AreEqual(_testList.Count, 6);

            for (int i = 3; i < _testObjects.Length; i++)
            {
                Assert.AreEqual(subArray[i - 3], _testObjects[i]);
            }

            PrintList();

            _testList.Clear();
        }
Beispiel #4
0
        public void SortTest()
        {
            EditableList <EditableTestObject> dataList = new EditableList <EditableTestObject>();

            dataList.Add(EditableTestObject.CreateInstance(1, "John", 60));
            dataList.Add(EditableTestObject.CreateInstance(1, "John", 60));
            dataList.Add(EditableTestObject.CreateInstance(1, "John", 60));
            dataList.Add(EditableTestObject.CreateInstance(2, "Tester", 70));
            dataList.Add(EditableTestObject.CreateInstance(2, "Tester", 70));
            dataList.Add(EditableTestObject.CreateInstance(2, "Tester", 70));
            dataList.Add(EditableTestObject.CreateInstance(3, "Tester", 70));
            dataList.Add(EditableTestObject.CreateInstance(3, "Tester", 70));
            dataList.Add(EditableTestObject.CreateInstance(3, "Tester", 70));

            BindingSource bindingSource = new BindingSource(dataList, null);

            bindingSource.Sort = "ID";

            int prev = 0;

            foreach (EditableTestObject o in dataList)
            {
                Assert.IsTrue(o.ID >= prev);
                prev = o.ID;
            }

            bindingSource[0] = EditableTestObject.CreateInstance(2, "John", 60);

            prev = 0;
            foreach (EditableTestObject o in dataList)
            {
                Assert.IsTrue(o.ID >= prev);
                prev = o.ID;
            }
        }
Beispiel #5
0
        public void TestSortedInsert()
        {
            Console.WriteLine("--- TestSortedInsert ---");
            _testList.Clear();
            _testList.RemoveSort();
            _testList.ApplySort(_testList.GetItemProperties(null)["Seconds"], ListSortDirection.Descending);

            for (var i = 0; i < 3; i++)
            {
                _testList.Insert(0, _testObjects[i]);
            }

            Assert.AreEqual(_testList.Count, 3);
            Assert.AreEqual(_testList[0], _testObjects[2]);
            Assert.AreEqual(_testList[1], _testObjects[0]);
            Assert.AreEqual(_testList[2], _testObjects[1]);

            var _subArray = new EditableTestObject[3];

            for (var i = 3; i < _testObjects.Length; i++)
            {
                _subArray[i - 3] = _testObjects[i];
            }

            _testList.InsertRange(0, _subArray);
            Assert.AreEqual(_testList.Count, 6);

            Assert.AreEqual(_testList[0], _testObjects[3]);
            Assert.AreEqual(_testList[2], _testObjects[4]);
            Assert.AreEqual(_testList[3], _testObjects[5]);

            PrintList();

            _testList.Clear();
            Assert.AreEqual(_testList.Count, 0);

            _testList.ApplySort(_testList.GetItemProperties(null)["Seconds"], ListSortDirection.Ascending);

            for (var i = 0; i < 3; i++)
            {
                _testList.Insert(0, _testObjects[i]);
            }

            Assert.AreEqual(_testList.Count, 3);
            Assert.AreEqual(_testList[0], _testObjects[1]);
            Assert.AreEqual(_testList[1], _testObjects[0]);
            Assert.AreEqual(_testList[2], _testObjects[2]);

            _testList.InsertRange(0, _subArray);
            Assert.AreEqual(_testList.Count, 6);

            Assert.AreEqual(_testList[2], _testObjects[5]);
            Assert.AreEqual(_testList[3], _testObjects[4]);
            Assert.AreEqual(_testList[5], _testObjects[3]);

            PrintList();

            _testList.Clear();
        }
Beispiel #6
0
            public static EditableTestObject CreateInstance(int id, string name, int seconds)
            {
                EditableTestObject instance = CreateInstance();

                instance.ID      = id;
                instance.Name    = name;
                instance.Seconds = seconds;

                return(instance);
            }
Beispiel #7
0
        public void CreateWithDirtyTest()
        {
            var to = EditableTestObject.CreateInstance();

            to.ID = 10;

            Assert.IsTrue(to.IsDirty);

            var list = new EditableList <EditableTestObject>(new[] { to });

            Assert.IsTrue(to.IsDirty);
            Assert.IsTrue(list.IsDirty);
        }
Beispiel #8
0
        private void TestList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            EditableArrayList array = sender as EditableArrayList;

            Assert.IsNotNull(array);
            if (e.Action != NotifyCollectionChangedAction.Reset)
            {
                Assert.That(array.IsDirty);
            }

            EditableTestObject o = (EditableTestObject)(e.NewItems != null? e.NewItems[0]:
                                                        e.OldItems != null ? e.OldItems[0]: null);

            Console.WriteLine("CollectionChanged (ID:{3}). Type: {0}, OldIndex: {1}, NewIndex: {2}",
                              e.Action, e.OldStartingIndex, e.NewStartingIndex, o != null? o.ID: -1);
        }
Beispiel #9
0
        public void SortTest()
        {
            var dataList = new EditableList <EditableTestObject>
            {
                EditableTestObject.CreateInstance(1, "John", 60),
                EditableTestObject.CreateInstance(1, "John", 60),
                EditableTestObject.CreateInstance(1, "John", 60),
                EditableTestObject.CreateInstance(2, "Tester", 70),
                EditableTestObject.CreateInstance(2, "Tester", 70),
                EditableTestObject.CreateInstance(2, "Tester", 70),
                EditableTestObject.CreateInstance(3, "Tester", 70),
                EditableTestObject.CreateInstance(3, "Tester", 70),
                EditableTestObject.CreateInstance(3, "Tester", 70)
            };

            var bindingSource = new BindingSource(dataList, null)
            {
                Sort = "ID"
            };
            var prev = 0;

            foreach (var o in dataList)
            {
                Assert.IsTrue(o.ID >= prev);
                prev = o.ID;
            }

            bindingSource[0] = EditableTestObject.CreateInstance(2, "John", 60);

            prev = 0;

            foreach (var o in dataList)
            {
                Assert.IsTrue(o.ID >= prev);
                prev = o.ID;
            }
        }