Ejemplo n.º 1
0
        public void InitializedList()
        {
            var dl = new List <TestItemDM> {
                new TestItemDM(0), new TestItemDM(1), new TestItemDM(2)
            };
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };
            var vl = new ListVM <TestItemVM> {
                Metadata = { DataProvider = { Data = bl } }
            };

            Assert.AreEqual(3, vl.Count);

            bl.RemoveAt(1);
            Assert.AreEqual(2, vl.Count);
            bl.Remove(bl[0]);
            Assert.AreEqual(1, vl.Count);
            bl.Clear();
            Assert.AreEqual(0, vl.Count);

            bl.Add(new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(0) } }
            });
            Assert.AreEqual(1, vl.Count);
            bl.Insert(0, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(1) } }
            });
            Assert.AreEqual(2, vl.Count);
            bl.Insert(2, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(1) } }
            });
            Assert.AreEqual(3, vl.Count);
        }
Ejemplo n.º 2
0
        public void Test1()
        {
            var dl = new List <TestItemDM>(new [] { new TestItemDM(0) });
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };
            var vl = new ListVM <TestItemVM> {
                Metadata = { DataProvider = { Data = bl } }
            };

            dl = new List <TestItemDM>(new [] { new TestItemDM(1) });
            bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            TestItemVM oldFirst = vl.FirstOrDefault();
            TestItemVM newfirst = null;

            vl.CollectionChanged += delegate { newfirst = vl.FirstOrDefault(); };

            vl.Metadata.DataProvider.Data = bl;

            var oldFirstTypeInstanceId = oldFirst.TypeInstanceId();
            var newFirstTypeInstanceId = newfirst.TypeInstanceId();

            Assert.AreEqual(newFirstTypeInstanceId, oldFirstTypeInstanceId + 1);
        }
Ejemplo n.º 3
0
        public void Add_NoUnderlyingObject()
        {
            var bm = new ListBM <TestItemBM>();

            bm.Add(new TestItemBM());
            Assert.AreEqual(1, bm.Count, "Count");
        }
Ejemplo n.º 4
0
        public void RemoveAt_NoUnderlyingObject()
        {
            var bm = new ListBM <TestItemBM>();

            bm.Add(new TestItemBM());
            bm.RemoveAt(0);
            Assert.AreEqual(0, bm.Count, "Count");
        }
Ejemplo n.º 5
0
        public void BusinessList_Value_LocalDataProvider()
        {
            var list = new ListBM <StringBM>();

            list.Metadata.DataProvider.Data = new List <string>(new [] { "A", "B", "C" });
            list.Add(new StringBM {
                Metadata = { DataProvider = { Data = "D" } }
            });
            list.RemoveAt(0);
        }
Ejemplo n.º 6
0
        public void BusinessList_Enum_LocalDataProvider()
        {
            var list = new ListBM <EnumBM <TestEnum> >();

            list.Metadata.DataProvider.Data = new List <TestEnum>(new [] { TestEnum.A, TestEnum.B, TestEnum.C });
            list.Add(new EnumBM <TestEnum> {
                Metadata = { DataProvider = { Data = TestEnum.C } }
            });
            list.RemoveAt(0);
        }
Ejemplo n.º 7
0
        public void IListT()
        {
            var dl = new List <TestItemDM>();
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };
            var vl = (IList <TestItemVM>) new ListVM <TestItemVM> {
                Metadata = { DataProvider = { Data = bl } }
            };
            var di = (TestItemDM)null;
            var vi = (TestItemVM)null;

            vl.Add(vi = new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= di = new TestItemDM(0) } }
                                                               } } }
            });
            Assert.AreEqual(1, bl.Count);
            Assert.AreEqual(1, dl.Count);
            Assert.AreEqual(0, vl.IndexOf(vi));
            vl.Add(new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(1) } }
                                                               } } }
            });
            Assert.AreEqual(2, dl.Count);
            vl.Add(new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(2) } }
                                                               } } }
            });
            Assert.AreEqual(3, dl.Count);
            vl.RemoveAt(1);
            Assert.AreEqual(2, dl.Count);
            vl.Remove(vi);
            Assert.AreEqual(1, dl.Count);
            vl.Clear();
            Assert.AreEqual(0, dl.Count);
            vl.Insert(0, new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(0) } }
                                                               } } }
            });
            vl.Insert(0, new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(1) } }
                                                               } } }
            });
            vl.Insert(2, new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(2) } }
                                                               } } }
            });
            Assert.AreEqual(3, dl.Count);
        }
Ejemplo n.º 8
0
        public void Clear_DefaultDataProvider_Array()
        {
            var dm = new [] { new TestItemDM(100), new TestItemDM(101) };
            var bm = new ListBM <TestItemBM> {
                MːData = dm
            };

            Assert.Throws <NotSupportedException>(() =>
                                                  bm.Clear()
                                                  );
        }
Ejemplo n.º 9
0
        public void InitializedList()
        {
            var dl = new List <TestItemDM> {
                new TestItemDM(0), new TestItemDM(1), new TestItemDM(2)
            };
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            Assert.AreEqual(3, bl.Count);
        }
Ejemplo n.º 10
0
        public void RemoveNonContainedItem()
        {
            var dl = new List <TestItemDM>();
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            Assert.IsFalse(bl.Remove(new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(99) } }
            }));
        }
Ejemplo n.º 11
0
        public void SetData_DefaultDataProvider_List_to_Array()
        {
            var dm1 = new List <TestItemDM>(new [] { new TestItemDM(100) });
            var dm2 = new [] { new TestItemDM(102), new TestItemDM(103) };
            var bm  = new ListBM <TestItemBM> {
                MːData = dm1
            };

            Assert.AreEqual(dm1.Count, bm.Count, "Count");
            bm.MːData = dm2;
            Assert.AreEqual(dm2.Length, bm.Count, "Count");
        }
Ejemplo n.º 12
0
        public void RemoveNonContainedItem()
        {
            var dl = new List <TestItemDM>();
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };
            var vl = (IList <TestItemVM>) new ListVM <TestItemVM> {
                Metadata = { DataProvider = { Data = bl } }
            };

            Assert.AreEqual(false, vl.Remove(TestItemVM.New()));
        }
Ejemplo n.º 13
0
 public void InvalidMetadataInitialization()
 {
     Assert.Throws <InvalidOperationException>(delegate {
         var bl = new ListBM <TestItemBM> {
             Metadata =
             {
                 LogicProvider = new CustomListLogicProvider(OnCollectionChanged, OnCollectionChanged),                      // <-- invalid
                 DataProvider  = { Data = new List <TestItemDM>() }
             }
         };
     });
 }
Ejemplo n.º 14
0
        public void Remove_DefaultDataProvider_List()
        {
            var dm = new List <TestItemDM>(new [] { new TestItemDM(100) });
            var bm = new ListBM <TestItemBM> {
                MːData = dm
            };

            bm.Remove(bm[0]);

            Assert.AreEqual(0, bm.Count, "Count");
            Assert.AreEqual(0, dm.Count, "Data.Count");
        }
Ejemplo n.º 15
0
        public void CheckReentrancyThrowsInvalidOperationException()
        {
            var dl = new List <TestItemDM> {
                new TestItemDM(0), new TestItemDM(1), new TestItemDM(2)
            };
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            bl.CollectionChanged += OnViewModelCollectionChangedCallInvalid;
            bl.Add(TestItemBM.New());
            bl.CollectionChanged -= OnViewModelCollectionChangedCallInvalid;
        }
Ejemplo n.º 16
0
        public void Add_DefaultDataProvider_List()
        {
            var dm = new List <TestItemDM>();
            var bm = new ListBM <TestItemBM> {
                MːData = dm
            };

            bm.Add(new TestItemBM {
                MːData = new TestItemDM(100)
            });

            Assert.AreEqual(1, bm.Count, "Count");
            Assert.AreEqual(1, dm.Count, "Data.Count");
        }
Ejemplo n.º 17
0
        public void ICollection()
        {
            var dl = new List <TestItemDM>(new [] { new TestItemDM(0) });
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };
            var vl = (ICollection) new ListVM <TestItemVM> {
                Metadata = { DataProvider = { Data = bl } }
            };

            vl.CopyTo(new TestItemVM[1], 0);
            Assert.AreEqual(1, vl.Count);
            Assert.AreEqual(false, vl.IsSynchronized);
            Assert.IsNotNull(vl.SyncRoot);
        }
Ejemplo n.º 18
0
        public void BusinessList_Object_LocalDataProvider()
        {
            var list = new ListBM <TestObject>();

            list.Metadata.DataProvider.Data = new List <TestData>(new [] { new TestData {
                                                                               A = 1, B = "1", C = DateTime.Now
                                                                           }, new TestData {
                                                                               A = 2, B = "2", C = DateTime.Now
                                                                           } });
            list.Add(new TestObject {
                Metadata = { DataProvider           = { Data = new TestData {
                                                            A          = 3, B = "3", C = DateTime.Now
                                                        } } }
            });
            list.RemoveAt(0);
        }
Ejemplo n.º 19
0
        public void DataListItemsChange()
        {
            var dl = new List <TestItemDM> {
                new TestItemDM(0), new TestItemDM(1), new TestItemDM(2)
            };
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            dl.RemoveAt(2); dl.Add(new TestItemDM(3));
            bl.Metadata.DataProvider.NotifyDataChanged();
            for (int i = 0; i < bl.Count; i++)
            {
                Assert.AreEqual(dl[i], bl[i].Metadata.DataProvider.Data);
            }
        }
Ejemplo n.º 20
0
        public void BeginUpdateEndUpdate()
        {
            var dl = new List <TestItemDM> {
                new TestItemDM(0), new TestItemDM(1), new TestItemDM(2)
            };
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            bl.CollectionChanged += OnViewModelCollectionChangedCallInvalid;
            bl.BeginUpdate();
            Assert.Throws <InvalidOperationException>(() => bl.BeginUpdate());
            bl.Add(TestItemBM.New());
            bl.EndUpdate();
            Assert.Throws <InvalidOperationException>(() => bl.EndUpdate());
            bl.CollectionChanged -= OnViewModelCollectionChangedCallInvalid;
        }
Ejemplo n.º 21
0
        public void DataChange()
        {
            var dl = new List <TestItemDM> {
                new TestItemDM(0), new TestItemDM(1), new TestItemDM(2)
            };
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };

            dl = new List <TestItemDM> {
                new TestItemDM(3), new TestItemDM(4), new TestItemDM(5)
            };
            bl.Metadata.DataProvider.Data = dl;
            for (int i = 0; i < bl.Count; i++)
            {
                Assert.AreEqual(dl[i], bl[i].Metadata.DataProvider.Data);
            }
        }
Ejemplo n.º 22
0
        public void ListVM_Contains_Empty_BusinessList()
        {
            var dl = new List <TestItemDM>();
            var bl = new ListBM <TestItemBM> {
                Metadata = { DataProvider = { Data = dl } }
            };
            var vl = new ListVM <TestItemVM> {
                Metadata = { DataProvider = { Data = bl } }
            };
            var di = (TestItemDM)null;
            var vi = (TestItemVM)null;

            Assert.AreEqual(false, vl.IsReadOnly);
            Assert.AreEqual(false, ((IList)vl).IsFixedSize);

            vl.Add(vi = new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= di = new TestItemDM(0) } }
                                                               } } }
            });
            Assert.AreEqual(1, bl.Count);
            Assert.AreEqual(1, dl.Count);
            Assert.AreEqual(0, vl.IndexOf(vi));
            Assert.AreEqual(0, ((IList)vl).IndexOf(vi));
            Assert.AreEqual(true, ((IList)vl).Contains(vi));
            Assert.AreEqual(vi, vl[0]);
            Assert.AreEqual(vi, ((IList)vl)[0]);
            vl.Add(new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(1) } }
                                                               } } }
            });
            Assert.AreEqual(2, dl.Count);
            vl.Add(new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(2) } }
                                                               } } }
            });
            Assert.AreEqual(3, dl.Count);
            vl.RemoveAt(1);
            Assert.AreEqual(2, dl.Count);
            vl.Remove(vi);
            Assert.AreEqual(1, dl.Count);
            vl.Clear();
            Assert.AreEqual(0, dl.Count);
            vl.Insert(0, new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(0) } }
                                                               } } }
            });
            vl.Insert(0, new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(1) } }
                                                               } } }
            });
            vl.Insert(2, new TestItemVM {
                Metadata = { DataProvider                  = { Data         = new TestItemBM {
                                                                   Metadata                  =                { DataProvider=                { Data= new TestItemDM(2) } }
                                                               } } }
            });
            Assert.AreEqual(3, dl.Count);

            foreach (var item in vl)
            {
                Assert.IsTrue(vl.Contains(item));
            }
            foreach (var item in (IEnumerable)vl)
            {
                Assert.IsTrue(vl.Contains(item));
            }

            vl.CopyTo(new TestItemVM[3], 0);
            vl[0]          = TestItemVM.New();
            ((IList)vl)[0] = TestItemVM.New();
            vl.Move(0, 2);
            vl.Dispose();
        }
Ejemplo n.º 23
0
        public void BusinessList_Contains_Empty_DataList()
        {
            var dl = new List <TestItemDM>();
            var bl = new ListBM <TestItemBM> {
                Metadata =
                {
//TODO:				LogicProvider=new CustomListLogicProvider(OnCollectionChanged,OnCollectionChanged),
                    DataProvider = { Data = dl }
                }
            };
            var di = (TestItemDM)null;
            var bi = (TestItemBM)null;

            Assert.AreEqual(false, bl.IsReadOnly);
            Assert.AreEqual(false, ((IList)bl).IsFixedSize);

            bl.CollectionChanged += OnCollectionChanged;

            ((IList)bl).Add(bi            = new TestItemBM());
            bi.Metadata.DataProvider.Data = di = new TestItemDM(0);
            Assert.AreEqual(1, ((IList)bl).Count);
            Assert.AreEqual(1, dl.Count);
            Assert.AreEqual(0, bl.IndexOf(bi));
            Assert.AreEqual(0, ((IList)bl).IndexOf(bi));
            Assert.AreEqual(true, ((IList)bl).Contains(bi));
            Assert.AreEqual(bi, bl[0]);
            Assert.AreEqual(bi, ((IList)bl)[0]);
            Assert.AreEqual(bl, bl[0].Parent);
            bl.Add(new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(1) } }
            });
            Assert.AreEqual(2, dl.Count);
            bl.Add(new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(2) } }
            });
            Assert.AreEqual(3, dl.Count);
            ((IList)bl).RemoveAt(1);
            Assert.AreEqual(2, dl.Count);
            ((IList)bl).Remove(bi);
            Assert.IsNull(bi.Parent);
            Assert.AreEqual(1, dl.Count);
            ((IList)bl).Clear();
            Assert.AreEqual(0, dl.Count);
            ((IList)bl).Insert(0, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(0) } }
            });
            bl.Insert(0, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(1) } }
            });
            Assert.AreEqual(bl, bl[0].Parent);
            bl.Insert(2, new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(2) } }
            });
            Assert.AreEqual(3, dl.Count);

            foreach (var item in bl)
            {
                Assert.IsTrue(bl.Contains(item));
            }
            foreach (var item in (IEnumerable)bl)
            {
                Assert.IsTrue(bl.Contains(item));
            }

            bl.CopyTo(new TestItemBM[3], 0);
            bl[0] = new TestItemBM {
                Metadata = { DataProvider = { Data = new TestItemDM(0) } }
            };
            ((IList)bl)[0] = TestItemBM.New();
//			bl.Move(0,2);

            bl.CollectionChanged += OnCollectionChanged;
            bl.Dispose();
        }