File tree Expand file tree Collapse file tree 2 files changed +3
-3
lines changed
Services/AspNetCoreTemplate.Services.Data
Tests/AspNetCoreTemplate.Services.Data.Tests Expand file tree Collapse file tree 2 files changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public SettingsService(IDeletableEntityRepository<Setting> settingsRepository)
18
18
19
19
public int GetCount ( )
20
20
{
21
- return this . settingsRepository . All ( ) . Count ( ) ;
21
+ return this . settingsRepository . AllAsNoTracking ( ) . Count ( ) ;
22
22
}
23
23
24
24
public IEnumerable < T > GetAll < T > ( )
Original file line number Diff line number Diff line change @@ -37,13 +37,13 @@ public async Task GetCountShouldReturnCorrectNumberUsingDbContext()
37
37
{
38
38
var options = new DbContextOptionsBuilder < ApplicationDbContext > ( )
39
39
. UseInMemoryDatabase ( databaseName : "SettingsTestDb" ) . Options ;
40
- var dbContext = new ApplicationDbContext ( options ) ;
40
+ using var dbContext = new ApplicationDbContext ( options ) ;
41
41
dbContext . Settings . Add ( new Setting ( ) ) ;
42
42
dbContext . Settings . Add ( new Setting ( ) ) ;
43
43
dbContext . Settings . Add ( new Setting ( ) ) ;
44
44
await dbContext . SaveChangesAsync ( ) ;
45
45
46
- var repository = new EfDeletableEntityRepository < Setting > ( dbContext ) ;
46
+ using var repository = new EfDeletableEntityRepository < Setting > ( dbContext ) ;
47
47
var service = new SettingsService ( repository ) ;
48
48
Assert . Equal ( 3 , service . GetCount ( ) ) ;
49
49
}
You can’t perform that action at this time.
0 commit comments