public void ThrowExceptionOnSqlDbProviderCreateMergeIfAtleastOneQualifierFieldIsMissingFromDataEntity()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionOnSqlDbProviderCreateMergeIfAtleastOneQualifierFieldIsMissingFromDataEntityClass>();
            var qualifiers       = Field.From("Field1", "Field4");

            // Act/Assert
            statementBuilder.CreateMerge(queryBuilder, qualifiers);
        }
示例#2
0
        public void ThrowExceptionOnSqlStatementBuilderCreateMergeIfThereAreNoPrimaryAndNoQualifiers()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = "Table";
            var fields           = Field.From("Field1", "Field2", "Field3");

            // Act
            statementBuilder.CreateMerge(queryBuilder: queryBuilder,
                                         tableName: tableName,
                                         fields: fields,
                                         qualifiers: null,
                                         primaryField: null,
                                         identityField: null);
        }
示例#3
0
        public void ThrowExceptionOnSqlStatementBuilderCreateMergeIfThePrimaryIsNotReallyAPrimary()
        {
            // 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.CreateMerge(queryBuilder: queryBuilder,
                                         tableName: tableName,
                                         fields: fields,
                                         qualifiers: null,
                                         primaryField: primaryField,
                                         identityField: null);
        }
示例#4
0
        public void ThrowExceptionOnSqlStatementBuilderCreateMergeIfTheTableIsNull()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder();
            var tableName        = (string)null;
            var fields           = Field.From("Field1", "Field2", "Field3");
            var qualifiers       = Field.From("Field1");

            // Act
            statementBuilder.CreateMerge(queryBuilder: queryBuilder,
                                         tableName: tableName,
                                         fields: fields,
                                         qualifiers: qualifiers,
                                         primaryField: null,
                                         identityField: null);
        }
示例#5
0
        public void TestWithClassMappings()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithClassMappingsClass>();
            var qualifiers       = Field.From("Field1");

            // Act
            var actual   = statementBuilder.CreateMerge(queryBuilder, qualifiers);
            var expected = $"" +
                           $"MERGE [ClassName] AS T " +
                           $"USING ( SELECT @Field1 AS [Field1], @Field2 AS [Field2], @Field3 AS [Field3] ) " +
                           $"AS S ON ( S.[Field1] = T.[Field1] ) " +
                           $"WHEN NOT MATCHED THEN " +
                           $"INSERT ( [Field1], [Field2], [Field3] ) " +
                           $"VALUES ( S.[Field1], S.[Field2], S.[Field3] ) " +
                           $"WHEN MATCHED THEN " +
                           $"UPDATE SET [Field2] = S.[Field2], [Field3] = S.[Field3] ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#6
0
        public void TestWithClassId()
        {
            // Setup
            var statementBuilder = new SqlStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithClassIdClass>();
            var qualifiers       = (IEnumerable <Field>)null;

            // Act
            var actual   = statementBuilder.CreateMerge(queryBuilder, qualifiers);
            var expected = $"" +
                           $"MERGE [TestWithClassIdClass] AS T " +
                           $"USING ( SELECT @TestWithClassIdClassId AS [TestWithClassIdClassId], @Field2 AS [Field2], @Field3 AS [Field3] ) " +
                           $"AS S ON ( S.[TestWithClassIdClassId] = T.[TestWithClassIdClassId] ) " +
                           $"WHEN NOT MATCHED THEN " +
                           $"INSERT ( [TestWithClassIdClassId], [Field2], [Field3] ) " +
                           $"VALUES ( S.[TestWithClassIdClassId], S.[Field2], S.[Field3] ) " +
                           $"WHEN MATCHED THEN " +
                           $"UPDATE SET [Field2] = S.[Field2], [Field3] = S.[Field3] ;";

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