Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SergerGood committed Mar 15, 2023
1 parent dee4d34 commit 7cfdd9c
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RepoDb.IntegrationTests.Setup;
using RepoDb.PostgreSql.BulkOperations.IntegrationTests.Models;
using System.Linq;
using System.Threading.Tasks;

namespace RepoDb.PostgreSql.BulkOperations.IntegrationTests.Operations
{
Expand Down Expand Up @@ -58,6 +59,31 @@ public void TestBinaryBulkDelete()
Assert.AreEqual(0, countResult);
}
}

[TestMethod]
public void TestBinaryBulkDeleteTableNameWithSchema()
{
using var connection = GetConnection();

// Prepare
var entities = Helper.CreateBulkOperationLightIdentityTables(10, true);
var tableName = "public.BulkOperationIdentityTable";

// Act
connection.BinaryBulkInsert(tableName,
entities: entities,
identityBehavior: BulkImportIdentityBehavior.KeepIdentity);

// Act
var result = connection.BinaryBulkDelete(tableName, entities);

// Assert
Assert.AreEqual(entities.Count, result);

// Assert
var countResult = connection.CountAll(tableName);
Assert.AreEqual(0, countResult);
}

[TestMethod]
public void TestBinaryBulkDeleteWithBatchSize()
Expand Down Expand Up @@ -1244,6 +1270,31 @@ public void TestBinaryBulkDeleteAsync()
Assert.AreEqual(0, countResult);
}
}

[TestMethod]
public async Task TestBinaryBulkDeleteAsyncTableNameWithSchema()
{
await using var connection = GetConnection();

// Prepare
var entities = Helper.CreateBulkOperationLightIdentityTables(10, true);
var tableName = "public.BulkOperationIdentityTable";

// Act
await connection.BinaryBulkInsertAsync(tableName,
entities: entities,
identityBehavior: BulkImportIdentityBehavior.KeepIdentity);

// Act
var result = await connection.BinaryBulkDeleteAsync(tableName, entities);

// Assert
Assert.AreEqual(entities.Count, result);

// Assert
var countResult = await connection.CountAllAsync(tableName);
Assert.AreEqual(0, countResult);
}

[TestMethod]
public void TestBinaryBulkDeleteAsyncWithBatchSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Data;
using System.Linq;
using System.Threading.Tasks;

namespace RepoDb.PostgreSql.BulkOperations.IntegrationTests.Operations
{
Expand Down Expand Up @@ -55,6 +56,27 @@ public void TestBinaryBulkInsert()
Assert.AreEqual(entities.Count(), assertCount);
}
}

[TestMethod]
public void TestBinaryBulkInsertTableNameWithSchema()
{
using var connection = GetConnection();

// Prepare
var entities = Helper.CreateBulkOperationLightIdentityTables(10, false);
var tableName = "public.BulkOperationIdentityTable";

// Act
var result = connection.BinaryBulkInsert(tableName, entities);

// Assert
Assert.AreEqual(entities.Count, result);

// Assert
var queryResult = connection.QueryAll<BulkOperationLightIdentityTable>(tableName).ToList();
var assertCount = Helper.AssertEntitiesEquality(entities, queryResult, (t1, t2) => entities.IndexOf(t1) == queryResult.IndexOf(t2));
Assert.AreEqual(entities.Count, assertCount);
}

[TestMethod]
public void TestBinaryBulkInsertWithIdentityValues()
Expand Down Expand Up @@ -2023,6 +2045,27 @@ public void TestBinaryBulkInsertAsync()
}
}

[TestMethod]
public async Task TestBinaryBulkInsertAsyncTableNameWithSchema()
{
await using var connection = GetConnection();

// Prepare
var entities = Helper.CreateBulkOperationLightIdentityTables(10, false);
var tableName = "public.BulkOperationIdentityTable";

// Act
var result = await connection.BinaryBulkInsertAsync(tableName, entities);

// Assert
Assert.AreEqual(entities.Count, result);

// Assert
var queryResult = connection.QueryAll<BulkOperationLightIdentityTable>(tableName).ToList();
var assertCount = Helper.AssertEntitiesEquality(entities, queryResult, (t1, t2) => entities.IndexOf(t1) == queryResult.IndexOf(t2));
Assert.AreEqual(entities.Count, assertCount);
}

[TestMethod]
public void TestBinaryBulkInsertAsyncWithIdentityValues()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Data;
using System.Linq;
using System.Threading.Tasks;

namespace RepoDb.PostgreSql.BulkOperations.IntegrationTests.Operations
{
Expand Down Expand Up @@ -55,6 +56,27 @@ public void TestBinaryBulkMerge()
Assert.AreEqual(entities.Count(), assertCount);
}
}

[TestMethod]
public void TestBinaryBulkMergeTableNameWithSchema()
{
using var connection = GetConnection();

// Prepare
var entities = Helper.CreateBulkOperationLightIdentityTables(10, false);
var tableName = "public.BulkOperationIdentityTable";

// Act
var result = connection.BinaryBulkMerge(tableName, entities);

// Assert
Assert.AreEqual(entities.Count, result);

// Assert
var queryResult = connection.QueryAll<BulkOperationLightIdentityTable>(tableName).ToList();
var assertCount = Helper.AssertEntitiesEquality(entities, queryResult, (t1, t2) => entities.IndexOf(t1) == queryResult.IndexOf(t2));
Assert.AreEqual(entities.Count, assertCount);
}

[TestMethod]
public void TestBinaryBulkMergeWithBatchSize()
Expand Down Expand Up @@ -2740,6 +2762,27 @@ public void TestBinaryBulkMergeAsync()
}
}

[TestMethod]
public async Task TestBinaryBulkMergeAsyncTableNameWithSchema()
{
await using var connection = GetConnection();

// Prepare
var entities = Helper.CreateBulkOperationLightIdentityTables(10, false);
var tableName = "public.BulkOperationIdentityTable";

// Act
var result = await connection.BinaryBulkMergeAsync(tableName, entities);

// Assert
Assert.AreEqual(entities.Count, result);

// Assert
var queryResult = connection.QueryAll<BulkOperationLightIdentityTable>(tableName).ToList();
var assertCount = Helper.AssertEntitiesEquality(entities, queryResult, (t1, t2) => entities.IndexOf(t1) == queryResult.IndexOf(t2));
Assert.AreEqual(entities.Count, assertCount);
}

[TestMethod]
public void TestBinaryBulkMergeAsyncWithBatchSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RepoDb.IntegrationTests.Setup;
using RepoDb.PostgreSql.BulkOperations.IntegrationTests.Models;
using System.Linq;
using System.Threading.Tasks;

namespace RepoDb.PostgreSql.BulkOperations.IntegrationTests.Operations
{
Expand Down Expand Up @@ -63,6 +64,37 @@ public void TestBinaryBulkUpdate()
Assert.AreEqual(entities.Count(), assertCount);
}
}

[TestMethod]
public void TestBinaryBulkUpdateTableNameWithSchema()
{
using var connection = GetConnection();

// Prepare
var createdEntities = Helper.CreateBulkOperationLightIdentityTables(10, true);
var tableName = "public.BulkOperationIdentityTable";

// Act
connection.BinaryBulkInsert(tableName,
entities: createdEntities,
identityBehavior: BulkImportIdentityBehavior.KeepIdentity);

// Prepare
var updatedEntities = Helper.UpdateBulkOperationLightIdentityTables(createdEntities);

// Act
var result = connection.BinaryBulkUpdate(tableName, updatedEntities);

// Assert
Assert.AreEqual(updatedEntities.Count, result);

// Assert
var queryResult = connection.QueryAll<BulkOperationLightIdentityTable>(tableName).ToList();
Assert.AreEqual(10, queryResult.Count);

var assertCount = Helper.AssertEntitiesEquality(updatedEntities, queryResult, (t1, t2) => t1.Id == t2.Id, false);
Assert.AreEqual(expected: updatedEntities.Count, assertCount);
}

[TestMethod]
public void TestBinaryBulkUpdateWithBatchSize()
Expand Down Expand Up @@ -1694,6 +1726,37 @@ public void TestBinaryBulkUpdateAsync()
Assert.AreEqual(entities.Count(), assertCount);
}
}

[TestMethod]
public async Task TestBinaryBulkUpdateAsyncTableNameWithSchema()
{
await using var connection = GetConnection();

// Prepare
var createdEntities = Helper.CreateBulkOperationLightIdentityTables(10, true);
var tableName = "public.BulkOperationIdentityTable";

// Act
await connection.BinaryBulkInsertAsync(tableName,
entities: createdEntities,
identityBehavior: BulkImportIdentityBehavior.KeepIdentity);

// Prepare
var updatedEntities = Helper.UpdateBulkOperationLightIdentityTables(createdEntities);

// Act
var result = await connection.BinaryBulkUpdateAsync(tableName, updatedEntities);

// Assert
Assert.AreEqual(updatedEntities.Count, result);

// Assert
var queryResult = connection.QueryAll<BulkOperationLightIdentityTable>(tableName).ToList();
Assert.AreEqual(10, queryResult.Count);

var assertCount = Helper.AssertEntitiesEquality(updatedEntities, queryResult, (t1, t2) => t1.Id == t2.Id, false);
Assert.AreEqual(expected: updatedEntities.Count, assertCount);
}

[TestMethod]
public void TestBinaryBulkUpdateAsyncWithBatchSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ private static string GetDeleteByKeyCommandText(string sourceTableName,
/// <returns></returns>
private static string GetBinaryBulkInsertPseudoTableName(string tableName,
IDbSetting dbSetting) =>
$"_RepoDb_BinaryBulkInsert_{tableName.AsUnquoted(true, dbSetting)}";
$"_RepoDb_BinaryBulkInsert_{tableName.AsUnquoted(true, dbSetting).AsAlphaNumeric()}";

/// <summary>
///
Expand All @@ -1172,7 +1172,7 @@ private static string GetBinaryBulkInsertPseudoTableName(string tableName,
/// <returns></returns>
private static string GetBinaryBulkMergePseudoTableName(string tableName,
IDbSetting dbSetting) =>
$"_RepoDb_BinaryBulkMerge_{tableName.AsUnquoted(true, dbSetting)}";
$"_RepoDb_BinaryBulkMerge_{tableName.AsUnquoted(true, dbSetting).AsAlphaNumeric()}";

/// <summary>
///
Expand All @@ -1182,7 +1182,7 @@ private static string GetBinaryBulkMergePseudoTableName(string tableName,
/// <returns></returns>
private static string GetBinaryBulkUpdatePseudoTableName(string tableName,
IDbSetting dbSetting) =>
$"_RepoDb_BinaryBulkUpdate_{tableName.AsUnquoted(true, dbSetting)}";
$"_RepoDb_BinaryBulkUpdate_{tableName.AsUnquoted(true, dbSetting).AsAlphaNumeric()}";

/// <summary>
///
Expand All @@ -1192,7 +1192,7 @@ private static string GetBinaryBulkUpdatePseudoTableName(string tableName,
/// <returns></returns>
private static string GetBinaryBulkDeletePseudoTableName(string tableName,
IDbSetting dbSetting) =>
$"_RepoDb_BinaryBulkDelete_{tableName.AsUnquoted(true, dbSetting)}";
$"_RepoDb_BinaryBulkDelete_{tableName.AsUnquoted(true, dbSetting).AsAlphaNumeric()}";

/// <summary>
///
Expand Down

0 comments on commit 7cfdd9c

Please sign in to comment.