Ejemplo n.º 1
0
        public void Check_RowsSates()
        {
            var dmTable = set.Tables[0];

            dmTable.Rows[0].Delete();
            dmTable.Rows[1].SetAdded();
            dmTable.Rows[2].SetModified();

            DmSetSurrogate dss = new DmSetSurrogate(set);

            // Convert to DmSetSurrogate
            var surrogateDs = new DmSetSurrogate(set);
            // serialize as json string
            var stringSurrogate = JsonConvert.SerializeObject(surrogateDs);
            // deserialize as surrogate
            var surrogateDsFromJson = JsonConvert.DeserializeObject <DmSetSurrogate>(stringSurrogate);
            // Convert to DmSet
            var set2 = surrogateDs.ConvertToDmSet(set);

            var rows2 = set2.Tables[0].Rows;


            Assert.Equal(DmRowState.Deleted, rows2[0].RowState);
            Assert.Equal(DmRowState.Added, rows2[1].RowState);
            Assert.Equal(DmRowState.Modified, rows2[2].RowState);
            Assert.Equal(DmRowState.Unchanged, rows2[3].RowState);
            Assert.Equal(DmRowState.Unchanged, rows2[4].RowState);
            Assert.Equal(DmRowState.Unchanged, rows2[5].RowState);
        }
Ejemplo n.º 2
0
        public void Convert_DmSetSurrogate_To_DmSet()
        {
            // Convert to DmSetSurrogate
            var surrogateDs = new DmSetSurrogate(set);
            // serialize as json string
            var stringSurrogate = JsonConvert.SerializeObject(surrogateDs);
            // deserialize as surrogate
            var surrogateDsFromJson = JsonConvert.DeserializeObject <DmSetSurrogate>(stringSurrogate);
            // Convert to DmSet
            var set2 = surrogateDs.ConvertToDmSet(set);

            Assert.NotSame(set, set2);
            Assert.Equal(set.CaseSensitive, set2.CaseSensitive);
            Assert.Equal(set.Culture, set2.Culture);
            Assert.Equal(set.DmSetName, set2.DmSetName);
            Assert.Equal(set.Tables.Count, set2.Tables.Count);
            Assert.Equal(set.Tables[0].Columns.Count, set2.Tables[0].Columns.Count);
            Assert.Equal(set.Tables[0].Rows.Count, set2.Tables[0].Rows.Count);
        }
Ejemplo n.º 3
0
        public void Properties()
        {
            DmSet   set           = new DmSet("DMSET");
            DmTable clientsTable  = new DmTable("Clients");
            DmTable productsTable = new DmTable("Products");

            set.Tables.Add(clientsTable);
            set.Tables.Add(productsTable);

            DmColumn productId = new DmColumn <Int32>("Id");

            productId.AllowDBNull     = false;
            productId.IsAutoIncrement = true;
            productId.IsCompute       = false;
            productId.IsUnicode       = false;
            productId.IsUnsigned      = false;
            productsTable.Columns.Add(productId);

            DmColumn fkClientId = new DmColumn <Guid>("clientId");

            fkClientId.AllowDBNull = true;
            productsTable.Columns.Add(fkClientId);

            DmColumn productName = new DmColumn <string>("name");

            productName.AllowDBNull = true;
            productName.DbType      = System.Data.DbType.StringFixedLength;
            productName.MaxLength   = 150;
            productId.IsCompute     = false;
            productId.IsUnicode     = true;
            productId.IsUnsigned    = true;
            productsTable.Columns.Add(productName);

            DmColumn productPrice = new DmColumn <Decimal>("price");

            productPrice.AllowDBNull = false;
            productPrice.DbType      = System.Data.DbType.VarNumeric;
            productPrice.Precision   = 6;
            productPrice.Scale       = 2;
            // for test purpose
            productId.IsCompute = true;
            productsTable.Columns.Add(productPrice);

            productsTable.PrimaryKey = new DmKey(new DmColumn[] { productId, productName, productPrice });

            DmColumn clientId = new DmColumn <Guid>("Id");

            clientId.AllowDBNull = false;
            clientsTable.Columns.Add(clientId);

            DmColumn clientName = new DmColumn <string>("Name");

            clientsTable.Columns.Add(clientName);

            clientsTable.PrimaryKey = new DmKey(clientId);

            // ForeignKey
            DmRelation fkClientRelation = new DmRelation("FK_Products_Clients", clientId, fkClientId);

            productsTable.AddForeignKey(fkClientRelation);

            var clientGuid = Guid.NewGuid();
            var drClient   = clientsTable.NewRow();

            drClient["Name"] = "Pertus";
            drClient["Id"]   = clientGuid;
            clientsTable.Rows.Add(drClient);

            var drProduct = productsTable.NewRow();

            drProduct["clientId"] = clientGuid;
            drProduct["name"]     = "Ensemble bleu blanc rouge";
            drProduct["price"]    = 12.23d;
            productsTable.Rows.Add(drProduct);


            // Convert to DmSetSurrogate
            var surrogateDs = new DmSetSurrogate(set);
            // serialize as json string
            var stringSurrogate = JsonConvert.SerializeObject(surrogateDs);
            // deserialize as surrogate
            var surrogateDsFromJson = JsonConvert.DeserializeObject <DmSetSurrogate>(stringSurrogate);
            // Convert to DmSet
            var set2 = surrogateDs.ConvertToDmSet(set);

            // Assertions on DmSet properties
            Assert.Equal(set.DmSetName, set2.DmSetName);
            Assert.Equal(set.Culture, set2.Culture);
            Assert.Equal(set.CaseSensitive, set2.CaseSensitive);
            Assert.Equal(set.Relations.Count, set2.Relations.Count);
            Assert.Equal(set.Tables.Count, set2.Tables.Count);

            //Assertions on Table properties
            var productsTable2 = set2.Tables["Products"];
            var clientsTable2  = set2.Tables["Clients"];

            AssertIsEqual(productsTable, productsTable2);
            AssertIsEqual(clientsTable, clientsTable2);

            // Assertions on columns
            var productId2 = set2.Tables["Products"].Columns["Id"];

            AssertIsEqual(productId, productId2);
            var fkClientId2 = set2.Tables["Products"].Columns["clientId"];

            AssertIsEqual(fkClientId, fkClientId2);
            var productName2 = set2.Tables["Products"].Columns["name"];

            AssertIsEqual(productName, productName2);
            var productPrice2 = set2.Tables["Products"].Columns["price"];

            AssertIsEqual(productPrice, productPrice2);
            var clientId2 = set2.Tables["Clients"].Columns["Id"];

            AssertIsEqual(clientId, clientId2);
            var clientName2 = set2.Tables["Clients"].Columns["Name"];

            AssertIsEqual(clientName, clientName2);
        }