Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Fixed inconsistent naming of async methods #1014

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ dotnet_naming_symbols.instance_fields.applicable_kinds = field

dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _

# Async naming conventions
dotnet_naming_rule.suffix_async_should_be_asyncsuffix.severity = error #suggestion
dotnet_naming_rule.suffix_async_should_be_asyncsuffix.symbols = suffix_async
dotnet_naming_rule.suffix_async_should_be_asyncsuffix.style = asyncsuffix

dotnet_naming_symbols.suffix_async.applicable_kinds = method
dotnet_naming_symbols.suffix_async.applicable_accessibilities = *
dotnet_naming_symbols.suffix_async.required_modifiers = async

dotnet_naming_style.asyncsuffix.required_prefix =
dotnet_naming_style.asyncsuffix.required_suffix = Async
dotnet_naming_style.asyncsuffix.word_separator =
dotnet_naming_style.asyncsuffix.capitalization = pascal_case
###############################
# C# Coding Conventions #
###############################
Expand Down
2 changes: 1 addition & 1 deletion src/ApplicationCore/Interfaces/IBasketQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces;
/// </summary>
public interface IBasketQueryService
{
Task<int> CountTotalBasketItems(string username);
Task<int> CountTotalBasketItemsAsync(string username);
}

4 changes: 2 additions & 2 deletions src/ApplicationCore/Interfaces/IBasketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces;
public interface IBasketService
{
Task TransferBasketAsync(string anonymousId, string userName);
Task<Basket> AddItemToBasket(string username, int catalogItemId, decimal price, int quantity = 1);
Task<Result<Basket>> SetQuantities(int basketId, Dictionary<string, int> quantities);
Task<Basket> AddItemToBasketAsync(string username, int catalogItemId, decimal price, int quantity = 1);
Task<Result<Basket>> SetQuantitiesAsync(int basketId, Dictionary<string, int> quantities);
Task DeleteBasketAsync(int basketId);
}
4 changes: 2 additions & 2 deletions src/ApplicationCore/Services/BasketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BasketService(IRepository<Basket> basketRepository,
_logger = logger;
}

public async Task<Basket> AddItemToBasket(string username, int catalogItemId, decimal price, int quantity = 1)
public async Task<Basket> AddItemToBasketAsync(string username, int catalogItemId, decimal price, int quantity = 1)
{
var basketSpec = new BasketWithItemsSpecification(username);
var basket = await _basketRepository.FirstOrDefaultAsync(basketSpec);
Expand All @@ -44,7 +44,7 @@ public async Task DeleteBasketAsync(int basketId)
await _basketRepository.DeleteAsync(basket);
}

public async Task<Result<Basket>> SetQuantities(int basketId, Dictionary<string, int> quantities)
public async Task<Result<Basket>> SetQuantitiesAsync(int basketId, Dictionary<string, int> quantities)
{
var basketSpec = new BasketWithItemsSpecification(basketId);
var basket = await _basketRepository.FirstOrDefaultAsync(basketSpec);
Expand Down
8 changes: 4 additions & 4 deletions src/BlazorAdmin/CustomAuthStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ public CustomAuthStateProvider(HttpClient httpClient,

public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
return new AuthenticationState(await GetUser(useCache: true));
return new AuthenticationState(await GetUserAsync(useCache: true));
}

private async ValueTask<ClaimsPrincipal> GetUser(bool useCache = false)
private async ValueTask<ClaimsPrincipal> GetUserAsync(bool useCache = false)
{
var now = DateTimeOffset.Now;
if (useCache && now < _userLastCheck + UserCacheRefreshInterval)
{
return _cachedUser;
}

_cachedUser = await FetchUser();
_cachedUser = await FetchUserAsync();
_userLastCheck = now;

return _cachedUser;
}

private async Task<ClaimsPrincipal> FetchUser()
private async Task<ClaimsPrincipal> FetchUserAsync()
{
UserInfo user = null;

Expand Down
4 changes: 2 additions & 2 deletions src/BlazorAdmin/JavaScript/Cookies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public Cookies(IJSRuntime jsRuntime)
_jsRuntime = jsRuntime;
}

public async Task DeleteCookie(string name)
public async Task DeleteCookieAsync(string name)
{
await _jsRuntime.InvokeAsync<string>(JSInteropConstants.DeleteCookie, name);
}

public async Task<string> GetCookie(string name)
public async Task<string> GetCookieAsync(string name)
{
return await _jsRuntime.InvokeAsync<string>(JSInteropConstants.GetCookie, name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorAdmin/JavaScript/Css.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public Css(IJSRuntime jsRuntime)
_jsRuntime = jsRuntime;
}

public async Task ShowBodyOverflow()
public async Task ShowBodyOverflowAsync()
{
await _jsRuntime.InvokeAsync<string>(JSInteropConstants.ShowBodyOverflow);
}

public async Task<string> HideBodyOverflow()
public async Task<string> HideBodyOverflowAsync()
{
return await _jsRuntime.InvokeAsync<string>(JSInteropConstants.HideBodyOverflow);
}
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorAdmin/JavaScript/Route.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Route(IJSRuntime jsRuntime)
_jsRuntime = jsRuntime;
}

public async Task RouteOutside(string path)
public async Task RouteOutsideAsync(string path)
{
await _jsRuntime.InvokeAsync<string>(JSInteropConstants.RouteOutside, path);
}
Expand Down
20 changes: 10 additions & 10 deletions src/BlazorAdmin/Pages/CatalogItemPage/Create.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<div class="modal @_modalClass" tabindex="-1" role="dialog" style="display:@_modalDisplay">
<div class="modal-dialog" role="document">
<div class="modal-content">
<EditForm Model="_item" OnValidSubmit="@CreateClick">
<EditForm Model="_item" OnValidSubmit="@CreateClickAsync">
<DataAnnotationsValidator />
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Create</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="CloseAsync">
<span aria-hidden="true">&times;</span>
</button>
</div>
Expand Down Expand Up @@ -87,7 +87,7 @@
}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="Close">Cancel</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="CloseAsync">Cancel</button>
<button type="submit" class="btn btn-primary">
Create
</button>
Expand Down Expand Up @@ -122,22 +122,22 @@
private bool _showCreateModal = false;
private CreateCatalogItemRequest _item = new CreateCatalogItemRequest();

private async Task CreateClick()
private async Task CreateClickAsync()
{
var result = await CatalogItemService.Create(_item);
var result = await CatalogItemService.CreateAsync(_item);
if (result != null)
{
await OnSaveClick.InvokeAsync(null);
await Close();
await CloseAsync();
}
}

public async Task Open()
public async Task OpenAsync()
{

Logger.LogInformation("Now loading... /Catalog/Create");

await new Css(JSRuntime).HideBodyOverflow();
await new Css(JSRuntime).HideBodyOverflowAsync();

_item = new CreateCatalogItemRequest
{
Expand All @@ -152,9 +152,9 @@
StateHasChanged();
}

private async Task Close()
private async Task CloseAsync()
{
await new Css(JSRuntime).ShowBodyOverflow();
await new Css(JSRuntime).ShowBodyOverflowAsync();
_modalDisplay = "none";
_modalClass = "";
_showCreateModal = false;
Expand Down
22 changes: 11 additions & 11 deletions src/BlazorAdmin/Pages/CatalogItemPage/Delete.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete @_item.Name</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="CloseAsync">
<span aria-hidden="true">&times;</span>
</button>
</div>
Expand Down Expand Up @@ -75,8 +75,8 @@

</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="Close">Cancel</button>
<button class="btn btn-danger" @onclick="() => DeleteClick(_item.Id)">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="CloseAsync">Cancel</button>
<button class="btn btn-danger" @onclick="() => DeleteClickAsync(_item.Id)">
Delete
</button>
</div>
Expand Down Expand Up @@ -105,23 +105,23 @@
private bool _showDeleteModal = false;
private CatalogItem _item = new CatalogItem();

private async Task DeleteClick(int id)
private async Task DeleteClickAsync(int id)
{
// TODO: Add some kind of "are you sure" check before this

await CatalogItemService.Delete(id);
await CatalogItemService.DeleteAsync(id);

await OnSaveClick.InvokeAsync(null);
await Close();
await CloseAsync();
}

public async Task Open(int id)
public async Task OpenAsync(int id)
{
Logger.LogInformation("Now loading... /Catalog/Delete/{Id}", id);

await new Css(JSRuntime).HideBodyOverflow();
await new Css(JSRuntime).HideBodyOverflowAsync();

_item = await CatalogItemService.GetById(id);
_item = await CatalogItemService.GetByIdAsync(id);

_modalDisplay = "block;";
_modalClass = "Show";
Expand All @@ -130,9 +130,9 @@
StateHasChanged();
}

private async Task Close()
private async Task CloseAsync()
{
await new Css(JSRuntime).ShowBodyOverflow();
await new Css(JSRuntime).ShowBodyOverflowAsync();
_modalDisplay = "none";
_modalClass = "";
_showDeleteModal = false;
Expand Down
20 changes: 10 additions & 10 deletions src/BlazorAdmin/Pages/CatalogItemPage/Details.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Details @_item.Name</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="CloseAsync">
<span aria-hidden="true">&times;</span>
</button>
</div>
Expand Down Expand Up @@ -79,8 +79,8 @@

</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="Close">Close</button>
<button class="btn btn-primary" @onclick="EditClick">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="CloseAsync">Close</button>
<button class="btn btn-primary" @onclick="EditClickAsync">
Edit
</button>
</div>
Expand Down Expand Up @@ -108,20 +108,20 @@
private bool _showDetailsModal = false;
private CatalogItem _item = new CatalogItem();

public async Task EditClick()
public async Task EditClickAsync()
{
await OnEditClick.InvokeAsync(_item.Id);
await Close();
await CloseAsync();
}

public async Task Open(int id)
public async Task OpenAsync(int id)
{

Logger.LogInformation("Now loading... /Catalog/Details/{Id}", id);

await new Css(JSRuntime).HideBodyOverflow();
await new Css(JSRuntime).HideBodyOverflowAsync();

_item = await CatalogItemService.GetById(id);
_item = await CatalogItemService.GetByIdAsync(id);

_modalDisplay = "block;";
_modalClass = "Show";
Expand All @@ -130,9 +130,9 @@
StateHasChanged();
}

public async Task Close()
public async Task CloseAsync()
{
await new Css(JSRuntime).ShowBodyOverflow();
await new Css(JSRuntime).ShowBodyOverflowAsync();

_modalDisplay = "none";
_modalClass = "";
Expand Down
22 changes: 11 additions & 11 deletions src/BlazorAdmin/Pages/CatalogItemPage/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<div class="modal @_modalClass" tabindex="-1" role="dialog" style="display:@_modalDisplay">
<div class="modal-dialog" role="document">
<div class="modal-content">
<EditForm Model="_item" OnValidSubmit="@SaveClick">
<EditForm Model="_item" OnValidSubmit="@SaveClickAsync">
<DataAnnotationsValidator />
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit @_item.Name</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="CloseAsync">
<span aria-hidden="true">&times;</span>
</button>
</div>
Expand Down Expand Up @@ -90,7 +90,7 @@
}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="Close">Cancel</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="CloseAsync">Cancel</button>
<button type="submit" class="btn btn-primary">
Save
</button>
Expand Down Expand Up @@ -124,20 +124,20 @@
private bool _showEditModal = false;
private CatalogItem _item = new CatalogItem();

private async Task SaveClick()
private async Task SaveClickAsync()
{
await CatalogItemService.Edit(_item);
await CatalogItemService.EditAsync(_item);
await OnSaveClick.InvokeAsync(null);
await Close();
await CloseAsync();
}

public async Task Open(int id)
public async Task OpenAsync(int id)
{
Logger.LogInformation("Now loading... /Catalog/Edit/{Id}", id);

await new Css(JSRuntime).HideBodyOverflow();
await new Css(JSRuntime).HideBodyOverflowAsync();

_item = await CatalogItemService.GetById(id);
_item = await CatalogItemService.GetByIdAsync(id);

_modalDisplay = "block;";
_modalClass = "Show";
Expand All @@ -146,9 +146,9 @@
StateHasChanged();
}

private async Task Close()
private async Task CloseAsync()
{
await new Css(JSRuntime).ShowBodyOverflow();
await new Css(JSRuntime).ShowBodyOverflowAsync();

_modalDisplay = "none";
_modalClass = "";
Expand Down
Loading