Exemplo n.º 1
0
        public void TestBasicSqlExpressionDataTypes()
        {
            List <ColumnMetadata> metadata = ColumnMetadata.GetColumnMetadata <Employee>().ToList();

            metadata.ForEach(x => Trace.WriteLine(String.Format("{0}\t{1}\tIs nullable:{2}",
                                                                x.AssociatedProperty.Name, x.SqlDataType, x.IsNullable)));
        }
Exemplo n.º 2
0
        public void TestDataTableConversion()
        {
            Employee test = new Employee()
            {
                Id                       = 5,
                DateHired                = DateTime.Now,
                EmployeeCode             = 'D',
                GlobalId                 = Guid.NewGuid(),
                IsEnabled                = false,
                MaxTimeOffAllowed        = new TimeSpan(7, 0, 0, 0),
                MilesPerHourWalkingSpeed = 3.4F,
                Name                     = "Brad",
                NumberOfCupcakesEaten    = 662553223,
                OrgCode                  = "ASDF",
                Picture                  = new byte[] { 0x00000 },
                RecordLoadedTime         = DateTime.Now,
                RoomNumber               = 30000,
                SalaryPerHour            = 7.25M,
                Weight                   = 230.345676
            };

            List <Employee> testList = new List <Employee>();

            testList.Add(test);

            List <ColumnMetadata> metadata = ColumnMetadata.GetColumnMetadata <Employee>().ToList();

            DataTable dt = Scribe.Conversion.DataTableFactory.CreateTableFromList(testList, metadata);

            Assert.IsTrue(dt.Rows.Count == testList.Count);
            Assert.IsTrue(dt.Columns.Count == metadata.Count);
        }
Exemplo n.º 3
0
        public void TestColumnMetadata()
        {
            List <ColumnMetadata> metadata = ColumnMetadata.GetColumnMetadata <Employee>().ToList();

            Assert.IsTrue(typeof(Employee).GetProperties().Count() == metadata.Count);
            Assert.IsTrue(metadata.Where(x => x.IsNotMapped).Count() == 1);
            Assert.IsTrue(metadata.Where(x => x.IsPrimaryKey && x.IsIdentity).Count() == 1);
            Assert.IsTrue(metadata.Where(x => x.HasConversion).Count() == 1);
        }
Exemplo n.º 4
0
        public void TestCreateTable()
        {
            TableAttribute ta = new TableAttribute("Employee", "dbo");


            var meta      = ColumnMetadata.GetColumnMetadata <Employee>().ToList();
            var testTable = _provider.FormulateCreateTableStatement <Employee>(ta, meta);

            Trace.WriteLine(testTable);
        }
        public void BootstrapDb()
        {
            Config.Global.DbConfigProvider   = new TestDbConfigProvider();
            Config.Global.DefaultSqlProvider = new DefaultSqlProvider();

            provider = Config.Global.DefaultSqlProvider;

            using (ScribeContext con = new ScribeContext())
            {
                var tableAttribute = TableAttribute.GetFor <Employee>();
                var meta           = ColumnMetadata.GetColumnMetadata <Employee>().Where(x => !x.IsNotMapped).ToList();

                bool employeeTableExists =
                    con.Connection.Query <int>("SELECT COUNT(*) FROM sys.tables where name like 'Employee'").First() == 1;

                if (!employeeTableExists)
                {
                    var employeeTable = provider.FormulateCreateTableStatement <Employee>(tableAttribute,
                                                                                          meta
                                                                                          );

                    con.Connection.Execute(employeeTable);
                    string alterStatement = @"
ALTER TABLE [dbo].[Employee]
DROP COLUMN XmlData;

ALTER TABLE [dbo].[Employee]
	ADD [XmlData] XML NOT NULL;

ALTER TABLE [dbo].[Employee]
	DROP COLUMN [Id];

ALTER TABLE [dbo].[Employee]
	ADD [Id] INT NOT NULL IDENTITY(1,1);

ALTER TABLE [dbo].[Employee]
	ADD CONSTRAINT PK_Employee PRIMARY KEY ([Id]);"    ;

                    con.Connection.Execute(alterStatement);
                }
                string truncateStatement = @"
TRUNCATE TABLE [dbo].[Employee]
";

                con.Connection.Execute(truncateStatement);



                con.Commit();
            }
        }
Exemplo n.º 6
0
        public void TestInsertMergeStatement()
        {
            TableAttribute ta = new TableAttribute("Employee", "dbo");



            var meta = ColumnMetadata.GetColumnMetadata <Employee>().ToList();


            var testTable = _provider.GetMergeStatementForInsert <Employee>(meta,
                                                                            ta, ta, ta);

            Trace.WriteLine(testTable);
        }
Exemplo n.º 7
0
        public void TestDeleteMergeStatement()
        {
            TableAttribute input       = new TableAttribute("EmployeeIn", "dbo");
            TableAttribute destination = new TableAttribute("Employee", "dbo");



            var meta = ColumnMetadata.GetColumnMetadata <Employee>().ToList();


            var testTable = _provider.GetMergeStatementForDelete <Employee>(meta,
                                                                            input, destination, input);

            Trace.WriteLine(testTable);
        }