Skip to content

Commit

Permalink
Fixes to TwoDatabasesTest
Browse files Browse the repository at this point in the history
Capture connection strings including security info before it's gone
(Persist Security Info=false)
  • Loading branch information
roji committed Jan 26, 2020
1 parent 3561e90 commit 973b1ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
17 changes: 11 additions & 6 deletions test/EFCore.Relational.Specification.Tests/TwoDatabasesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,28 @@ protected TwoDatabasesTestBase(FixtureBase fixture)
}

[ConditionalFact]
public void Can_query_from_one_connection_string_and_save_changes_to_another()
public virtual void Can_query_from_one_connection_string_and_save_changes_to_another()
{
using var context1 = CreateBackingContext("TwoDatabasesOne");
using var context2 = CreateBackingContext("TwoDatabasesTwo");

var connectionString1 = context1.Database.GetConnectionString();
var connectionString2 = context2.Database.GetConnectionString();

Assert.NotEqual(context1.Database.GetConnectionString(), context2.Database.GetConnectionString());

context1.Database.EnsureCreatedResiliently();
context2.Database.EnsureCreatedResiliently();

using (var context = new TwoDatabasesContext(CreateTestOptions(new DbContextOptionsBuilder()).Options))
{
context.Database.SetConnectionString(context1.Database.GetConnectionString());
context.Database.SetConnectionString(connectionString1);

var data = context.Foos.ToList();
data[0].Bar = "Modified One";
data[1].Bar = "Modified Two";

context.Database.SetConnectionString(context2.Database.GetConnectionString());
context.Database.SetConnectionString(connectionString2);

context.SaveChanges();
}
Expand All @@ -48,7 +51,7 @@ public void Can_query_from_one_connection_string_and_save_changes_to_another()
}

[ConditionalFact]
public void Can_query_from_one_connection_and_save_changes_to_another()
public virtual void Can_query_from_one_connection_and_save_changes_to_another()
{
using var context1 = CreateBackingContext("TwoDatabasesOneB");
using var context2 = CreateBackingContext("TwoDatabasesTwoB");
Expand Down Expand Up @@ -76,16 +79,18 @@ public void Can_query_from_one_connection_and_save_changes_to_another()
}

[ConditionalFact]
public void Can_set_connection_string_in_interceptor()
public virtual void Can_set_connection_string_in_interceptor()
{
using var context1 = CreateBackingContext("TwoDatabasesIntercept");

var connectionString1 = context1.Database.GetConnectionString();

context1.Database.EnsureCreatedResiliently();

using (var context = new TwoDatabasesContext(
CreateTestOptions(new DbContextOptionsBuilder(), withConnectionString: true)
.AddInterceptors(new ConnectionStringConnectionInterceptor(
context1.Database.GetConnectionString(), DummyConnectionString))
connectionString1, DummyConnectionString))
.Options))
{
var data = context.Foos.ToList();
Expand Down
30 changes: 15 additions & 15 deletions test/EFCore.Specification.Tests/MusicStoreTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected MusicStoreTestBase(TFixture fixture)
}

[ConditionalFact]
public async Task Browse_ReturnsViewWithGenre()
public virtual async Task Browse_ReturnsViewWithGenre()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand All @@ -44,7 +44,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task Index_CreatesViewWithGenres()
public virtual async Task Index_CreatesViewWithGenres()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand All @@ -64,7 +64,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task Details_ReturnsAlbumDetail()
public virtual async Task Details_ReturnsAlbumDetail()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand Down Expand Up @@ -110,7 +110,7 @@ private static Genre[] CreateTestGenres(int numberOfGenres, int numberOfAlbums,
}

[ConditionalFact]
public async Task Index_GetsSixTopAlbums()
public virtual async Task Index_GetsSixTopAlbums()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand Down Expand Up @@ -162,7 +162,7 @@ public static Album[] GetAlbums()
}

[ConditionalFact]
public async Task GenreMenuComponent_Returns_NineGenres()
public virtual async Task GenreMenuComponent_Returns_NineGenres()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand All @@ -186,7 +186,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task AddressAndPayment_RedirectToCompleteWhenSuccessful()
public virtual async Task AddressAndPayment_RedirectToCompleteWhenSuccessful()
{
const string cartId = "CartId_A";

Expand Down Expand Up @@ -215,7 +215,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task AddressAndPayment_ReturnsOrderIfInvalidPromoCode()
public virtual async Task AddressAndPayment_ReturnsOrderIfInvalidPromoCode()
{
const string cartId = "CartId_A";

Expand Down Expand Up @@ -251,7 +251,7 @@ protected Order CreateOrder(string userName = "RainbowDash")
};

[ConditionalFact]
public async Task Complete_ReturnsOrderIdIfValid()
public virtual async Task Complete_ReturnsOrderIdIfValid()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand All @@ -272,7 +272,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task Complete_ReturnsErrorIfInvalidOrder()
public virtual async Task Complete_ReturnsErrorIfInvalidOrder()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand All @@ -290,7 +290,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task CartSummaryComponent_returns_items()
public virtual async Task CartSummaryComponent_returns_items()
{
const string cartId = "CartId_A";
const string albumTitle = "Good goat, M.A.A.D Village";
Expand Down Expand Up @@ -330,7 +330,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async void Music_store_project_to_mapped_entity()
public virtual async void Music_store_project_to_mapped_entity()
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand Down Expand Up @@ -368,7 +368,7 @@ join artist in context.Artists on album.ArtistId equals artist.ArtistId
}

[ConditionalFact]
public async Task RemoveFromCart_removes_items_from_cart()
public virtual async Task RemoveFromCart_removes_items_from_cart()
{
const string cartId = "CartId_A";
const int numberOfItems = 5;
Expand Down Expand Up @@ -403,7 +403,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
[ConditionalTheory]
[InlineData(null)]
[InlineData("CartId_A")]
public async Task Cart_is_empty_when_no_items_have_been_added(string cartId)
public virtual async Task Cart_is_empty_when_no_items_have_been_added(string cartId)
{
using var context = CreateContext();
await context.Database.CreateExecutionStrategy().ExecuteAsync(
Expand All @@ -421,7 +421,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task Cart_has_items_once_they_have_been_added()
public virtual async Task Cart_has_items_once_they_have_been_added()
{
const string cartId = "CartId_A";

Expand Down Expand Up @@ -450,7 +450,7 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync(
}

[ConditionalFact]
public async Task Can_add_items_to_cart()
public virtual async Task Can_add_items_to_cart()
{
const string cartId = "CartId_A";

Expand Down

0 comments on commit 973b1ea

Please sign in to comment.