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

Add failing test that exposes DbDataSource related bug. #3003

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions test/EFCore.PG.Tests/NpgsqlRelationalConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,46 @@ public void Uses_DbDataSource_from_application_service_provider()
Assert.Equal("Host=FakeHost", connection2.ConnectionString);
}

[Fact]
public void Uses_correct_DbDataSource_from_application_service_provider_with_cached_DbContextOptions_extension()
{
var serviceCollection1 = new ServiceCollection();

serviceCollection1
.AddNpgsqlDataSource("Host=FakeHost1")
.AddDbContext<FakeDbContext>(o => o.UseNpgsql());

using (var serviceProvider1 = serviceCollection1.BuildServiceProvider())
{
var dataSource1 = serviceProvider1.GetRequiredService<NpgsqlDataSource>();

Assert.Equal("Host=FakeHost1", dataSource1.ConnectionString);

var context1 = serviceProvider1.GetRequiredService<FakeDbContext>();
var relationalConnection1 = (NpgsqlRelationalConnection)context1.GetService<IRelationalConnection>()!;

Assert.Same(dataSource1, relationalConnection1.DbDataSource);
}

var serviceCollection2 = new ServiceCollection();

serviceCollection2
.AddNpgsqlDataSource("Host=FakeHost2")
.AddDbContext<FakeDbContext>(o => o.UseNpgsql());

using (var serviceProvider2 = serviceCollection2.BuildServiceProvider())
{
var dataSource2 = serviceProvider2.GetRequiredService<NpgsqlDataSource>();

Assert.Equal("Host=FakeHost2", dataSource2.ConnectionString);

var context2 = serviceProvider2.GetRequiredService<FakeDbContext>();
var relationalConnection2 = (NpgsqlRelationalConnection)context2.GetService<IRelationalConnection>()!;

Assert.Same(dataSource2, relationalConnection2.DbDataSource);
}
}

[Fact]
public void Can_create_master_connection_with_connection_string()
{
Expand Down