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 ComplexDomainBuilds() { var config = new MutableConfiguration(ConnectionString); config.AddNamespaceOf <Post>(); var migrator = MakeMigrator(config); IEnumerable <string> errors; IEnumerable <string> warnings; var script = migrator.GenerateSqlDiff( new IMap[] { }, config.Maps, null, new Mock <ILogger>().Object, new string[0], new string[0], out warnings, out errors); Assert.Equal(Regex.Replace(@"create table [Blogs] ([BlogId] int not null identity(1,1) primary key, [Title] nvarchar(255) null, [CreateDate] datetime not null default (current_timestamp), [Description] nvarchar(255) null); create table [Categories] ([CategoryId] int not null identity(1,1) primary key, [ParentId] int null, [Name] nvarchar(255) null); create table [Comments] ([CommentId] int not null identity(1,1) primary key, [Content] nvarchar(255) null, [PostId] int null, [UserId] int null, [CommentDate] datetime not null default (current_timestamp)); create table [Likes] ([LikeId] int not null identity(1,1) primary key, [UserId] int null, [CommentId] int null); create table [OneToOneLefts] ([OneToOneLeftId] int not null identity(1,1) primary key, [RightId] int null, [Name] nvarchar(255) null); create table [OneToOneRights] ([OneToOneRightId] int not null identity(1,1) primary key, [LeftId] int null, [Name] nvarchar(255) null); create table [Pairs] ([PairId] int not null identity(1,1) primary key, [ReferencesId] int null, [ReferencedById] int null); create table [Posts] ([PostId] int not null identity(1,1) primary key, [Title] nvarchar(255) null, [Content] nvarchar(255) null, [Rating] decimal(18,10) not null default (0), [AuthorId] int null, [BlogId] int null, [DoNotMap] bit not null default (0)); create table [PostTags] ([PostTagId] int not null identity(1,1) primary key, [PostId] int null, [TagId] int null); create table [SimpleClasses] ([SimpleClassId] int not null identity(1,1) primary key, [Name] nvarchar(255) null, [CreatedDate] datetime not null default (current_timestamp)); create table [Tags] ([TagId] int not null identity(1,1) primary key, [Content] nvarchar(255) null); create table [Users] ([UserId] int not null identity(1,1) primary key, [Username] nvarchar(255) null, [EmailAddress] nvarchar(255) null, [Password] nvarchar(255) null, [IsEnabled] bit not null default (0), [HeightInMeters] decimal(18,10) not null default (0)); alter table [Categories] add constraint fk_Category_Category_Parent foreign key ([ParentId]) references [Categories]([CategoryId]); alter table [Comments] add constraint fk_Comment_Post_Post foreign key ([PostId]) references [Posts]([PostId]); alter table [Comments] add constraint fk_Comment_User_User foreign key ([UserId]) references [Users]([UserId]); alter table [Likes] add constraint fk_Like_User_User foreign key ([UserId]) references [Users]([UserId]); alter table [Likes] add constraint fk_Like_Comment_Comment foreign key ([CommentId]) references [Comments]([CommentId]); alter table [OneToOneLefts] add constraint fk_OneToOneLeft_OneToOneRight_Right foreign key ([RightId]) references [OneToOneRights]([OneToOneRightId]); alter table [OneToOneRights] add constraint fk_OneToOneRight_OneToOneLeft_Left foreign key ([LeftId]) references [OneToOneLefts]([OneToOneLeftId]); alter table [Pairs] add constraint fk_Pair_Pair_References foreign key ([ReferencesId]) references [Pairs]([PairId]); alter table [Pairs] add constraint fk_Pair_Pair_ReferencedBy foreign key ([ReferencedById]) references [Pairs]([PairId]); alter table [Posts] add constraint fk_Post_User_Author foreign key ([AuthorId]) references [Users]([UserId]); alter table [Posts] add constraint fk_Post_Blog_Blog foreign key ([BlogId]) references [Blogs]([BlogId]); alter table [PostTags] add constraint fk_PostTag_Post_Post foreign key ([PostId]) references [Posts]([PostId]); alter table [PostTags] add constraint fk_PostTag_Tag_Tag foreign key ([TagId]) references [Tags]([TagId]); create index [idx_Category_Parent] on [Categories] ([ParentId]); create index [idx_Comment_Post] on [Comments] ([PostId]); create index [idx_Comment_User] on [Comments] ([UserId]); create index [idx_Like_User] on [Likes] ([UserId]); create index [idx_Like_Comment] on [Likes] ([CommentId]); create index [idx_OneToOneLeft_Right] on [OneToOneLefts] ([RightId]); create index [idx_OneToOneRight_Left] on [OneToOneRights] ([LeftId]); create index [idx_Pair_References] on [Pairs] ([ReferencesId]); create index [idx_Pair_ReferencedBy] on [Pairs] ([ReferencedById]); create index [idx_Post_Author] on [Posts] ([AuthorId]); create index [idx_Post_Blog] on [Posts] ([BlogId]); create index [idx_PostTag_Post] on [PostTags] ([PostId]); create index [idx_PostTag_Tag] on [PostTags] ([TagId]);", @"(?<!\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 ExplicitExcludeRemovesFetchedParentColumn() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>().Fetch(p => p.Blog).Exclude(p => p.Blog.Description); var config = new MutableConfiguration(new System.Configuration.ConnectionStringSettings("Default", "", "System.Data.SqlClient")); config.AddNamespaceOf <Post>(); 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.[OwnerId] from [Posts] as t left join [Blogs] as t_1 on t.BlogId = t_1.BlogId", sql.Sql); }
public void ExplicitExcludeRemovesColumnFromRoot() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>().Exclude(p => p.Content); var config = new MutableConfiguration(new System.Configuration.ConnectionStringSettings("Default", "", "System.Data.SqlClient")); config.AddNamespaceOf <Post>(); var writer = new SelectWriter(new SqlServerDialect(), config); var sql = writer.GenerateSql(query); this.output.WriteLine(sql.Sql); Assert.Equal("select [PostId], [Title], [Rating], [AuthorId], [BlogId], [DoNotMap] from [Posts]", sql.Sql); }
public void ExplicitExcludeRemovesColumnFromRoot() { var query = (SelectQuery <Post>) this.GetSelectQuery <Post>() .Exclude(p => p.Content); var config = new MutableConfiguration(); config.AddNamespaceOf <Post>(); 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.[Rating], t.[AuthorId], t.[BlogId], t.[DoNotMap] from [Posts] as t", 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); }
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); 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()); }
public void ComplexDomainBuilds() { var config = new MutableConfiguration(ConnectionString); config.AddNamespaceOf<Post>(); var migrator = MakeMigrator(config); IEnumerable<string> errors; IEnumerable<string> warnings; var script = migrator.GenerateSqlDiff( new IMap[] { }, config.Maps, null, new Mock<ILogger>().Object, new string[0], out warnings, out errors); Assert.Equal(Regex.Replace(@"create table [Blogs] ([BlogId] int not null identity(1,1) primary key, [Title] nvarchar(255) null, [CreateDate] datetime not null default (current_timestamp), [Description] nvarchar(255) null); create table [Categories] ([CategoryId] int not null identity(1,1) primary key, [ParentId] int null, [Name] nvarchar(255) null); create table [Comments] ([CommentId] int not null identity(1,1) primary key, [Content] nvarchar(255) null, [PostId] int null, [UserId] int null, [CommentDate] datetime not null default (current_timestamp)); create table [Likes] ([LikeId] int not null identity(1,1) primary key, [UserId] int null, [CommentId] int null); create table [OneToOneLefts] ([OneToOneLeftId] int not null identity(1,1) primary key, [RightId] int null, [Name] nvarchar(255) null); create table [OneToOneRights] ([OneToOneRightId] int not null identity(1,1) primary key, [LeftId] int null, [Name] nvarchar(255) null); create table [Pairs] ([PairId] int not null identity(1,1) primary key, [ReferencesId] int null, [ReferencedById] int null); create table [Posts] ([PostId] int not null identity(1,1) primary key, [Title] nvarchar(255) null, [Content] nvarchar(255) null, [Rating] decimal(18,10) not null default (0), [AuthorId] int null, [BlogId] int null, [DoNotMap] bit not null default (0)); create table [PostTags] ([PostTagId] int not null identity(1,1) primary key, [PostId] int null, [TagId] int null); create table [SimpleClasses] ([SimpleClassId] int not null identity(1,1) primary key, [Name] nvarchar(255) null, [CreatedDate] datetime not null default (current_timestamp)); create table [Tags] ([TagId] int not null identity(1,1) primary key, [Content] nvarchar(255) null); create table [Users] ([UserId] int not null identity(1,1) primary key, [Username] nvarchar(255) null, [EmailAddress] nvarchar(255) null, [Password] nvarchar(255) null, [IsEnabled] bit not null default (0), [HeightInMeters] decimal(18,10) not null default (0)); alter table [Categories] add constraint fk_Category_Category_Parent foreign key ([ParentId]) references [Categories]([CategoryId]); alter table [Comments] add constraint fk_Comment_Post_Post foreign key ([PostId]) references [Posts]([PostId]); alter table [Comments] add constraint fk_Comment_User_User foreign key ([UserId]) references [Users]([UserId]); alter table [Likes] add constraint fk_Like_User_User foreign key ([UserId]) references [Users]([UserId]); alter table [Likes] add constraint fk_Like_Comment_Comment foreign key ([CommentId]) references [Comments]([CommentId]); alter table [OneToOneLefts] add constraint fk_OneToOneLeft_OneToOneRight_Right foreign key ([RightId]) references [OneToOneRights]([OneToOneRightId]); alter table [OneToOneRights] add constraint fk_OneToOneRight_OneToOneLeft_Left foreign key ([LeftId]) references [OneToOneLefts]([OneToOneLeftId]); alter table [Pairs] add constraint fk_Pair_Pair_References foreign key ([ReferencesId]) references [Pairs]([PairId]); alter table [Pairs] add constraint fk_Pair_Pair_ReferencedBy foreign key ([ReferencedById]) references [Pairs]([PairId]); alter table [Posts] add constraint fk_Post_User_Author foreign key ([AuthorId]) references [Users]([UserId]); alter table [Posts] add constraint fk_Post_Blog_Blog foreign key ([BlogId]) references [Blogs]([BlogId]); alter table [PostTags] add constraint fk_PostTag_Post_Post foreign key ([PostId]) references [Posts]([PostId]); alter table [PostTags] add constraint fk_PostTag_Tag_Tag foreign key ([TagId]) references [Tags]([TagId]); create index [idx_Category_Parent] on [Categories] ([ParentId]); create index [idx_Comment_Post] on [Comments] ([PostId]); create index [idx_Comment_User] on [Comments] ([UserId]); create index [idx_Like_User] on [Likes] ([UserId]); create index [idx_Like_Comment] on [Likes] ([CommentId]); create index [idx_OneToOneLeft_Right] on [OneToOneLefts] ([RightId]); create index [idx_OneToOneRight_Left] on [OneToOneRights] ([LeftId]); create index [idx_Pair_References] on [Pairs] ([ReferencesId]); create index [idx_Pair_ReferencedBy] on [Pairs] ([ReferencedById]); create index [idx_Post_Author] on [Posts] ([AuthorId]); create index [idx_Post_Blog] on [Posts] ([BlogId]); create index [idx_PostTag_Post] on [PostTags] ([PostId]); create index [idx_PostTag_Tag] on [PostTags] ([TagId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); }
public void ComplexDomainBuilds() { var config = new MutableConfiguration(); config.AddNamespaceOf <Dashing.Tests.TestDomain.Post>(); var migrator = MakeMigrator(config); IEnumerable <string> errors; IEnumerable <string> warnings; var script = migrator.GenerateSqlDiff( new IMap[] { }, config.Maps, null, new string[0], new string[0], out warnings, out errors); this.output.WriteLine(script.Trim()); Assert.Equal(Regex.Replace(@"create table [Blogs] ([BlogId] int not null identity(1,1) primary key, [Title] nvarchar(255) null, [CreateDate] datetime2(2) not null default (current_timestamp), [Description] nvarchar(255) null, [OwnerId] int null); create table [BoolClasses] ([BoolClassId] int not null identity(1,1) primary key, [IsFoo] bit not null default (0)); create table [Comments] ([CommentId] int not null identity(1,1) primary key, [Content] nvarchar(255) null, [PostId] int null, [UserId] int null, [CommentDate] datetime2(2) not null default (current_timestamp)); create table [Customers] ([CustomerId] int not null identity(1,1) primary key, [Name] nvarchar(255) null); create table [Deliveries] ([DeliveryId] int not null identity(1,1) primary key, [Name] nvarchar(255) null); create table [Likes] ([LikeId] int not null identity(1,1) primary key, [UserId] int null, [CommentId] int null); create table [LineItems] ([LineItemId] int not null identity(1,1) primary key, [OrderId] int null); create table [OneToOneLefts] ([OneToOneLeftId] int not null identity(1,1) primary key, [RightId] int null, [Name] nvarchar(255) null); create table [OneToOneRights] ([OneToOneRightId] int not null identity(1,1) primary key, [LeftId] int null, [Name] nvarchar(255) null); create table [Orders] ([OrderId] int not null identity(1,1) primary key, [DeliveryId] int null, [CustomerId] int null); create table [Pairs] ([PairId] int not null identity(1,1) primary key, [ReferencesId] int null, [ReferencedById] int null); create table [Posts] ([PostId] int not null identity(1,1) primary key, [Title] nvarchar(255) null, [Content] nvarchar(255) null, [Rating] decimal(18,10) not null default (0), [AuthorId] int null, [BlogId] int null, [DoNotMap] bit not null default (0)); create table [PostTags] ([PostTagId] int not null identity(1,1) primary key, [PostId] int null, [ElTagId] int null); create table [Tags] ([TagId] int not null identity(1,1) primary key, [Content] nvarchar(255) null); create table [ThingThatReferencesOrderNullables] ([Id] int not null identity(1,1) primary key, [OrderId] int null); create table [ThingWithNullables] ([Id] int not null identity(1,1) primary key, [Nullable] int null, [Name] nvarchar(255) null); create table [ReferencesThingWithNullables] ([Id] int not null identity(1,1) primary key, [ThingId] int null); create table [Users] ([UserId] int not null identity(1,1) primary key, [Username] nvarchar(255) null, [EmailAddress] nvarchar(255) null, [Password] nvarchar(255) null, [IsEnabled] bit not null default (0), [HeightInMeters] decimal(18,10) not null default (0)); alter table [Blogs] add constraint fk_Blog_User_Owner foreign key ([OwnerId]) references [Users]([UserId]); alter table [Comments] add constraint fk_Comment_Post_Post foreign key ([PostId]) references [Posts]([PostId]); alter table [Comments] add constraint fk_Comment_User_User foreign key ([UserId]) references [Users]([UserId]); alter table [Likes] add constraint fk_Like_User_User foreign key ([UserId]) references [Users]([UserId]); alter table [Likes] add constraint fk_Like_Comment_Comment foreign key ([CommentId]) references [Comments]([CommentId]); alter table [LineItems] add constraint fk_LineItem_Order_Order foreign key ([OrderId]) references [Orders]([OrderId]); alter table [OneToOneLefts] add constraint fk_OneToOneLeft_OneToOneRight_Right foreign key ([RightId]) references [OneToOneRights]([OneToOneRightId]); alter table [OneToOneRights] add constraint fk_OneToOneRight_OneToOneLeft_Left foreign key ([LeftId]) references [OneToOneLefts]([OneToOneLeftId]); alter table [Orders] add constraint fk_Order_Delivery_Delivery foreign key ([DeliveryId]) references [Deliveries]([DeliveryId]); alter table [Orders] add constraint fk_Order_Customer_Customer foreign key ([CustomerId]) references [Customers]([CustomerId]); alter table [Pairs] add constraint fk_Pair_Pair_References foreign key ([ReferencesId]) references [Pairs]([PairId]); alter table [Pairs] add constraint fk_Pair_Pair_ReferencedBy foreign key ([ReferencedById]) references [Pairs]([PairId]); alter table [Posts] add constraint fk_Post_User_Author foreign key ([AuthorId]) references [Users]([UserId]); alter table [Posts] add constraint fk_Post_Blog_Blog foreign key ([BlogId]) references [Blogs]([BlogId]); alter table [PostTags] add constraint fk_PostTag_Post_Post foreign key ([PostId]) references [Posts]([PostId]); alter table [PostTags] add constraint fk_PostTag_Tag_ElTag foreign key ([ElTagId]) references [Tags]([TagId]); alter table [ThingThatReferencesOrderNullables] add constraint fk_ThingThatReferencesOrderNullable_Order_Order foreign key ([OrderId]) references [Orders]([OrderId]); alter table [ReferencesThingWithNullables] add constraint fk_ReferencesThingWithNullable_ThingWithNullable_Thing foreign key ([ThingId]) references [ThingWithNullables]([Id]); create index [idx_Blog_Owner] on [Blogs] ([OwnerId]); create index [idx_Comment_Post] on [Comments] ([PostId]); create index [idx_Comment_User] on [Comments] ([UserId]); create index [idx_Like_User] on [Likes] ([UserId]); create index [idx_Like_Comment] on [Likes] ([CommentId]); create index [idx_LineItem_Order] on [LineItems] ([OrderId]); create index [idx_OneToOneLeft_Right] on [OneToOneLefts] ([RightId]); create index [idx_OneToOneRight_Left] on [OneToOneRights] ([LeftId]); create index [idx_Order_Delivery] on [Orders] ([DeliveryId]); create index [idx_Order_Customer] on [Orders] ([CustomerId]); create index [idx_Pair_References] on [Pairs] ([ReferencesId]); create index [idx_Pair_ReferencedBy] on [Pairs] ([ReferencedById]); create index [idx_Post_Author] on [Posts] ([AuthorId]); create index [idx_Post_Blog] on [Posts] ([BlogId]); create index [idx_PostTag_Post] on [PostTags] ([PostId]); create index [idx_PostTag_ElTag] on [PostTags] ([ElTagId]); create index [idx_ThingThatReferencesOrderNullable_Order] on [ThingThatReferencesOrderNullables] ([OrderId]); create index [idx_ReferencesThingWithNullable_Thing] on [ReferencesThingWithNullables] ([ThingId]);", @"(?<!\r)\n", Environment.NewLine), script.Trim()); }