public void TableThrowsArgumentExceptionForEmptyTableName() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var exception = Assert.Throws<ArgumentException>( () => sqlBuilder.Table("")); Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("tableName"), exception.Message); }
public void UpdateSpecifyingTypeWithSqlCharacters() { var sqlBuilder = new UpdateSqlBuilder(MsSqlCharacters.Instance); var sqlQuery = sqlBuilder .Table(typeof(Customer)) .ToSqlQuery(); Assert.Equal("UPDATE [Sales].[Customers] SET ", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void UpdateSpecifyingType() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table(typeof(Customer)) .ToSqlQuery(); Assert.Equal("UPDATE Sales.Customers SET ", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void UpdateSpecifyingTableNameWithSqlCharacters() { var sqlBuilder = new UpdateSqlBuilder(MsSqlCharacters.Instance); var sqlQuery = sqlBuilder .Table("Table") .ToSqlQuery(); Assert.Equal("UPDATE [Table] SET ", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void UpdateSpecifyingTableName() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table("Table") .ToSqlQuery(); Assert.Equal("UPDATE Table SET ", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void UpdateTableSetColumnValue() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .WhereEquals("Id", 100122) .ToSqlQuery(); Assert.Equal("UPDATE Table SET Column1 = ?,Column2 = ? WHERE Id = ?", sqlQuery.CommandText); Assert.Equal(3, sqlQuery.Arguments.Count); Assert.Equal("Foo", sqlQuery.Arguments[0]); Assert.Equal(12, sqlQuery.Arguments[1]); Assert.Equal(100122, sqlQuery.Arguments[2]); }
public void UpdateTableSetColumnValueWithSqlCharacters() { var sqlBuilder = new UpdateSqlBuilder(MsSqlCharacters.Instance); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .WhereEquals("Id", 100122) .ToSqlQuery(); Assert.Equal("UPDATE [Table] SET [Column1] = @p0,[Column2] = @p1 WHERE [Id] = @p2", sqlQuery.CommandText); Assert.Equal(3, sqlQuery.Arguments.Count); Assert.Equal("Foo", sqlQuery.Arguments[0]); Assert.Equal(12, sqlQuery.Arguments[1]); Assert.Equal(100122, sqlQuery.Arguments[2]); }
public void UpdateTableSetColumnValueWhereNotInSqlQuery() { var subQuery = new SqlQuery("SELECT Id FROM Table WHERE Column = ?", 1024); var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .Where("Column3").NotIn(subQuery) .ToSqlQuery(); Assert.Equal("UPDATE Table SET Column1 = ?,Column2 = ? WHERE (Column3 NOT IN (SELECT Id FROM Table WHERE Column = ?))", sqlQuery.CommandText); Assert.Equal(3, sqlQuery.Arguments.Count); Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType); Assert.Equal("Foo", sqlQuery.Arguments[0].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType); Assert.Equal(12, sqlQuery.Arguments[1].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType); Assert.Equal(1024, sqlQuery.Arguments[2].Value); }
public void UpdateTableSetColumnValueWhereNotInArgs() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .Where("Column3").NotIn(1, 2, 3) .ToSqlQuery(); Assert.Equal("UPDATE Table SET Column1 = ?,Column2 = ? WHERE (Column3 NOT IN (?,?,?))", sqlQuery.CommandText); Assert.Equal(5, sqlQuery.Arguments.Count); Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType); Assert.Equal("Foo", sqlQuery.Arguments[0].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType); Assert.Equal(12, sqlQuery.Arguments[1].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType); Assert.Equal(1, sqlQuery.Arguments[2].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[3].DbType); Assert.Equal(2, sqlQuery.Arguments[3].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[4].DbType); Assert.Equal(3, sqlQuery.Arguments[4].Value); }
public void UpdateTableSetColumnValueWhereNotBetween() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .Where("Id").NotBetween(1, 199) .ToSqlQuery(); Assert.Equal("UPDATE Table SET Column1 = ?,Column2 = ? WHERE (Id NOT BETWEEN ? AND ?)", sqlQuery.CommandText); Assert.Equal(4, sqlQuery.Arguments.Count); Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType); Assert.Equal("Foo", sqlQuery.Arguments[0].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType); Assert.Equal(12, sqlQuery.Arguments[1].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType); Assert.Equal(1, sqlQuery.Arguments[2].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[3].DbType); Assert.Equal(199, sqlQuery.Arguments[3].Value); }
public void UpdateTableSetColumnValueWhereIsNull() { var sqlBuilder = new UpdateSqlBuilder(SqlCharacters.Empty); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .Where("Id").IsNull() .ToSqlQuery(); Assert.Equal("UPDATE Table SET Column1 = ?,Column2 = ? WHERE (Id IS NULL)", sqlQuery.CommandText); Assert.Equal(2, sqlQuery.Arguments.Count); Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType); Assert.Equal("Foo", sqlQuery.Arguments[0].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType); Assert.Equal(12, sqlQuery.Arguments[1].Value); }
public void UpdateTableSetColumnValueWhereIsEqualToWithSqlCharacters() { var sqlBuilder = new UpdateSqlBuilder(MsSqlCharacters.Instance); var sqlQuery = sqlBuilder .Table("Table") .SetColumnValue("Column1", "Foo") .SetColumnValue("Column2", 12) .Where("Id").IsEqualTo(100122) .ToSqlQuery(); Assert.Equal("UPDATE [Table] SET [Column1] = @p0,[Column2] = @p1 WHERE ([Id] = @p2)", sqlQuery.CommandText); Assert.Equal(3, sqlQuery.Arguments.Count); Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType); Assert.Equal("Foo", sqlQuery.Arguments[0].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[1].DbType); Assert.Equal(12, sqlQuery.Arguments[1].Value); Assert.Equal(DbType.Int32, sqlQuery.Arguments[2].DbType); Assert.Equal(100122, sqlQuery.Arguments[2].Value); }