Esempio n. 1
0
        public void TestSqlStatementBuilderCreateInsertAllWithPrimary()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");
            var primaryField     = new DbField("Field1", true, false, false, typeof(int), null, null, null);

            // Act
            var actual = statementBuilder.CreateInsertAll(queryBuilder: queryBuilder,
                                                          tableName: tableName,
                                                          fields: fields,
                                                          batchSize: 1,
                                                          primaryField: primaryField,
                                                          identityField: null);
            var expected = $"" +
                           $"INSERT INTO [Table] " +
                           $"( [Field1], [Field2], [Field3] ) " +
                           $"VALUES " +
                           $"( @Field1, @Field2, @Field3 ) ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void TestSqlStatementBuilderCreateInsertAllWithIdentityAsBigInt()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");
            var identityField    = new DbField("Field1", false, true, false, typeof(long), null, null, null);

            // Act
            var actual = statementBuilder.CreateInsertAll(queryBuilder: queryBuilder,
                                                          tableName: tableName,
                                                          fields: fields,
                                                          batchSize: 1,
                                                          primaryField: null,
                                                          identityField: identityField);
            var expected = $"" +
                           $"INSERT INTO [Table] " +
                           $"( [Field2], [Field3] ) " +
                           $"VALUES " +
                           $"( @Field2, @Field3 ) ; " +
                           $"SET @Field1 = CONVERT(BIGINT, SCOPE_IDENTITY()) ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        public void ThrowExceptionOnSqlStatementBuilderCreateInsertAllIfTheTableIsWhitespace()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = " ";

            // Act
            statementBuilder.CreateInsertAll(queryBuilder: queryBuilder,
                                             tableName: tableName,
                                             fields: null,
                                             batchSize: 1,
                                             primaryField: null,
                                             identityField: null);
        }
Esempio n. 4
0
        public void ThrowExceptionOnSqlStatementBuilderCreateInsertAllIfThePrimaryIsNotReallyAPrimary()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");
            var primaryField     = new DbField("Field1", false, false, false, typeof(int), null, null, null);

            // Act
            statementBuilder.CreateInsertAll(queryBuilder: queryBuilder,
                                             tableName: tableName,
                                             fields: fields,
                                             batchSize: 1,
                                             primaryField: primaryField,
                                             identityField: null);
        }
Esempio n. 5
0
        public void TestSqlStatementBuilderCreateInsertAllWithUnquotedTableSchema()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "dbo.Table";
            var fields           = Field.From("Field1", "Field2", "Field3");

            // Act
            var actual = statementBuilder.CreateInsertAll(queryBuilder: queryBuilder,
                                                          tableName: tableName,
                                                          fields: fields,
                                                          batchSize: 1,
                                                          primaryField: null,
                                                          identityField: null);
            var expected = $"" +
                           $"INSERT INTO [dbo].[Table] " +
                           $"( [Field1], [Field2], [Field3] ) " +
                           $"VALUES " +
                           $"( @Field1, @Field2, @Field3 ) ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }