public void TestSqlStatementBuilderCreateUpdateAllWithCoveredPrimaryField() { // Setup var statementBuilder = new SqlStatementBuilder(); var queryBuilder = new QueryBuilder(); var tableName = "Table"; var fields = Field.From("Field1", "Field2", "Field3"); var field = new DbField("Field1", true, true, false, typeof(int), null, null, null); // Act var actual = statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder, tableName: tableName, fields: fields, qualifiers: null, batchSize: 1, primaryField: field, identityField: null); var expected = $"" + $"UPDATE [Table] " + $"SET [Field2] = @Field2, [Field3] = @Field3 " + $"WHERE ([Field1] = @Field1) ;"; // Assert Assert.AreEqual(expected, actual); }
public void TestSqlStatementBuilderCreateUpdateAllWithUnquotedTableSchema() { // Setup var statementBuilder = new SqlStatementBuilder(); var queryBuilder = new QueryBuilder(); var tableName = "dbo.Table"; var fields = Field.From("Field1", "Field2", "Field3"); var qualifiers = Field.From("Field1"); // Act var actual = statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder, tableName: tableName, fields: fields, qualifiers: qualifiers, batchSize: 1, primaryField: null, identityField: null); var expected = $"" + $"UPDATE [dbo].[Table] " + $"SET [Field2] = @Field2, [Field3] = @Field3 " + $"WHERE ([Field1] = @Field1) ;"; // Assert Assert.AreEqual(expected, actual); }
public void TestSqlStatementBuilderCreateUpdateAllForThreeBatches() { // Setup var statementBuilder = new SqlStatementBuilder(); var queryBuilder = new QueryBuilder(); var tableName = "Table"; var fields = Field.From("Field1", "Field2", "Field3"); var qualifiers = Field.From("Field1"); // Act var actual = statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder, tableName: tableName, fields: fields, qualifiers: qualifiers, batchSize: 3, primaryField: null, identityField: null); var expected = $"" + $"UPDATE [Table] " + $"SET [Field2] = @Field2, [Field3] = @Field3 " + $"WHERE ([Field1] = @Field1) ; " + $"UPDATE [Table] " + $"SET [Field2] = @Field2_1, [Field3] = @Field3_1 " + $"WHERE ([Field1] = @Field1_1) ; " + $"UPDATE [Table] " + $"SET [Field2] = @Field2_2, [Field3] = @Field3_2 " + $"WHERE ([Field1] = @Field1_2) ;"; // Assert Assert.AreEqual(expected, actual); }
public void ThrowExceptionOnSqlStatementBuilderCreateUpdateAllIfThereAreNoQualifiers() { // Setup var statementBuilder = new SqlStatementBuilder(); var queryBuilder = new QueryBuilder(); var tableName = "Table"; var fields = Field.From("Field1", "Field2", "Field3"); // Act statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder, tableName: tableName, fields: fields, qualifiers: null, batchSize: 1, primaryField: null, identityField: null); }
public void ThrowExceptionOnSqlStatementBuilderCreateUpdateAllIfTheIdentityIsNotReallyAnIdentity() { // Setup var statementBuilder = new SqlStatementBuilder(); var queryBuilder = new QueryBuilder(); var tableName = "Table"; var fields = Field.From("Field1", "Field2", "Field3"); var qualifiers = Field.From("Field1"); var identifyField = new DbField("Field2", false, false, false, typeof(int), null, null, null); // Act statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder, tableName: tableName, fields: fields, qualifiers: qualifiers, batchSize: 1, primaryField: null, identityField: identifyField); }