public void BulkUpdateEmptyArray() { var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); var result = updateWriter.GenerateBulkSql <Post>(p => p.Title = "Foo", Enumerable.Empty <Expression <Func <Post, bool> > >()); this.outputHelper.WriteLine(result.Sql); Assert.Equal("update [Posts] set [Title] = @Title", result.Sql); }
public void BulkUpdateNull() { var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); var result = updateWriter.GenerateBulkSql <Post>(p => p.Title = "Foo", null); this.outputHelper.WriteLine(result.Sql); Assert.Equal("update [Posts] set [Title] = @Title", result.Sql); }
public void BulkUpdateIgnoresConstructorSetProperties() { // assemble var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); // act Expression <Func <ClassWithConstructor, bool> > predicate = p => p.Id == 1; var result = updateWriter.GenerateBulkSql(p => { }, new[] { predicate }); // assert Debug.Write(result.Sql); Assert.Equal(string.Empty, result.Sql); // Is this the correct result? }
public void BulkUpdateManyOneNullAddsNull() { // assemble var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); // act Expression <Func <Post, bool> > predicate = p => p.PostId == 1; var result = updateWriter.GenerateBulkSql(p => p.Blog = null, new[] { predicate }); // assert Debug.Write(result.Sql); Assert.Equal("update [Posts] set [BlogId] = @Blog where ([PostId] = @l_1)", result.Sql); // Is this the correct result? var param1 = result.Parameters.GetValueOfParameter("@Blog"); Assert.Null(param1); }
public void MultipleJoinFkWorks() { var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); // act var author = new User { UserId = 99 }; Expression <Func <Post, bool> > predicate = p => p.Blog.Owner == author; var result = updateWriter.GenerateBulkSql( p => p.Blog = new Blog { BlogId = 1 }, new[] { predicate }); // assert this.outputHelper.WriteLine(result.Sql); Assert.Equal("update t set t.[BlogId] = @Blog from [Posts] as t inner join [Blogs] as t_100 on t.BlogId = t_100.BlogId where (t_100.[OwnerId] = @l_1)", result.Sql); Assert.Equal(99, result.Parameters.Get <int>("l_1")); Assert.Equal(1, result.Parameters.Get <int>("Blog")); }
public void MultipleJoinWorks() { var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); // act Expression <Func <Post, bool> > predicate = p => p.Blog.Owner.EmailAddress.EndsWith("@acme.com"); var result = updateWriter.GenerateBulkSql( p => { p.Blog = new Blog { BlogId = 1 }; p.Rating = 5; }, new[] { predicate }); // assert this.outputHelper.WriteLine(result.Sql); Assert.Equal("update t set t.[Rating] = @Rating, t.[BlogId] = @Blog from [Posts] as t left join [Blogs] as t_100 on t.BlogId = t_100.BlogId left join [Users] as t_101 on t_100.OwnerId = t_101.UserId where t_101.[EmailAddress] like @l_1", result.Sql); Assert.Equal("*****@*****.**", result.Parameters.Get <string>("l_1")); Assert.Equal(1, result.Parameters.Get <int>("Blog")); Assert.Equal(5m, result.Parameters.Get <decimal>("Rating")); }
public void BulkUpdateManyToOnePropertyResolvesForeignKeyId() { // assemble var updateWriter = new BulkUpdateWriter(new SqlServerDialect(), MakeConfig()); // act Expression <Func <Post, bool> > predicate = p => p.PostId == 1; var result = updateWriter.GenerateBulkSql( p => p.Blog = new Blog { BlogId = 1 }, new[] { predicate }); // assert Debug.Write(result.Sql); Assert.Equal("update [Posts] set [BlogId] = @Blog where ([PostId] = @l_1)", result.Sql); // Is this the correct result? var param1 = result.Parameters.GetValueOfParameter("@Blog"); var param2 = result.Parameters.GetValueOfParameter("@l_1"); Assert.IsType <int>(param1); Assert.IsType <int>(param2); }