示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }