public void AddNewNotNullRelationshipToTableWithData() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf <Simple2.Post>(); var to = new MutableConfiguration(ConnectionString); to.AddNamespaceOf <Simple3.Post>(); to.Setup <Simple3.Post>().Property(p => p.Blog).IsNullable = false; var migrator = MakeMigrator(from, true); var answerProvider = new Mock <IAnswerProvider>(); answerProvider.Setup(a => a.GetAnswer <int>(It.IsAny <string>())).Returns(99); IEnumerable <string> warnings; IEnumerable <string> errors; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock <ILogger>().Object, new string[0], out warnings, out errors); Assert.Equal(Regex.Replace(@"create table [Blogs] ([Id] int not null identity(1,1) primary key, [Title] nvarchar(255) null); alter table [Posts] add [BlogId] int not null default (99); alter table [Posts] add constraint fk_Post_Blog_Blog foreign key ([BlogId]) references [Blogs]([Id]); create index [idx_Post_Blog] on [Posts] ([BlogId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); }
public void ExcludeRemovesColumnFromGet() { var config = new MutableConfiguration(new System.Configuration.ConnectionStringSettings("Default", "", "System.Data.SqlClient")); config.AddNamespaceOf <Post>(); config.Setup <Post>().Property(p => p.Content).ExcludeByDefault(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateGetSql <Post, int>(1); this.output.WriteLine(sql.Sql); Assert.Equal("select [PostId], [Title], [Rating], [AuthorId], [BlogId], [DoNotMap] from [Posts] where PostId = @Id", sql.Sql); }
public void ExcludeRemovesFetchedCollectionColumn() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>().Fetch(p => p.Comments); var config = new MutableConfiguration(new System.Configuration.ConnectionStringSettings("Default", "", "System.Data.SqlClient")); config.AddNamespaceOf <Post>(); config.Setup <Comment>().Property(c => c.Content).ExcludeByDefault(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateSql(query); this.output.WriteLine(sql.Sql); Assert.Equal("select t.[PostId], t.[Title], t.[Content], t.[Rating], t.[AuthorId], t.[BlogId], t.[DoNotMap], t_1.[CommentId], t_1.[PostId], t_1.[UserId], t_1.[CommentDate] from [Posts] as t left join [Comments] as t_1 on t.PostId = t_1.PostId order by t.[PostId]", sql.Sql); }
public void IncludeAllReaddsColumnFromRoot() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>().IncludeAll(); var config = new MutableConfiguration(new System.Configuration.ConnectionStringSettings("Default", "", "System.Data.SqlClient")); config.AddNamespaceOf <Post>(); config.Setup <Post>().Property(p => p.Content).ExcludeByDefault(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateSql(query); this.output.WriteLine(sql.Sql); Assert.Equal("select [PostId], [Title], [Content], [Rating], [AuthorId], [BlogId], [DoNotMap] from [Posts]", sql.Sql); }
public void IncludeAllReaddsColumn() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>().Fetch(p => p.Blog).IncludeAll(); var config = new MutableConfiguration(new System.Configuration.ConnectionStringSettings("Default", "", "System.Data.SqlClient")); config.AddNamespaceOf <Post>(); config.Setup <Blog>().Property(b => b.Description).ExcludeByDefault(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateSql(query); this.output.WriteLine(sql.Sql); Assert.Equal("select t.[PostId], t.[Title], t.[Content], t.[Rating], t.[AuthorId], t.[DoNotMap], t_1.[BlogId], t_1.[Title], t_1.[CreateDate], t_1.[Description], t_1.[OwnerId] from [Posts] as t left join [Blogs] as t_1 on t.BlogId = t_1.BlogId", sql.Sql); }
private IConfiguration GetConfig <TEntity, TProperty>(Expression <Func <TEntity, TProperty> > excludeByDefault = null) { var config = new MutableConfiguration(); config.AddNamespaceOf <Post>(); if (excludeByDefault != null) { config.Setup <TEntity>() .Property(excludeByDefault) .ExcludeByDefault(); } return(config); }
public void ExcludeRemovesColumnFromRoot() { var query = this.GetSelectQuery <Post>(); var config = new MutableConfiguration(); config.AddNamespaceOf <Post>(); config.Setup <Post>() .Property(p => p.Content) .ExcludeByDefault(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateSql(query, new AutoNamingDynamicParameters()); this.output.WriteLine(sql.Sql); Assert.Equal("select [PostId], [Title], [Rating], [AuthorId], [BlogId], [DoNotMap] from [Posts]", sql.Sql); }
public void ExcludeRemovesFetchedParentColumn() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>() .Fetch(p => p.Blog); var config = new MutableConfiguration(); config.AddNamespaceOf <Post>(); config.Setup <Blog>() .Property(b => b.Description) .ExcludeByDefault(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateSql(query, new AutoNamingDynamicParameters()); this.output.WriteLine(sql.Sql); Assert.Equal("select t.[PostId], t.[Title], t.[Content], t.[Rating], t.[AuthorId], t.[DoNotMap], t_1.[BlogId], t_1.[Title], t_1.[CreateDate], t_1.[OwnerId] from [Posts] as t left join [Blogs] as t_1 on t.BlogId = t_1.BlogId", sql.Sql); }
public void AddNewNotNullRelationshipToTableWithData() { var from = new MutableConfiguration(ConnectionString).AddNamespaceOf<Simple2.Post>(); var to = new MutableConfiguration(ConnectionString); to.AddNamespaceOf<Simple3.Post>(); to.Setup<Simple3.Post>().Property(p => p.Blog).IsNullable = false; var migrator = MakeMigrator(from, true); var answerProvider = new Mock<IAnswerProvider>(); answerProvider.Setup(a => a.GetAnswer<int>(It.IsAny<string>())).Returns(99); IEnumerable<string> warnings; IEnumerable<string> errors; var script = migrator.GenerateSqlDiff( @from.Maps, to.Maps, answerProvider.Object, new Mock<ILogger>().Object, new string[0], out warnings, out errors); Assert.Equal(Regex.Replace(@"create table [Blogs] ([Id] int not null identity(1,1) primary key, [Title] nvarchar(255) null); alter table [Posts] add [BlogId] int not null default (99); alter table [Posts] add constraint fk_Post_Blog_Blog foreign key ([BlogId]) references [Blogs]([Id]); create index [idx_Post_Blog] on [Posts] ([BlogId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); }