Skip to content

Commit 267d083

Browse files
committed
cleanup
1 parent 1b439a5 commit 267d083

9 files changed

Lines changed: 58 additions & 61 deletions

File tree

readme.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
Extends [Verify](https://github.com/VerifyTests/Verify) to allow snapshot testing with EntityFramework.
88

99

10-
11-
## NuGet package
10+
## NuGet packages
1211

1312
* https://nuget.org/packages/Verify.EntityFramework/
1413
* https://nuget.org/packages/Verify.EntityFrameworkClassic/
@@ -26,7 +25,7 @@ Enable VerifyEntityFramework once at assembly load time:
2625
```cs
2726
VerifyEntityFramework.Enable();
2827
```
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>
28+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L473-L477' title='Snippet source file'>snippet source</a> | <a href='#snippet-enablecore' title='Start of snippet'>anchor</a></sup>
3029
<!-- endSnippet -->
3130

3231

@@ -58,7 +57,7 @@ builder.UseSqlServer(connection);
5857
builder.EnableRecording();
5958
var data = new SampleDbContext(builder.Options);
6059
```
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>
60+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L235-L242' title='Snippet source file'>snippet source</a> | <a href='#snippet-enablerecording' title='Start of snippet'>anchor</a></sup>
6261
<!-- endSnippet -->
6362

6463
`EnableRecording` should only be called in the test context.
@@ -86,7 +85,7 @@ await data.Companies
8685

8786
await Verify(data.Companies.Count());
8887
```
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>
88+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L315-L332' title='Snippet source file'>snippet source</a> | <a href='#snippet-recording' title='Start of snippet'>anchor</a></sup>
9089
<!-- endSnippet -->
9190

9291
Will result in the following verified file:
@@ -143,7 +142,7 @@ await Verify(new
143142
sql = entries
144143
});
145144
```
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>
145+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L439-L462' title='Snippet source file'>snippet source</a> | <a href='#snippet-recordingspecific' title='Start of snippet'>anchor</a></sup>
147146
<!-- endSnippet -->
148147

149148

@@ -174,7 +173,7 @@ await data2.Companies
174173

175174
await Verify(data2.Companies.Count());
176175
```
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>
176+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L284-L306' title='Snippet source file'>snippet source</a> | <a href='#snippet-multidbcontexts' title='Start of snippet'>anchor</a></sup>
178177
<!-- endSnippet -->
179178

180179
<!-- snippet: CoreTests.MultiDbContexts.verified.txt -->
@@ -275,15 +274,18 @@ public async Task Deleted()
275274
var options = DbContextOptions();
276275

277276
await using var data = new SampleDbContext(options);
278-
data.Add(new Company { Content = "before" });
277+
data.Add(new Company
278+
{
279+
Content = "before"
280+
});
279281
await data.SaveChangesAsync();
280282

281283
var company = data.Companies.Single();
282284
data.Companies.Remove(company);
283285
await Verify(data.ChangeTracker);
284286
}
285287
```
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>
288+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L35-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-deleted' title='Start of snippet'>anchor</a></sup>
287289
<!-- endSnippet -->
288290

289291
Will result in the following verified file:
@@ -327,7 +329,7 @@ public async Task Modified()
327329
await Verify(data.ChangeTracker);
328330
}
329331
```
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>
332+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L56-L75' title='Snippet source file'>snippet source</a> | <a href='#snippet-modified' title='Start of snippet'>anchor</a></sup>
331333
<!-- endSnippet -->
332334

333335
Will result in the following verified file:
@@ -362,7 +364,7 @@ var queryable = data.Companies
362364
.Where(x => x.Content == "value");
363365
await Verify(queryable);
364366
```
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>
367+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L214-L220' title='Snippet source file'>snippet source</a> | <a href='#snippet-queryable' title='Start of snippet'>anchor</a></sup>
366368
<!-- endSnippet -->
367369

368370
Will result in the following verified file:
@@ -410,7 +412,7 @@ await Verify(data.AllData())
410412
serializer =>
411413
serializer.TypeNameHandling = TypeNameHandling.Objects));
412414
```
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>
415+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L196-L205' title='Snippet source file'>snippet source</a> | <a href='#snippet-alldata' title='Start of snippet'>anchor</a></sup>
414416
<!-- endSnippet -->
415417

416418
Will result in the following verified file with all data in the database:
@@ -494,32 +496,30 @@ public async Task IgnoreNavigationProperties()
494496
x => x.IgnoreNavigationProperties(data));
495497
}
496498
```
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>
499+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L77-L100' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorenavigationproperties' title='Start of snippet'>anchor</a></sup>
498500
<!-- endSnippet -->
499501

502+
500503
## WebApplicationFactory
501504

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:
505+
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)an identifier must be used to be able to retrieve the recorded commands. Start by enable recording with a unique identifier, for example the test name or a GUID:
504506

505507
<!-- snippet: EnableRecordingWithIdentifier -->
506508
<a id='snippet-enablerecordingwithidentifier'></a>
507509
```cs
508510
.ConfigureTestServices(services =>
509511
{
510-
services.AddScoped<DbContextOptions<SampleDbContext>>(_ =>
511-
{
512-
return new DbContextOptionsBuilder<SampleDbContext>()
512+
services.AddScoped(_ =>
513+
new DbContextOptionsBuilder<SampleDbContext>()
513514
.EnableRecording(testName)
514515
.UseSqlite($"Data Source={testName};Mode=Memory;Cache=Shared")
515-
.Options;
516-
});
516+
.Options);
517517
});
518518
```
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>
519+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L397-L408' title='Snippet source file'>snippet source</a> | <a href='#snippet-enablerecordingwithidentifier' title='Start of snippet'>anchor</a></sup>
520520
<!-- endSnippet -->
521521

522-
Then use the same identifer for recording:
522+
Then use the same identifier for recording:
523523

524524
<!-- snippet: RecordWithIdentifier -->
525525
<a id='snippet-recordwithidentifier'></a>
@@ -532,7 +532,7 @@ var companies = await httpClient.GetFromJsonAsync<Company[]>("/companies");
532532

533533
var entries = EfRecording.FinishRecording(testName);
534534
```
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>
535+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L364-L374' title='Snippet source file'>snippet source</a> | <a href='#snippet-recordwithidentifier' title='Start of snippet'>anchor</a></sup>
536536
<!-- endSnippet -->
537537

538538
The results will not be automatically included in verified file so it will have to be verified manually:
@@ -546,9 +546,10 @@ await Verify(new
546546
sql = entries
547547
});
548548
```
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>
549+
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L376-L384' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyrecordedcommandswithidentifier' title='Start of snippet'>anchor</a></sup>
550550
<!-- endSnippet -->
551551

552+
552553
## Icon
553554

554555
[Database](https://thenounproject.com/term/database/310841/) designed by [Creative Stall](https://thenounproject.com/creativestall/) from [The Noun Project](https://thenounproject.com).

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;CS8632;EF1001</NoWarn>
5-
<Version>6.3.1</Version>
5+
<Version>6.4.0</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<PackageTags>EntityFramework, Verify</PackageTags>
88
<Description>Extends Verify (https://github.com/VerifyTests/Verify) to allow verification of EntityFramework bits.</Description>
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{
2-
queryable:
3-
SELECT [c].[Id], [c].[Content]
1+
SELECT [c].[Id], [c].[Content]
42
FROM [Companies] AS [c]
5-
WHERE [c].[Content] = N'value'
6-
}
3+
WHERE [c].[Content] = N'value'

src/Verify.EntityFramework.Tests/CoreTests.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public async Task Deleted()
4040
var options = DbContextOptions();
4141

4242
await using var data = new SampleDbContext(options);
43-
data.Add(new Company { Content = "before" });
43+
data.Add(new Company
44+
{
45+
Content = "before"
46+
});
4447
await data.SaveChangesAsync();
4548

4649
var company = data.Companies.Single();
@@ -140,10 +143,7 @@ public async Task SomePropsModified()
140143

141144
[Test]
142145
public Task ShouldIgnoreDbFactory() =>
143-
Verify(new
144-
{
145-
Factory = new MyDbContextFactory()
146-
});
146+
Verify(new MyDbContextFactory());
147147

148148
[Test]
149149
public Task ShouldIgnoreDbFactoryInterface()
@@ -162,10 +162,7 @@ class TargetWithFactoryInterface
162162

163163
[Test]
164164
public Task ShouldIgnoreDbContext() =>
165-
Verify(new
166-
{
167-
Factory = new SampleDbContext(new DbContextOptions<SampleDbContext>())
168-
});
165+
Verify(new SampleDbContext(new DbContextOptions<SampleDbContext>()));
169166

170167
class MyDbContextFactory : IDbContextFactory<SampleDbContext>
171168
{
@@ -208,7 +205,6 @@ await Verify(data.AllData())
208205
#endregion
209206
}
210207

211-
212208
[Test]
213209
public async Task Queryable()
214210
{
@@ -231,7 +227,7 @@ public async Task NestedQueryable()
231227
var data = database.Context;
232228
var queryable = data.Companies
233229
.Where(x => x.Content == "value");
234-
await Verify(new { queryable });
230+
await Verify(queryable);
235231
}
236232

237233
void Build(string connection)
@@ -356,52 +352,59 @@ public async Task RecordingWebApplicationFactory(int run)
356352

357353
await context.Database.EnsureCreatedAsync();
358354

359-
context.Add(new Company { Id = 1, Content = "Foo" });
355+
context.Add(new Company
356+
{
357+
Id = 1,
358+
Content = "Foo"
359+
});
360360

361361
await context.SaveChangesAsync();
362362
}
363363

364364
#region RecordWithIdentifier
365+
365366
var httpClient = factory.CreateClient();
366367

367368
EfRecording.StartRecording(testName);
368369

369370
var companies = await httpClient.GetFromJsonAsync<Company[]>("/companies");
370371

371372
var entries = EfRecording.FinishRecording(testName);
373+
372374
#endregion
373375

374376
#region VerifyRecordedCommandsWithIdentifier
377+
375378
await Verify(new
376379
{
377380
target = companies!.Length,
378381
sql = entries
379382
});
383+
380384
#endregion
381385
}
382386

383387
class CustomWebApplicationFactory : WebApplicationFactory<Startup>
384388
{
385389
readonly string testName;
386390

387-
public CustomWebApplicationFactory(string testName)
388-
{
391+
public CustomWebApplicationFactory(string testName) =>
389392
this.testName = testName;
390-
}
391393

392394
protected override void ConfigureWebHost(IWebHostBuilder builder) =>
393395
builder
394-
#region EnableRecordingWithIdentifier
396+
397+
#region EnableRecordingWithIdentifier
398+
395399
.ConfigureTestServices(services =>
396400
{
397-
services.AddScoped<DbContextOptions<SampleDbContext>>(_ =>
398-
{
399-
return new DbContextOptionsBuilder<SampleDbContext>()
401+
services.AddScoped(_ =>
402+
new DbContextOptionsBuilder<SampleDbContext>()
400403
.EnableRecording(testName)
401404
.UseSqlite($"Data Source={testName};Mode=Memory;Cache=Shared")
402-
.Options;
403-
});
405+
.Options);
404406
});
407+
405408
#endregion
406409

407410
protected override IHostBuilder CreateHostBuilder() =>
@@ -411,14 +414,12 @@ protected override IHostBuilder CreateHostBuilder() =>
411414

412415
public class Startup
413416
{
414-
public void ConfigureServices(IServiceCollection services)
415-
{
417+
public void ConfigureServices(IServiceCollection services) =>
416418
services
417419
.AddDbContext<SampleDbContext>(builder =>
418420
{
419421
builder.UseInMemoryDatabase("");
420422
});
421-
}
422423

423424
public void Configure(IApplicationBuilder app)
424425
{

src/Verify.EntityFramework.Tests/Verify.EntityFramework.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="NUnit" Version="3.13.3" />
1212
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
1313
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.3.0" PrivateAssets="all" />
14-
<PackageReference Include="Verify.NUnit" Version="16.4.2" />
14+
<PackageReference Include="Verify.NUnit" Version="16.5.4" />
1515
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
1616
<PackageReference Include="EfLocalDb" Version="13.4.0" />
1717
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />

src/Verify.EntityFramework/LogCommandInterceptor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class LogCommandInterceptor :
2626
return state?.OrderBy(x => x.StartTime);
2727
}
2828

29-
public LogCommandInterceptor(string? identifier)
30-
{
29+
public LogCommandInterceptor(string? identifier) =>
3130
this.identifier = identifier;
32-
}
3331

3432
public override void CommandFailed(DbCommand command, CommandErrorEventData data)
3533
=> Add("CommandFailed", command, data, data.Exception);

src/Verify.EntityFramework/Verify.EntityFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.3" />
7-
<PackageReference Include="Verify" Version="16.4.2" />
7+
<PackageReference Include="Verify" Version="16.5.4" />
88
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
99
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
1010
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />

src/Verify.EntityFrameworkClassic.Tests/Verify.EntityFrameworkClassic.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
88
<PackageReference Include="NUnit" Version="3.13.3" />
99
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
10-
<PackageReference Include="Verify.NUnit" Version="16.4.2" />
10+
<PackageReference Include="Verify.NUnit" Version="16.5.4" />
1111
<PackageReference Include="EfClassicLocalDb" Version="13.4.0" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
1313
<PackageReference Include="ProjectDefaults" Version="1.0.78" PrivateAssets="all" />

src/Verify.EntityFrameworkClassic/Verify.EntityFrameworkClassic.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ItemGroup>
66
<Using Remove="System.Net.Http" />
77
<PackageReference Include="EntityFramework" Version="6.4.4" />
8-
<PackageReference Include="Verify" Version="16.4.2" />
8+
<PackageReference Include="Verify" Version="16.5.4" />
99
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1010
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />
1111
<PackageReference Include="ProjectDefaults" Version="1.0.78" PrivateAssets="all" />

0 commit comments

Comments
 (0)