@@ -5,6 +5,21 @@ namespace SqlServerSimulator;
55[ TestClass ]
66public class EFCoreBasics
77{
8+ [ AssemblyInitialize ]
9+ public static async Task HotPath ( TestContext context )
10+ {
11+ if ( System . Diagnostics . Debugger . IsAttached )
12+ return ;
13+
14+ // Triggers JIT compilation of the most common path among all tests, improving the accuracy of their timings.
15+ // Also functions as a sanity check against the simulator being completely broken.
16+ using var dbContext = new TestDbContext ( ) ;
17+
18+ Assert . IsEmpty ( dbContext . Rows . Select ( x => x . Id ) . AsEnumerable ( ) ) ;
19+
20+ Assert . AreEqual ( 0 , await dbContext . SaveChangesAsync ( context . CancellationToken ) ) ;
21+ }
22+
823 public static Simulation CreateDefaultSimulation ( )
924 {
1025 var simulation = new Simulation ( ) ;
@@ -21,11 +36,11 @@ class TestRow
2136 public int Id { get ; set ; }
2237 }
2338
24- class TestContext ( Simulation simulation ) : DbContext
39+ class TestDbContext ( Simulation simulation ) : DbContext
2540 {
2641 public Simulation Simulation { get ; set ; } = simulation ;
2742
28- public TestContext ( )
43+ public TestDbContext ( )
2944 : this ( CreateDefaultSimulation ( ) )
3045 {
3146 }
@@ -41,7 +56,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
4156 [ TestMethod ]
4257 public void InsertRowSync ( )
4358 {
44- using var context = new TestContext ( ) ;
59+ using var context = new TestDbContext ( ) ;
4560
4661 var row = new TestRow { Id = 1 } ;
4762
@@ -57,7 +72,7 @@ public void InsertRowSync()
5772 [ TestMethod ]
5873 public async Task InsertRowAsync ( )
5974 {
60- await using var context = new TestContext ( ) ;
75+ await using var context = new TestDbContext ( ) ;
6176
6277 var row = new TestRow { Id = 1 } ;
6378
@@ -72,7 +87,7 @@ public void RoundTrip()
7287 var simulation = CreateDefaultSimulation ( ) ;
7388 const int storedValue = 3 ;
7489
75- using ( var context = new TestContext ( simulation ) )
90+ using ( var context = new TestDbContext ( simulation ) )
7691 {
7792 var row = new TestRow { Id = storedValue } ;
7893
@@ -81,7 +96,7 @@ public void RoundTrip()
8196 _ = context . SaveChanges ( ) ;
8297 }
8398
84- using ( var context = new TestContext ( simulation ) )
99+ using ( var context = new TestDbContext ( simulation ) )
85100 {
86101 var receivedValue = context . Rows . Select ( x => x . Id ) . AsEnumerable ( ) ;
87102
0 commit comments