Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Resharper: Replace async method with Task return" #1513

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
1 change: 0 additions & 1 deletion WarningSeverities.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RemoveRedundantOrStatement_002ETrue/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RemoveToList_002E1/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RemoveToList_002E2/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceAsyncWithTaskReturn/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceObjectPatternWithVarPattern/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceSequenceEqualWithConstantPattern/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReplaceWithFirstOrDefault_002E1/@EntryIndexedValue">WARNING</s:String>
Expand Down
4 changes: 2 additions & 2 deletions src/Examples/DapperExample/Repositories/DapperRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public async Task<IReadOnlyCollection<TResource>> GetAsync(QueryLayer queryLayer
}

/// <inheritdoc />
public Task<int> CountAsync(FilterExpression? filter, CancellationToken cancellationToken)
public async Task<int> CountAsync(FilterExpression? filter, CancellationToken cancellationToken)
{
var queryLayer = new QueryLayer(ResourceType)
{
Expand All @@ -173,7 +173,7 @@ public Task<int> CountAsync(FilterExpression? filter, CancellationToken cancella
CommandDefinition sqlCommand = _dapperFacade.GetSqlCommand(selectNode, cancellationToken);
LogSqlCommand(sqlCommand);

return ExecuteQueryAsync(connection => connection.ExecuteScalarAsync<int>(sqlCommand), cancellationToken);
return await ExecuteQueryAsync(async connection => await connection.ExecuteScalarAsync<int>(sqlCommand), cancellationToken);
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/AtomicOperations/OperationsProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccesso
return results;
}

protected virtual Task<OperationContainer?> ProcessOperationAsync(OperationContainer operation, CancellationToken cancellationToken)
protected virtual async Task<OperationContainer?> ProcessOperationAsync(OperationContainer operation, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -108,7 +108,7 @@ public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccesso
_targetedFields.CopyFrom(operation.TargetedFields);
_request.CopyFrom(operation.Request);

return _operationProcessorAccessor.ProcessAsync(operation, cancellationToken);
return await _operationProcessorAccessor.ProcessAsync(operation, cancellationToken);
}

protected void TrackLocalIdsForOperation(OperationContainer operation)
Expand Down
40 changes: 20 additions & 20 deletions src/JsonApiDotNetCore/Controllers/JsonApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,78 +42,78 @@ protected JsonApiController(IJsonApiOptions options, IResourceGraph resourceGrap
/// <inheritdoc />
[HttpGet]
[HttpHead]
public override Task<IActionResult> GetAsync(CancellationToken cancellationToken)
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
{
return base.GetAsync(cancellationToken);
return await base.GetAsync(cancellationToken);
}

/// <inheritdoc />
[HttpGet("{id}")]
[HttpHead("{id}")]
public override Task<IActionResult> GetAsync([Required] TId id, CancellationToken cancellationToken)
public override async Task<IActionResult> GetAsync([Required] TId id, CancellationToken cancellationToken)
{
return base.GetAsync(id, cancellationToken);
return await base.GetAsync(id, cancellationToken);
}

/// <inheritdoc />
[HttpGet("{id}/{relationshipName}")]
[HttpHead("{id}/{relationshipName}")]
public override Task<IActionResult> GetSecondaryAsync([Required] TId id, [Required] string relationshipName, CancellationToken cancellationToken)
public override async Task<IActionResult> GetSecondaryAsync([Required] TId id, [Required] string relationshipName, CancellationToken cancellationToken)
{
return base.GetSecondaryAsync(id, relationshipName, cancellationToken);
return await base.GetSecondaryAsync(id, relationshipName, cancellationToken);
}

/// <inheritdoc />
[HttpGet("{id}/relationships/{relationshipName}")]
[HttpHead("{id}/relationships/{relationshipName}")]
public override Task<IActionResult> GetRelationshipAsync([Required] TId id, [Required] string relationshipName, CancellationToken cancellationToken)
public override async Task<IActionResult> GetRelationshipAsync([Required] TId id, [Required] string relationshipName, CancellationToken cancellationToken)
{
return base.GetRelationshipAsync(id, relationshipName, cancellationToken);
return await base.GetRelationshipAsync(id, relationshipName, cancellationToken);
}

/// <inheritdoc />
[HttpPost]
public override Task<IActionResult> PostAsync([Required] TResource resource, CancellationToken cancellationToken)
public override async Task<IActionResult> PostAsync([Required] TResource resource, CancellationToken cancellationToken)
{
return base.PostAsync(resource, cancellationToken);
return await base.PostAsync(resource, cancellationToken);
}

/// <inheritdoc />
[HttpPost("{id}/relationships/{relationshipName}")]
public override Task<IActionResult> PostRelationshipAsync([Required] TId id, [Required] string relationshipName,
public override async Task<IActionResult> PostRelationshipAsync([Required] TId id, [Required] string relationshipName,
[Required] ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
{
return base.PostRelationshipAsync(id, relationshipName, rightResourceIds, cancellationToken);
return await base.PostRelationshipAsync(id, relationshipName, rightResourceIds, cancellationToken);
}

/// <inheritdoc />
[HttpPatch("{id}")]
public override Task<IActionResult> PatchAsync([Required] TId id, [Required] TResource resource, CancellationToken cancellationToken)
public override async Task<IActionResult> PatchAsync([Required] TId id, [Required] TResource resource, CancellationToken cancellationToken)
{
return base.PatchAsync(id, resource, cancellationToken);
return await base.PatchAsync(id, resource, cancellationToken);
}

/// <inheritdoc />
[HttpPatch("{id}/relationships/{relationshipName}")]
// Parameter `[Required] object? rightValue` makes Swashbuckle generate the OpenAPI request body as required. We don't actually validate ModelState, so it doesn't hurt.
public override Task<IActionResult> PatchRelationshipAsync([Required] TId id, [Required] string relationshipName, [Required] object? rightValue,
public override async Task<IActionResult> PatchRelationshipAsync([Required] TId id, [Required] string relationshipName, [Required] object? rightValue,
CancellationToken cancellationToken)
{
return base.PatchRelationshipAsync(id, relationshipName, rightValue, cancellationToken);
return await base.PatchRelationshipAsync(id, relationshipName, rightValue, cancellationToken);
}

/// <inheritdoc />
[HttpDelete("{id}")]
public override Task<IActionResult> DeleteAsync([Required] TId id, CancellationToken cancellationToken)
public override async Task<IActionResult> DeleteAsync([Required] TId id, CancellationToken cancellationToken)
{
return base.DeleteAsync(id, cancellationToken);
return await base.DeleteAsync(id, cancellationToken);
}

/// <inheritdoc />
[HttpDelete("{id}/relationships/{relationshipName}")]
public override Task<IActionResult> DeleteRelationshipAsync([Required] TId id, [Required] string relationshipName,
public override async Task<IActionResult> DeleteRelationshipAsync([Required] TId id, [Required] string relationshipName,
[Required] ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
{
return base.DeleteRelationshipAsync(id, relationshipName, rightResourceIds, cancellationToken);
return await base.DeleteRelationshipAsync(id, relationshipName, rightResourceIds, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public abstract class JsonApiOperationsController(
{
/// <inheritdoc />
[HttpPost]
public override Task<IActionResult> PostOperationsAsync([Required] IList<OperationContainer> operations, CancellationToken cancellationToken)
public override async Task<IActionResult> PostOperationsAsync([Required] IList<OperationContainer> operations, CancellationToken cancellationToken)
{
return base.PostOperationsAsync(operations, cancellationToken);
return await base.PostOperationsAsync(operations, cancellationToken);
}
}
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Middleware/JsonApiOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public bool CanWriteResult(OutputFormatterCanWriteContext context)
}

/// <inheritdoc />
public Task WriteAsync(OutputFormatterWriteContext context)
public async Task WriteAsync(OutputFormatterWriteContext context)
{
ArgumentGuard.NotNull(context);

var writer = context.HttpContext.RequestServices.GetRequiredService<IJsonApiWriter>();
return writer.WriteAsync(context.Object, context.HttpContext);
await writer.WriteAsync(context.Object, context.HttpContext);
}
}
8 changes: 4 additions & 4 deletions src/JsonApiDotNetCore/Serialization/Response/JsonApiWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ public JsonApiWriter(IJsonApiRequest request, IJsonApiOptions options, IResponse
}

/// <inheritdoc />
public Task WriteAsync(object? model, HttpContext httpContext)
public async Task WriteAsync(object? model, HttpContext httpContext)
{
ArgumentGuard.NotNull(httpContext);

if (model == null && !CanWriteBody((HttpStatusCode)httpContext.Response.StatusCode))
{
// Prevent exception from Kestrel server, caused by writing data:null json response.
return Task.CompletedTask;
return;
}

string? responseBody = GetResponseBody(model, httpContext);

if (httpContext.Request.Method == HttpMethod.Head.Method)
{
httpContext.Response.GetTypedHeaders().ContentLength = responseBody == null ? 0 : Encoding.UTF8.GetByteCount(responseBody);
return Task.CompletedTask;
return;
}

_traceWriter.LogMessage(() =>
Expand All @@ -70,7 +70,7 @@ public Task WriteAsync(object? model, HttpContext httpContext)
return $"Sending {httpContext.Response.StatusCode} response for {method} request at '{url}' with body: <<{responseBody}>>";
});

return SendResponseBodyAsync(httpContext.Response, responseBody);
await SendResponseBodyAsync(httpContext.Response, responseBody);
}

private static bool CanWriteBody(HttpStatusCode statusCode)
Expand Down
12 changes: 6 additions & 6 deletions src/JsonApiDotNetCore/Services/JsonApiResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,19 @@ protected async Task AssertPrimaryResourceDoesNotExistAsync(TResource resource,
}
}

protected virtual Task InitializeResourceAsync(TResource resourceForDatabase, CancellationToken cancellationToken)
protected virtual async Task InitializeResourceAsync(TResource resourceForDatabase, CancellationToken cancellationToken)
{
return _resourceDefinitionAccessor.OnPrepareWriteAsync(resourceForDatabase, WriteOperationKind.CreateResource, cancellationToken);
await _resourceDefinitionAccessor.OnPrepareWriteAsync(resourceForDatabase, WriteOperationKind.CreateResource, cancellationToken);
}

private Task AccurizeResourceTypesInHierarchyToAssignInRelationshipsAsync(TResource primaryResource, CancellationToken cancellationToken)
private async Task AccurizeResourceTypesInHierarchyToAssignInRelationshipsAsync(TResource primaryResource, CancellationToken cancellationToken)
{
return ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(primaryResource, true, cancellationToken);
await ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(primaryResource, true, cancellationToken);
}

protected Task AssertResourcesToAssignInRelationshipsExistAsync(TResource primaryResource, CancellationToken cancellationToken)
protected async Task AssertResourcesToAssignInRelationshipsExistAsync(TResource primaryResource, CancellationToken cancellationToken)
{
return ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(primaryResource, false, cancellationToken);
await ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(primaryResource, false, cancellationToken);
}

private async Task ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(TResource primaryResource, bool onlyIfTypeHierarchy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ public async Task Can_rollback_on_error()

const string personLocalId = "new-person";

await _testContext.RunOnDatabaseAsync(dbContext => _testContext.ClearAllTablesAsync(dbContext));
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await _testContext.ClearAllTablesAsync(dbContext);
});

var requestBody = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public sealed class CreateMusicTrackOperationsController(
IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request,
ITargetedFields targetedFields) : JsonApiOperationsController(options, resourceGraph, loggerFactory, processor, request, targetedFields)
{
public override Task<IActionResult> PostOperationsAsync(IList<OperationContainer> operations, CancellationToken cancellationToken)
public override async Task<IActionResult> PostOperationsAsync(IList<OperationContainer> operations, CancellationToken cancellationToken)
{
AssertOnlyCreatingMusicTracks(operations);

return base.PostOperationsAsync(operations, cancellationToken);
return await base.PostOperationsAsync(operations, cancellationToken);
}

private static void AssertOnlyCreatingMusicTracks(IEnumerable<OperationContainer> operations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public async Task Transforms_on_create_resource_with_side_effects()

List<RecordCompany> newCompanies = _fakers.RecordCompany.Generate(2);

await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTableAsync<RecordCompany>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<RecordCompany>();
});

var requestBody = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public async Task Can_rollback_on_error()
DateTimeOffset newBornAt = _fakers.Performer.Generate().BornAt;
string newTitle = _fakers.MusicTrack.Generate().Title;

await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTablesAsync<Performer, MusicTrack>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTablesAsync<Performer, MusicTrack>();
});

string unknownPerformerId = Unknown.StringId.For<Performer, int>();

Expand Down Expand Up @@ -110,7 +113,10 @@ public async Task Can_restore_to_previous_savepoint_on_error()
// Arrange
string newTrackTitle = _fakers.MusicTrack.Generate().Title;

await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTablesAsync<Performer, MusicTrack>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTablesAsync<Performer, MusicTrack>();
});

const string trackLid = "track-1";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public ResponseMetaTests(IntegrationTestContext<TestableStartup<MetaDbContext>,
public async Task Returns_top_level_meta()
{
// Arrange
await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTableAsync<SupportTicket>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<SupportTicket>();
});

const string route = "/supportTickets";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
public async Task Renders_resource_count_for_empty_collection()
{
// Arrange
await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTableAsync<SupportTicket>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<SupportTicket>();
});

const string route = "/supportTickets";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ protected async Task FinishWriteAsync(DomainGroup group, WriteOperationKind writ

protected abstract Task FlushMessageAsync(OutgoingMessage message, CancellationToken cancellationToken);

protected virtual Task<DomainGroup?> GetGroupToDeleteAsync(Guid groupId, CancellationToken cancellationToken)
protected virtual async Task<DomainGroup?> GetGroupToDeleteAsync(Guid groupId, CancellationToken cancellationToken)
{
return _groupSet.Include(group => group.Users).FirstOrDefaultAsync(group => group.Id == groupId, cancellationToken);
return await _groupSet.Include(group => group.Users).FirstOrDefaultAsync(group => group.Id == groupId, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected async Task FinishWriteAsync(DomainUser user, WriteOperationKind writeO

protected abstract Task FlushMessageAsync(OutgoingMessage message, CancellationToken cancellationToken);

protected virtual Task<DomainUser?> GetUserToDeleteAsync(Guid userId, CancellationToken cancellationToken)
protected virtual async Task<DomainUser?> GetUserToDeleteAsync(Guid userId, CancellationToken cancellationToken)
{
return _userSet.Include(domainUser => domainUser.Group).FirstOrDefaultAsync(domainUser => domainUser.Id == userId, cancellationToken);
return await _userSet.Include(domainUser => domainUser.Group).FirstOrDefaultAsync(domainUser => domainUser.Id == userId, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public async Task Create_group_writes_to_outbox()

string newGroupName = _fakers.DomainGroup.Generate().Name;

await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTableAsync<OutgoingMessage>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<OutgoingMessage>();
});

var requestBody = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public async Task Create_user_writes_to_outbox()
string newLoginName = _fakers.DomainUser.Generate().LoginName;
string newDisplayName = _fakers.DomainUser.Generate().DisplayName!;

await _testContext.RunOnDatabaseAsync(dbContext => dbContext.ClearTableAsync<OutgoingMessage>());
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
await dbContext.ClearTableAsync<OutgoingMessage>();
});

var requestBody = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ public override async Task AddToToManyRelationshipAsync(TId leftId, string relat
await base.AddToToManyRelationshipAsync(leftId, relationshipName, rightResourceIds, cancellationToken);
}

public override Task DeleteAsync(TId id, CancellationToken cancellationToken)
public override async Task DeleteAsync(TId id, CancellationToken cancellationToken)
{
if (IsSoftDeletable(typeof(TResource)))
{
return SoftDeleteAsync(id, cancellationToken);
await SoftDeleteAsync(id, cancellationToken);
}
else
{
await base.DeleteAsync(id, cancellationToken);
}

return base.DeleteAsync(id, cancellationToken);
}

private async Task SoftDeleteAsync(TId id, CancellationToken cancellationToken)
Expand Down
Loading