Skip to content

Commit

Permalink
[5.0.3/Tests only] Updates many-to-many change tracking tests to work…
Browse files Browse the repository at this point in the history
… with generated key values (#23807)

This is a precursor to fixes for #23659, #23787. This test has no product changes, it just refactors the many-to-many tests so that they can be run with generated key values, as well as running with explicit keys values like they currently do. Generated keys result in more work being done in fixup by navigations, which is where both of these issues live.

Once this is merged I will send out separate PRs to fix the two bugs.
  • Loading branch information
ajcvickers authored Jan 5, 2021
1 parent 0e91fa1 commit 6213a10
Show file tree
Hide file tree
Showing 6 changed files with 2,270 additions and 1,674 deletions.
1,866 changes: 1,275 additions & 591 deletions test/EFCore.Specification.Tests/ManyToManyTrackingTestBase.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ public abstract class ManyToManyQueryFixtureBase : SharedStoreFixtureBase<ManyTo
public Func<DbContext> GetContextCreator()
=> () => CreateContext();

private ManyToManyData _data;

public ISetSource GetExpectedData()
=> new ManyToManyData();
{
if (_data == null)
{
using var context = CreateContext();
_data = new ManyToManyData(context, false);
context.ChangeTracker.DetectChanges();
context.ChangeTracker.Clear();
}

return _data;
}

public IReadOnlyDictionary<Type, object> GetEntitySorters()
=> new Dictionary<Type, Func<object, object>>
Expand Down Expand Up @@ -329,7 +341,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
});
}

public virtual bool UseGeneratedKeys
=> false;

protected override void Seed(ManyToManyContext context)
=> ManyToManyContext.Seed(context);
{
new ManyToManyData(context, UseGeneratedKeys);
context.SaveChanges();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public ManyToManyContext(DbContextOptions options)
public DbSet<ImplicitManyToManyB> ImplicitManyToManyBs { get; set; }
public DbSet<GeneratedKeysLeft> GeneratedKeysLefts { get; set; }
public DbSet<GeneratedKeysRight> GeneratedKeysRights { get; set; }

public static void Seed(ManyToManyContext context)
=> ManyToManyData.Seed(context);
}

public static class ManyToManyContextExtensions
Expand Down
Loading

0 comments on commit 6213a10

Please sign in to comment.