示例#1
0
        public void T04_Insert()
        {
            ISqlClient sqlClient = getClient();

            sqlClient.ClearTable(testTable);

            // Get column definitions (from data base)
            List <SqlColumn> columns = sqlClient.GetColumns(testTable);

            // Add some information from test meta data definition
            foreach (ColumnMetadata cmd in columnMetadata)
            {
                SqlColumn col = columns.Where(n => n.Name == cmd.Fieldname).First();
                col.ValueString = cmd.TestValue;
                col.IsDocument  = cmd.IsDocument;
            }

            // Remove unsupported columns
            List <SqlColumn> toBeRemoved = columns.Where(n => n.SqlType == null).ToList();

            foreach (SqlColumn col in toBeRemoved)
            {
                columns.Remove(col);
            }

            // Convert strings to objects and insert row
            sqlClient.SetObjectValues(columns);
            sqlClient.Insert(columns);

            // Read back row from data base
            List <SqlColumn> result = new List <SqlColumn>();

            foreach (SqlColumn col in columns)
            {
                result.Add(new SqlColumn()
                {
                    Name = col.Name, SqlType = col.SqlType
                });
            }
            sqlClient.GetOneRow(result);

            // Verify that input values and output values match
            foreach (SqlColumn col in columns)
            {
                compareSqlColumn(col, result.Where(n => n.Name == col.Name).First());
            }

            // Verify that docuoment has been stored properly as blob
            string resultDocument = Path.Combine(Path.GetTempPath(), "Document1.pdf");

            File.WriteAllBytes(resultDocument,
                               columns.Where(n => n.Name == "MyDocument").First().ValueObject as Byte[]);
            Assert.IsTrue(SIEEUtils.CompareFiles(testDocument, resultDocument));
            File.Delete(resultDocument);

            // Clear table
            sqlClient.ClearTable(testTable);
        }