Skip to content

Commit

Permalink
Add npgsql + ef test case for duplicate key conflicts on insert
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Jan 18, 2022
1 parent 60213ef commit 96f2571
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions tests/client_tests/stock_npgsql/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,45 @@ static async Task Main(string[] args)
using (var conn = new NpgsqlConnection(connString)) {
conn.Open();

await TestBasics(conn);
await TestUnnestAsync(conn);
await TestInsertUsingEntityFramework(conn);
// await TestBasics(conn);
// await TestUnnestAsync(conn);
// await TestInsertUsingEntityFramework(conn);
await TestInsertWithDuplicateKeyConflict(conn);
}
}

private static async Task TestInsertWithDuplicateKeyConflict(NpgsqlConnection conn)
{
using (var cmd = new NpgsqlCommand("drop table if exists test.test", conn))
{
await cmd.ExecuteNonQueryAsync();
}
string createTable = @"
CREATE TABLE test.test (
id text default gen_random_text_uuid() primary key,
datetime timestamp with time zone
)";
using (var cmd = new NpgsqlCommand(createTable, conn))
{
await cmd.ExecuteNonQueryAsync();
}
CrateContext.ConnectionString = conn.ConnectionString;
var entries = new List<TestEntity>();
using (CrateContext context = new()) {
for (int i = 0; i < 4; i++)
{
var entry = new TestEntity();
context.Test.Add(entry);
entries.Add(entry);
}
await context.SaveChangesAsync();
}

using (CrateContext context = new()) {
foreach (var entry in entries) {
context.Test.Add(entry);
}
await context.SaveChangesAsync();
}
}

Expand Down

0 comments on commit 96f2571

Please sign in to comment.