Beispiel #1
0
        public void TestSqlStatementBuilderCreateInsertWithPrimaryAndIdentityAsBigInt()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            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);
            var identityField    = new DbField("Field2", false, true, false, typeof(long), null, null, null);

            // Act
            var actual = statementBuilder.CreateInsert(queryBuilder: queryBuilder,
                                                       tableName: tableName,
                                                       fields: fields,
                                                       primaryField: null,
                                                       identityField: identityField);
            var expected = $"" +
                           $"INSERT INTO [Table] " +
                           $"( [Field1], [Field3] ) " +
                           $"VALUES " +
                           $"( @Field1, @Field3 ) ; " +
                           $"SELECT CONVERT(BIGINT, SCOPE_IDENTITY()) AS [Result] ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void TestSqlStatementBuilderCreateInsertWithPrimary()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);
            var primaryField     = new DbField("Field1", true, false, false, typeof(int), null, null, null, null, Helper.DbSetting);

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void ThrowExceptionOnSqlStatementBuilderCreateInsertIfTheTableIsWhitespace()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = " ";

            // Act
            statementBuilder.CreateInsert(queryBuilder: queryBuilder,
                                          tableName: tableName,
                                          fields: null,
                                          primaryField: null,
                                          identityField: null);
        }
Beispiel #4
0
        public void ThrowExceptionOnSqlStatementBuilderCreateInsertIfThePrimaryIsNotReallyAPrimary()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);
            var primaryField     = new DbField("Field1", false, false, false, typeof(int), null, null, null, null, Helper.DbSetting);

            // Act
            statementBuilder.CreateInsert(queryBuilder: queryBuilder,
                                          tableName: tableName,
                                          fields: fields,
                                          primaryField: primaryField,
                                          identityField: null);
        }
Beispiel #5
0
        public void ThrowExceptionOnSqlStatementBuilderCreateInsertIfTheNonIdentityPrimaryIsNotCovered()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");
            var primaryField     = new DbField("Id", true, false, false, typeof(int), null, null, null);

            // Act
            statementBuilder.CreateInsert(queryBuilder: queryBuilder,
                                          tableName: tableName,
                                          fields: fields,
                                          primaryField: primaryField,
                                          identityField: null);
        }
Beispiel #6
0
        public void ThrowExceptionOnSqlStatementBuilderCreateInsertIfTheIdentityIsNotReallyAnIdentity()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            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.CreateInsert(queryBuilder: queryBuilder,
                                          tableName: tableName,
                                          fields: fields,
                                          primaryField: null,
                                          identityField: identifyField);
        }
Beispiel #7
0
        public void TestSqlStatementBuilderCreateInsertWithUnquotedTableSchema()
        {
            // Setup
            var statementBuilder = new SqlServerStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "dbo.Table";
            var fields           = Field.From(new[] { "Field1", "Field2", "Field3" }, Helper.DbSetting);

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

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