Esempio n. 1
0
        public void TestSqlStatementBuilderCreateUpdateWithUncoveredWhereExpressionButWithCoveredIdentity()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");

            var where = new QueryGroup(new QueryField("Id", 1));
            var field = new DbField("Field1", true, true, false, typeof(int), null, null, null);

            // Act
            var actual = statementBuilder.CreateUpdate(queryBuilder: queryBuilder,
                                                       tableName: tableName,
                                                       fields: fields,
                                                       where : where,
                                                       primaryField: null,
                                                       identityField: field);
            var expected = $"" +
                           $"UPDATE [Table] " +
                           $"SET [Field2] = @Field2, [Field3] = @Field3 " +
                           $"WHERE ([Id] = @_Id) ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void TestSqlStatementBuilderCreateUpdateWithWhereExpression()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");

            var where = new QueryGroup(new QueryField("Field1", 1));

            // Act
            var actual = statementBuilder.CreateUpdate(queryBuilder: queryBuilder,
                                                       tableName: tableName,
                                                       fields: fields,
                                                       where : where,
                                                       primaryField: null,
                                                       identityField: null);
            var expected = $"" +
                           $"UPDATE [Table] " +
                           $"SET [Field1] = @Field1, [Field2] = @Field2, [Field3] = @Field3 " +
                           $"WHERE ([Field1] = @_Field1) ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        public void ThrowExceptionOnSqlDbProviderCreateUpdateIfTheIdentityFieldIsNotThePrimaryField()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionOnSqlDbProviderCreateUpdateIfTheIdentityFieldIsNotThePrimaryFieldClass>();
            var queryGroup       = (QueryGroup)null;

            // Act/Assert
            statementBuilder.CreateUpdate(queryBuilder, queryGroup);
        }
Esempio n. 4
0
        public void ThrowExceptionOnSqlStatementBuilderCreateUpdateIfTheTableIsWhitespace()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = " ";
            var fields           = Field.From("Field1", "Field2", "Field3");

            // Act
            statementBuilder.CreateUpdate(queryBuilder: queryBuilder,
                                          tableName: tableName,
                                          fields: fields,
                                          where : null,
                                          primaryField: null,
                                          identityField: null);
        }
Esempio n. 5
0
        public void TestSqlDbProviderCreateUpdateWithFieldMapping()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestSqlDbProviderCreateUpdateWithFieldMappingClass>();
            var queryGroup       = (QueryGroup)null;

            // Act
            var actual   = statementBuilder.CreateUpdate(queryBuilder, queryGroup);
            var expected = $"" +
                           $"UPDATE [TestSqlDbProviderCreateUpdateWithFieldMappingClass] " +
                           $"SET [Field1] = @Field1, [Field2] = @Field2, [Field4] = @Field4 ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        public void TestWithClassMappings()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithClassMappingsClass>();
            var queryGroup       = (QueryGroup)null;

            // Act
            var actual   = statementBuilder.CreateUpdate(queryBuilder, queryGroup);
            var expected = $"" +
                           $"UPDATE [ClassName] " +
                           $"SET [Field1] = @Field1, [Field2] = @Field2, [Field3] = @Field3 ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 7
0
        public void ThrowExceptionOnSqlStatementBuilderCreateUpdateIfThePrimaryIsNotReallyAPrimary()
        {
            // 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.CreateUpdate(queryBuilder: queryBuilder,
                                          tableName: tableName,
                                          fields: fields,
                                          where : null,
                                          primaryField: primaryField,
                                          identityField: null);
        }
Esempio n. 8
0
        public void TestWithExpression()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithExpressionClass>();
            var queryGroup       = QueryGroup.Parse(new { Field1 = 1, Field4 = new { Operation = Operation.GreaterThan, Value = 2 } });

            // Act
            var actual   = statementBuilder.CreateUpdate(queryBuilder, queryGroup);
            var expected = $"" +
                           $"UPDATE [TestWithExpressionClass] " +
                           $"SET [Field2] = @Field2, [Field3] = @Field3 " +
                           $"WHERE ([Field1] = @_Field1 AND [Field4] > @_Field4) ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 9
0
        public void TestSqlStatementBuilderCreateUpdateWithUnquotedTableSchema()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "dbo.Table";
            var fields           = Field.From("Field1", "Field2", "Field3");

            var where = (QueryGroup)null;

            // Act
            var actual = statementBuilder.CreateUpdate(queryBuilder: queryBuilder,
                                                       tableName: tableName,
                                                       fields: fields,
                                                       where : where,
                                                       primaryField: null,
                                                       identityField: null);
            var expected = $"" +
                           $"UPDATE [dbo].[Table] " +
                           $"SET [Field1] = @Field1, [Field2] = @Field2, [Field3] = @Field3 ;";

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