Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add test case for insert with duplicate key conflict for npgsql + EF #208

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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