public void Can_create_columns_with_default_value_expressions_for_all_types() { ResetDatabase(); var migrator = CreateMigrator <ShopContext_v1>(); migrator.Update(); var defaultValuesMigration = new DefaultValueSqlMigration(); var createTableOperation = (CreateTableOperation)defaultValuesMigration.GetOperations().Single(); WhenSqlCe( () => { createTableOperation.Columns.Remove(createTableOperation.Columns.Single(c => c.Name == "DateTimeOffset")); createTableOperation.Columns.Remove(createTableOperation.Columns.Single(c => c.Name == "Time")); }); migrator = CreateMigrator <ShopContext_v1>(defaultValuesMigration); migrator.Update(); var table = Info.Tables.Single(t => t.Name == "DefaultValueSql"); Assert.True(table.Columns.Any(c => c.Name == "Binary" && c.Default.Contains("CONVERT([binary],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Boolean" && c.Default.Contains("CONVERT([bit],'1'"))); Assert.True(table.Columns.Any(c => c.Name == "Byte" && c.Default.Contains("CONVERT([tinyint],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "DateTime" && c.Default.Contains("CONVERT([datetime],'1947/08/15 03:33:20'"))); Assert.True(table.Columns.Any(c => c.Name == "Decimal" && c.Default.Contains("CONVERT([money],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Double" && c.Default.Contains("CONVERT([float],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Guid" && c.Default.Contains("CONVERT([uniqueidentifier],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Int" && c.Default.Contains("CONVERT([int],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Long" && c.Default.Contains("CONVERT([bigint],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Short" && c.Default.Contains("CONVERT([smallint],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Single" && c.Default.Contains("CONVERT([real],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "String" && c.Default.Contains("CONVERT([nvarchar](100),(123)"))); WhenNotSqlCe( () => { Assert.True( table.Columns.Any( c => c.Name == "DateTimeOffset" && c.Default.StartsWith("(CONVERT([datetimeoffset],'1947/08/15 03:33:20'"))); Assert.True(table.Columns.Any(c => c.Name == "Time" && c.Default.StartsWith("(CONVERT([time],'03:33:20'"))); }); }
public void Can_create_columns_with_default_value_expressions_for_all_types() { ResetDatabase(); var migrator = CreateMigrator<ShopContext_v1>(); migrator.Update(); var defaultValuesMigration = new DefaultValueSqlMigration(); var createTableOperation = (CreateTableOperation)defaultValuesMigration.GetOperations().Single(); WhenSqlCe( () => { createTableOperation.Columns.Remove(createTableOperation.Columns.Single(c => c.Name == "DateTimeOffset")); createTableOperation.Columns.Remove(createTableOperation.Columns.Single(c => c.Name == "Time")); }); migrator = CreateMigrator<ShopContext_v1>(defaultValuesMigration); migrator.Update(); var table = Info.Tables.Single(t => t.Name == "DefaultValueSql"); Assert.True(table.Columns.Any(c => c.Name == "Binary" && c.Default.Contains("CONVERT([binary],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Boolean" && c.Default.Contains("CONVERT([bit],'1'"))); Assert.True(table.Columns.Any(c => c.Name == "Byte" && c.Default.Contains("CONVERT([tinyint],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "DateTime" && c.Default.Contains("CONVERT([datetime],'1947/08/15 03:33:20'"))); Assert.True(table.Columns.Any(c => c.Name == "Decimal" && c.Default.Contains("CONVERT([money],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Double" && c.Default.Contains("CONVERT([float],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Guid" && c.Default.Contains("CONVERT([uniqueidentifier],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Int" && c.Default.Contains("CONVERT([int],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Long" && c.Default.Contains("CONVERT([bigint],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Short" && c.Default.Contains("CONVERT([smallint],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "Single" && c.Default.Contains("CONVERT([real],'123'"))); Assert.True(table.Columns.Any(c => c.Name == "String" && c.Default.Contains("CONVERT([nvarchar](100),(123)"))); WhenNotSqlCe( () => { Assert.True( table.Columns.Any( c => c.Name == "DateTimeOffset" && c.Default.StartsWith("(CONVERT([datetimeoffset],'1947/08/15 03:33:20'"))); Assert.True(table.Columns.Any(c => c.Name == "Time" && c.Default.StartsWith("(CONVERT([time],'03:33:20'"))); }); }