@@ -26,7 +26,7 @@ Enable VerifyEntityFramework once at assembly load time:
2626``` cs
2727VerifyEntityFramework .Enable ();
2828```
29- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L370-L374 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-enablecore ' title =' Start of snippet ' >anchor</a ></sup >
29+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L472-L476 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-enablecore ' title =' Start of snippet ' >anchor</a ></sup >
3030<!-- endSnippet -->
3131
3232
@@ -58,7 +58,7 @@ builder.UseSqlServer(connection);
5858builder .EnableRecording ();
5959var data = new SampleDbContext (builder .Options );
6060```
61- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L230-L237 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-enablerecording ' title =' Start of snippet ' >anchor</a ></sup >
61+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L239-L246 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-enablerecording ' title =' Start of snippet ' >anchor</a ></sup >
6262<!-- endSnippet -->
6363
6464` EnableRecording ` should only be called in the test context.
@@ -86,7 +86,7 @@ await data.Companies
8686
8787await Verify (data .Companies .Count ());
8888```
89- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L310-L327 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-recording ' title =' Start of snippet ' >anchor</a ></sup >
89+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L319-L336 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-recording ' title =' Start of snippet ' >anchor</a ></sup >
9090<!-- endSnippet -->
9191
9292Will result in the following verified file:
@@ -143,7 +143,7 @@ await Verify(new
143143 sql = entries
144144});
145145```
146- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L336-L359 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-recordingspecific ' title =' Start of snippet ' >anchor</a ></sup >
146+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L438-L461 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-recordingspecific ' title =' Start of snippet ' >anchor</a ></sup >
147147<!-- endSnippet -->
148148
149149
@@ -174,7 +174,7 @@ await data2.Companies
174174
175175await Verify (data2 .Companies .Count ());
176176```
177- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L279-L301 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-multidbcontexts ' title =' Start of snippet ' >anchor</a ></sup >
177+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L288-L310 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-multidbcontexts ' title =' Start of snippet ' >anchor</a ></sup >
178178<!-- endSnippet -->
179179
180180<!-- snippet: CoreTests.MultiDbContexts.verified.txt -->
@@ -241,7 +241,7 @@ public async Task Added()
241241 await Verify (data .ChangeTracker );
242242}
243243```
244- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L8-L24 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-added ' title =' Start of snippet ' >anchor</a ></sup >
244+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L17-L33 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-added ' title =' Start of snippet ' >anchor</a ></sup >
245245<!-- endSnippet -->
246246
247247Will result in the following verified file:
@@ -275,15 +275,15 @@ public async Task Deleted()
275275 var options = DbContextOptions ();
276276
277277 await using var data = new SampleDbContext (options );
278- data .Add (new Company {Content = " before" });
278+ data .Add (new Company { Content = " before" });
279279 await data .SaveChangesAsync ();
280280
281281 var company = data .Companies .Single ();
282282 data .Companies .Remove (company );
283283 await Verify (data .ChangeTracker );
284284}
285285```
286- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L26-L42 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-deleted ' title =' Start of snippet ' >anchor</a ></sup >
286+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L35-L51 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-deleted ' title =' Start of snippet ' >anchor</a ></sup >
287287<!-- endSnippet -->
288288
289289Will result in the following verified file:
@@ -327,7 +327,7 @@ public async Task Modified()
327327 await Verify (data .ChangeTracker );
328328}
329329```
330- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L44-L63 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-modified ' title =' Start of snippet ' >anchor</a ></sup >
330+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L53-L72 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-modified ' title =' Start of snippet ' >anchor</a ></sup >
331331<!-- endSnippet -->
332332
333333Will result in the following verified file:
@@ -362,7 +362,7 @@ var queryable = data.Companies
362362 .Where (x => x .Content == " value" );
363363await Verify (queryable );
364364```
365- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L209-L215 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-queryable ' title =' Start of snippet ' >anchor</a ></sup >
365+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L218-L224 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-queryable ' title =' Start of snippet ' >anchor</a ></sup >
366366<!-- endSnippet -->
367367
368368Will result in the following verified file:
@@ -410,7 +410,7 @@ await Verify(data.AllData())
410410 serializer =>
411411 serializer .TypeNameHandling = TypeNameHandling .Objects ));
412412```
413- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L190- L199 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-alldata ' title =' Start of snippet ' >anchor</a ></sup >
413+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L199-L208 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-alldata ' title =' Start of snippet ' >anchor</a ></sup >
414414<!-- endSnippet -->
415415
416416Will result in the following verified file with all data in the database:
@@ -494,9 +494,60 @@ public async Task IgnoreNavigationProperties()
494494 x => x .IgnoreNavigationProperties (data ));
495495}
496496```
497- <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L65-L88 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-ignorenavigationproperties ' title =' Start of snippet ' >anchor</a ></sup >
497+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L74-L97 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-ignorenavigationproperties ' title =' Start of snippet ' >anchor</a ></sup >
498498<!-- endSnippet -->
499499
500+ ## WebApplicationFactory
501+
502+ To be able to use [ WebApplicationFactory] ( https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.testing.webapplicationfactory-1 ) for [ integration testing] ( https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests )
503+ an identifier must be used to be able to retrive the recorded commands. Start by enable recording with a unique identifier, for example the test name or a GUID:
504+
505+ <!-- snippet: EnableRecordingWithIdentifier -->
506+ <a id =' snippet-enablerecordingwithidentifier ' ></a >
507+ ``` cs
508+ .ConfigureTestServices (services =>
509+ {
510+ services .AddScoped <DbContextOptions <SampleDbContext >>(_ =>
511+ {
512+ return new DbContextOptionsBuilder <SampleDbContext >()
513+ .EnableRecording (testName )
514+ .UseSqlite ($" Data Source={testName };Mode=Memory;Cache=Shared" )
515+ .Options ;
516+ });
517+ });
518+ ```
519+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L394-L405 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-enablerecordingwithidentifier ' title =' Start of snippet ' >anchor</a ></sup >
520+ <!-- endSnippet -->
521+
522+ Then use the same identifer for recording:
523+
524+ <!-- snippet: RecordWithIdentifier -->
525+ <a id =' snippet-recordwithidentifier ' ></a >
526+ ``` cs
527+ var httpClient = factory .CreateClient ();
528+
529+ EfRecording .StartRecording (testName );
530+
531+ var companies = await httpClient .GetFromJsonAsync <Company []>(" /companies" );
532+
533+ var entries = EfRecording .FinishRecording (testName );
534+ ```
535+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L364-L372 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-recordwithidentifier ' title =' Start of snippet ' >anchor</a ></sup >
536+ <!-- endSnippet -->
537+
538+ The results will not be automatically included in verified file so it will have to be verified manually:
539+
540+ <!-- snippet: VerifyRecordedCommandsWithIdentifier -->
541+ <a id =' snippet-verifyrecordedcommandswithidentifier ' ></a >
542+ ``` cs
543+ await Verify (new
544+ {
545+ target = companies ! .Length ,
546+ sql = entries
547+ });
548+ ```
549+ <sup ><a href =' /src/Verify.EntityFramework.Tests/CoreTests.cs#L374-L380 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-verifyrecordedcommandswithidentifier ' title =' Start of snippet ' >anchor</a ></sup >
550+ <!-- endSnippet -->
500551
501552## Icon
502553
0 commit comments