Пример #1
0
        public void DmTable_Clone_Copy()
        {
            var tbl = new DmTable("ServiceTickets");
            var id  = new DmColumn <Guid>("ServiceTicketID");

            tbl.Columns.Add(id);
            var key = new DmKey(new DmColumn[] { id });

            tbl.PrimaryKey = key;
            tbl.Columns.Add(new DmColumn <string>("Title"));
            tbl.Columns.Add(new DmColumn <string>("Description"));
            tbl.Columns.Add(new DmColumn <int>("StatusValue"));
            tbl.Columns.Add(new DmColumn <int>("EscalationLevel"));
            tbl.Columns.Add(new DmColumn <DateTime>("Opened"));
            tbl.Columns.Add(new DmColumn <DateTime>("Closed"));
            tbl.Columns.Add(new DmColumn <int>("CustomerID"));

            var st = tbl.NewRow();

            st["ServiceTicketID"] = Guid.NewGuid();
            st["Title"]           = "Titre AER";
            st["Description"]     = "Description 2";
            st["EscalationLevel"] = 1;
            st["StatusValue"]     = 2;
            st["Opened"]          = DateTime.Now;
            st["Closed"]          = null;
            st["CustomerID"]      = 1;
            tbl.Rows.Add(st);

            var tbl2 = tbl.Clone();

            Assert.NotSame(tbl2, tbl);
            Assert.Empty(tbl2.Rows);
            Assert.Equal(8, tbl2.Columns.Count);
            Assert.NotNull(tbl2.PrimaryKey);

            var tbl3 = tbl.Copy();

            Assert.NotSame(tbl3, tbl2);
            Assert.NotSame(tbl3, tbl);
            Assert.NotNull(tbl3.PrimaryKey);
            Assert.Equal(8, tbl3.Columns.Count);
            Assert.NotEmpty(tbl3.Rows);
        }