Exemplo n.º 1
0
        public void TestSqlStatementBuilderCreateUpdateAllWithCoveredPrimaryField()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);
            var field            = new DbField("Field1", true, true, false, typeof(int), null, null, null, null, Helper.DbSetting);

            // 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);
        }
Exemplo n.º 2
0
        public void TestSqlStatementBuilderCreateUpdateAllWithUnquotedTableSchema()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "dbo.Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);
            var qualifiers       = Field.From("Field1", Helper.DbSetting);

            // 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);
        }
Exemplo n.º 3
0
        public void TestSqlStatementBuilderCreateUpdateAllForThreeBatches()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            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);
        }
Exemplo n.º 4
0
        public void ThrowExceptionOnSqlStatementBuilderCreateUpdateAllIfThereAreNoQualifiers()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);

            // Act
            statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder,
                                             tableName: tableName,
                                             fields: fields,
                                             qualifiers: null,
                                             batchSize: 1,
                                             primaryField: null,
                                             identityField: null);
        }
Exemplo n.º 5
0
        public void ThrowExceptionOnSqlStatementBuilderCreateUpdateAllIfAnyOfTheQualifierIsNotCovered()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");
            var qualifiers       = Field.From("Id");

            // Act
            statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder,
                                             tableName: tableName,
                                             fields: fields,
                                             qualifiers: qualifiers,
                                             batchSize: 1,
                                             primaryField: null,
                                             identityField: null);
        }
Exemplo n.º 6
0
        public void ThrowExceptionOnSqlStatementBuilderCreateUpdateAllIfTheIdentityIsNotReallyAnIdentity()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);
            var qualifiers       = Field.From("Field1", Helper.DbSetting);
            var identifyField    = new DbField("Field2", false, false, false, typeof(int), null, null, null, null, Helper.DbSetting);

            // Act
            statementBuilder.CreateUpdateAll(queryBuilder: queryBuilder,
                                             tableName: tableName,
                                             fields: fields,
                                             qualifiers: qualifiers,
                                             batchSize: 1,
                                             primaryField: null,
                                             identityField: identifyField);
        }