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); }
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); }
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); }
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); }
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); }
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); }