Skip to content

Commit 852f618

Browse files
committed
[ASP.NET Core] CI unit test fix by reverting CountAsync change
1 parent 139f727 commit 852f618

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

ASP.NET Core/Services/AspNetCoreTemplate.Services.Data/ISettingsService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
namespace AspNetCoreTemplate.Services.Data
22
{
33
using System.Collections.Generic;
4-
using System.Threading.Tasks;
54

65
public interface ISettingsService
76
{
8-
Task<int> GetCountAsync();
7+
int GetCount();
98

109
IEnumerable<T> GetAll<T>();
1110
}

ASP.NET Core/Services/AspNetCoreTemplate.Services.Data/SettingsService.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
{
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Threading.Tasks;
65

76
using AspNetCoreTemplate.Data.Common.Repositories;
87
using AspNetCoreTemplate.Data.Models;
98
using AspNetCoreTemplate.Services.Mapping;
109

11-
using Microsoft.EntityFrameworkCore;
12-
1310
public class SettingsService : ISettingsService
1411
{
1512
private readonly IDeletableEntityRepository<Setting> settingsRepository;
@@ -19,9 +16,9 @@ public SettingsService(IDeletableEntityRepository<Setting> settingsRepository)
1916
this.settingsRepository = settingsRepository;
2017
}
2118

22-
public async Task<int> GetCountAsync()
19+
public int GetCount()
2320
{
24-
return await this.settingsRepository.All().CountAsync();
21+
return this.settingsRepository.All().Count();
2522
}
2623

2724
public IEnumerable<T> GetAll<T>()

ASP.NET Core/Tests/AspNetCoreTemplate.Services.Data.Tests/SettingsServiceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class SettingsServiceTests
1919
{
2020
[Fact]
21-
public async Task GetCountShouldReturnCorrectNumber()
21+
public void GetCountShouldReturnCorrectNumber()
2222
{
2323
var repository = new Mock<IDeletableEntityRepository<Setting>>();
2424
repository.Setup(r => r.All()).Returns(new List<Setting>
@@ -28,7 +28,7 @@ public async Task GetCountShouldReturnCorrectNumber()
2828
new Setting(),
2929
}.AsQueryable());
3030
var service = new SettingsService(repository.Object);
31-
Assert.Equal(3, await service.GetCountAsync());
31+
Assert.Equal(3, service.GetCount());
3232
repository.Verify(x => x.All(), Times.Once);
3333
}
3434

@@ -45,7 +45,7 @@ public async Task GetCountShouldReturnCorrectNumberUsingDbContext()
4545

4646
var repository = new EfDeletableEntityRepository<Setting>(dbContext);
4747
var service = new SettingsService(repository);
48-
Assert.Equal(3, await service.GetCountAsync());
48+
Assert.Equal(3, service.GetCount());
4949
}
5050
}
5151
}

ASP.NET Core/Tests/Sandbox/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static async Task<int> SandboxCode(SandboxOptions options, IServiceProvi
5353
var sw = Stopwatch.StartNew();
5454

5555
var settingsService = serviceProvider.GetService<ISettingsService>();
56-
Console.WriteLine($"Count of settings: {await settingsService.GetCountAsync()}");
56+
Console.WriteLine($"Count of settings: {settingsService.GetCount()}");
5757

5858
Console.WriteLine(sw.Elapsed);
5959
return await Task.FromResult(0);

ASP.NET Core/Web/AspNetCoreTemplate.Web/Areas/Administration/Controllers/DashboardController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public DashboardController(ISettingsService settingsService)
1616
this.settingsService = settingsService;
1717
}
1818

19-
public async Task<IActionResult> Index()
19+
public IActionResult Index()
2020
{
21-
var viewModel = new IndexViewModel { SettingsCount = await this.settingsService.GetCountAsync(), };
21+
var viewModel = new IndexViewModel { SettingsCount = this.settingsService.GetCount(), };
2222
return this.View(viewModel);
2323
}
2424
}

0 commit comments

Comments
 (0)