You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This constructs a `DbContext` using the options builder (which is pre-configured to connect to the template database) and then applies all pending migrations. After this point the template database has the full schema and is ready to be cloned for individual tests.
79
+
80
+
81
+
## Testing a specific migration
82
+
83
+
To test a single migration in isolation, build the template up to the migration _before_ the one under test using `IMigrator.MigrateAsync("targetMigration")`. Each test then receives a clone at that point and can apply the next migration independently.
<sup><ahref='/src/EfLocalDb.Tests/Snippets/TestSpecificMigration.cs#L5-L18'title='Snippet source file'>snippet source</a> | <ahref='#snippet-MigrateToSpecificTarget'title='Start of snippet'>anchor</a></sup>
102
+
<!-- endSnippet -->
103
+
104
+
This uses `IMigrator` (resolved from the EF Core service provider) instead of `Database.MigrateAsync()` so a target migration name can be specified. The template is frozen at that point and cloned for every test.
<sup><ahref='/src/EfLocalDb.Tests/Snippets/TestSpecificMigration.cs#L20-L45'title='Snippet source file'>snippet source</a> | <ahref='#snippet-TestSingleMigration'title='Start of snippet'>anchor</a></sup>
135
+
<!-- endSnippet -->
136
+
137
+
Each test gets its own database clone at the earlier migration state. It then applies the target migration and verifies the expected schema change. Because every test starts from the same cloned template, migrations under test are fully isolated from each other.
Copy file name to clipboardExpand all lines: pages/mdsource/efmigrations.source.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,4 +39,21 @@ Perform a [Runtime apply of migrations](https://docs.microsoft.com/en-us/ef/core
39
39
40
40
snippet: Migrate
41
41
42
-
This constructs a `DbContext` using the options builder (which is pre-configured to connect to the template database) and then applies all pending migrations. After this point the template database has the full schema and is ready to be cloned for individual tests.
42
+
This constructs a `DbContext` using the options builder (which is pre-configured to connect to the template database) and then applies all pending migrations. After this point the template database has the full schema and is ready to be cloned for individual tests.
43
+
44
+
45
+
## Testing a specific migration
46
+
47
+
To test a single migration in isolation, build the template up to the migration _before_ the one under test using `IMigrator.MigrateAsync("targetMigration")`. Each test then receives a clone at that point and can apply the next migration independently.
48
+
49
+
### Build the template to a known migration
50
+
51
+
snippet: MigrateToSpecificTarget
52
+
53
+
This uses `IMigrator` (resolved from the EF Core service provider) instead of `Database.MigrateAsync()` so a target migration name can be specified. The template is frozen at that point and cloned for every test.
54
+
55
+
### Apply and verify the next migration
56
+
57
+
snippet: TestSingleMigration
58
+
59
+
Each test gets its own database clone at the earlier migration state. It then applies the target migration and verifies the expected schema change. Because every test starts from the same cloned template, migrations under test are fully isolated from each other.
0 commit comments